Home | History | Annotate | Download | only in km_openssl
      1 /*
      2  * Copyright 2015 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_HKDF_H_
     18 #define SYSTEM_KEYMASTER_HKDF_H_
     19 
     20 #include "kdf.h"
     21 
     22 #include <keymaster/serializable.h>
     23 
     24 #include <keymaster/UniquePtr.h>
     25 
     26 namespace keymaster {
     27 
     28 /**
     29  * Rfc5869Sha256Kdf implements the key derivation function specified in RFC 5869 (using SHA256) and
     30  * outputs key material, as needed by ECIES. See https://tools.ietf.org/html/rfc5869 for details.
     31  */
     32 class Rfc5869Sha256Kdf : public Kdf {
     33   public:
     34     ~Rfc5869Sha256Kdf() {}
     35     bool Init(Buffer& secret, Buffer& salt) {
     36         return Init(secret.peek_read(), secret.available_read(), salt.peek_read(),
     37                     salt.available_read());
     38     }
     39 
     40     bool Init(const uint8_t* secret, size_t secret_len, const uint8_t* salt, size_t salt_len) {
     41         return Kdf::Init(KM_DIGEST_SHA_2_256, secret, secret_len, salt, salt_len);
     42     }
     43 
     44     bool GenerateKey(const uint8_t* info, size_t info_len, uint8_t* output,
     45                      size_t output_len) override;
     46 };
     47 
     48 }  // namespace keymaster
     49 
     50 #endif  // SYSTEM_KEYMASTER_HKDF_H_
     51