Home | History | Annotate | Download | only in keymaster
      1 /*
      2  * Copyright 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef SYSTEM_KEYMASTER_RSA_OPERATION_H_
     18 #define SYSTEM_KEYMASTER_RSA_OPERATION_H_
     19 
     20 #include <UniquePtr.h>
     21 
     22 #include <keymaster/key_blob.h>
     23 
     24 #include "operation.h"
     25 
     26 namespace keymaster {
     27 
     28 class RsaOperation : public Operation {
     29   public:
     30     RsaOperation(keymaster_purpose_t purpose, const Logger& logger, keymaster_digest_t digest,
     31                  keymaster_padding_t padding, RSA* key)
     32         : Operation(purpose, logger), rsa_key_(key), digest_(digest), padding_(padding) {}
     33     ~RsaOperation();
     34 
     35     virtual keymaster_error_t Begin() { return KM_ERROR_OK; }
     36     virtual keymaster_error_t Update(const Buffer& input, Buffer* output);
     37     virtual keymaster_error_t Abort() { return KM_ERROR_OK; }
     38 
     39   protected:
     40     keymaster_error_t StoreData(const Buffer& input);
     41 
     42     RSA* rsa_key_;
     43     keymaster_digest_t digest_;
     44     keymaster_padding_t padding_;
     45     Buffer data_;
     46 };
     47 
     48 class RsaSignOperation : public RsaOperation {
     49   public:
     50     RsaSignOperation(keymaster_purpose_t purpose, const Logger& logger, keymaster_digest_t digest,
     51                      keymaster_padding_t padding, RSA* key)
     52         : RsaOperation(purpose, logger, digest, padding, key) {}
     53     virtual keymaster_error_t Finish(const Buffer& signature, Buffer* output);
     54 };
     55 
     56 class RsaVerifyOperation : public RsaOperation {
     57   public:
     58     RsaVerifyOperation(keymaster_purpose_t purpose, const Logger& logger, keymaster_digest_t digest,
     59                        keymaster_padding_t padding, RSA* key)
     60         : RsaOperation(purpose, logger, digest, padding, key) {}
     61     virtual keymaster_error_t Finish(const Buffer& signature, Buffer* output);
     62 };
     63 
     64 }  // namespace keymaster
     65 
     66 #endif  // SYSTEM_KEYMASTER_RSA_OPERATION_H_
     67