gnunet-android

GNUnet for Android
Log | Files | Refs | README

hkdf.h (2740B)


      1 // Copyright 2014 The BoringSSL Authors
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     https://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 #ifndef OPENSSL_HEADER_HKDF_H
     16 #define OPENSSL_HEADER_HKDF_H
     17 
     18 #include <openssl/base.h>   // IWYU pragma: export
     19 
     20 #if defined(__cplusplus)
     21 extern "C" {
     22 #endif
     23 
     24 
     25 // HKDF.
     26 
     27 
     28 // HKDF computes HKDF (as specified by RFC 5869) of initial keying material
     29 // |secret| with |salt| and |info| using |digest|, and outputs |out_len| bytes
     30 // to |out_key|. It returns one on success and zero on error.
     31 //
     32 // HKDF is an Extract-and-Expand algorithm. It does not do any key stretching,
     33 // and as such, is not suited to be used alone to generate a key from a
     34 // password.
     35 OPENSSL_EXPORT int HKDF(uint8_t *out_key, size_t out_len, const EVP_MD *digest,
     36                         const uint8_t *secret, size_t secret_len,
     37                         const uint8_t *salt, size_t salt_len,
     38                         const uint8_t *info, size_t info_len);
     39 
     40 // HKDF_extract computes a HKDF PRK (as specified by RFC 5869) from initial
     41 // keying material |secret| and salt |salt| using |digest|, and outputs
     42 // |out_len| bytes to |out_key|. The maximum output size is |EVP_MAX_MD_SIZE|.
     43 // It returns one on success and zero on error.
     44 //
     45 // WARNING: This function orders the inputs differently from RFC 5869
     46 // specification. Double-check which parameter is the secret/IKM and which is
     47 // the salt when using.
     48 OPENSSL_EXPORT int HKDF_extract(uint8_t *out_key, size_t *out_len,
     49                                 const EVP_MD *digest, const uint8_t *secret,
     50                                 size_t secret_len, const uint8_t *salt,
     51                                 size_t salt_len);
     52 
     53 // HKDF_expand computes a HKDF OKM (as specified by RFC 5869) of length
     54 // |out_len| from the PRK |prk| and info |info| using |digest|, and outputs
     55 // the result to |out_key|. It returns one on success and zero on error.
     56 OPENSSL_EXPORT int HKDF_expand(uint8_t *out_key, size_t out_len,
     57                                const EVP_MD *digest, const uint8_t *prk,
     58                                size_t prk_len, const uint8_t *info,
     59                                size_t info_len);
     60 
     61 
     62 #if defined(__cplusplus)
     63 }  // extern C
     64 #endif
     65 
     66 #define HKDF_R_OUTPUT_TOO_LARGE 100
     67 
     68 #endif  // OPENSSL_HEADER_HKDF_H