gnunet-android

GNUnet for Android
Log | Files | Refs | README

kdf.h (6755B)


      1 /* kdf.h
      2  *
      3  * Copyright (C) 2006-2025 wolfSSL Inc.
      4  *
      5  * This file is part of wolfSSL.
      6  *
      7  * wolfSSL is free software; you can redistribute it and/or modify
      8  * it under the terms of the GNU General Public License as published by
      9  * the Free Software Foundation; either version 3 of the License, or
     10  * (at your option) any later version.
     11  *
     12  * wolfSSL is distributed in the hope that it will be useful,
     13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  * GNU General Public License for more details.
     16  *
     17  * You should have received a copy of the GNU General Public License
     18  * along with this program; if not, write to the Free Software
     19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
     20  */
     21 
     22 /*!
     23     \file wolfssl/wolfcrypt/kdf.h
     24 */
     25 
     26 #ifndef NO_KDF
     27 
     28 #ifndef WOLF_CRYPT_KDF_H
     29 #define WOLF_CRYPT_KDF_H
     30 
     31 #if defined(HAVE_FIPS) && \
     32     defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5)
     33     #include <wolfssl/wolfcrypt/fips.h>
     34 #endif
     35 
     36 #include <wolfssl/wolfcrypt/hmac.h>
     37 
     38 #ifdef __cplusplus
     39     extern "C" {
     40 #endif
     41 
     42 #if FIPS_VERSION3_GE(6,0,0)
     43     extern const unsigned int wolfCrypt_FIPS_kdf_ro_sanity[2];
     44     WOLFSSL_LOCAL int wolfCrypt_FIPS_KDF_sanity(void);
     45 #endif
     46 
     47 enum max_prf {
     48 #ifdef HAVE_FFDHE_8192
     49     MAX_PRF_HALF        = 516, /* Maximum half secret len */
     50 #elif defined(HAVE_FFDHE_6144)
     51     MAX_PRF_HALF        = 388, /* Maximum half secret len */
     52 #else
     53     MAX_PRF_HALF        = 260, /* Maximum half secret len */
     54 #endif
     55     MAX_PRF_LABSEED     = 128, /* Maximum label + seed len */
     56     MAX_PRF_DIG         = 224  /* Maximum digest len      */
     57 };
     58 
     59 
     60 #ifdef WOLFSSL_HAVE_PRF
     61 WOLFSSL_API int wc_PRF(byte* result, word32 resLen, const byte* secret,
     62                     word32 secLen, const byte* seed, word32 seedLen, int hash,
     63                     void* heap, int devId);
     64 WOLFSSL_API int wc_PRF_TLSv1(byte* digest, word32 digLen, const byte* secret,
     65                     word32 secLen, const byte* label, word32 labLen,
     66                     const byte* seed, word32 seedLen, void* heap, int devId);
     67 WOLFSSL_API int wc_PRF_TLS(byte* digest, word32 digLen, const byte* secret,
     68                     word32 secLen, const byte* label, word32 labLen,
     69                     const byte* seed, word32 seedLen, int useAtLeastSha256,
     70                     int hash_type, void* heap, int devId);
     71 #endif /* WOLFSSL_HAVE_PRF */
     72 
     73 #ifdef HAVE_HKDF
     74 
     75 enum {
     76 /*
     77     MAX_HKDF_LABEL_SZ   = OPAQUE16_LEN +
     78                           OPAQUE8_LEN + PROTOCOL_LABEL_SZ + MAX_LABEL_SZ +
     79                           OPAQUE8_LEN + WC_MAX_DIGEST_SIZE
     80 */
     81     MAX_TLS13_HKDF_LABEL_SZ = 47 + WC_MAX_DIGEST_SIZE
     82 };
     83 
     84 WOLFSSL_API int wc_Tls13_HKDF_Extract_ex(byte* prk, const byte* salt,
     85                           word32 saltLen, byte* ikm, word32 ikmLen, int digest,
     86                           void* heap, int devId);
     87 
     88 WOLFSSL_API int wc_Tls13_HKDF_Extract(byte* prk, const byte* salt,
     89                           word32 saltLen, byte* ikm, word32 ikmLen, int digest);
     90 
     91 WOLFSSL_API int wc_Tls13_HKDF_Expand_Label_ex(byte* okm, word32 okmLen,
     92                              const byte* prk, word32 prkLen,
     93                              const byte* protocol, word32 protocolLen,
     94                              const byte* label, word32 labelLen,
     95                              const byte* info, word32 infoLen,
     96                              int digest, void* heap, int devId);
     97 
     98 WOLFSSL_API int wc_Tls13_HKDF_Expand_Label(byte* okm, word32 okmLen,
     99                              const byte* prk, word32 prkLen,
    100                              const byte* protocol, word32 protocolLen,
    101                              const byte* label, word32 labelLen,
    102                              const byte* info, word32 infoLen,
    103                              int digest);
    104 #if defined(WOLFSSL_TICKET_NONCE_MALLOC) &&                                    \
    105     (!defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
    106 WOLFSSL_API int wc_Tls13_HKDF_Expand_Label_Alloc(byte* okm, word32 okmLen,
    107     const byte* prk, word32 prkLen, const byte* protocol, word32 protocolLen,
    108     const byte* label, word32 labelLen, const byte* info, word32 infoLen,
    109     int digest, void* heap);
    110 #endif /* !defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3) */
    111 
    112 #endif /* HAVE_HKDF */
    113 
    114 #ifdef WOLFSSL_WOLFSSH
    115 
    116 WOLFSSL_API int wc_SSH_KDF(byte hashId, byte keyId,
    117         byte* key, word32 keySz,
    118         const byte* k, word32 kSz,
    119         const byte* h, word32 hSz,
    120         const byte* sessionId, word32 sessionIdSz);
    121 
    122 #endif /* WOLFSSL_WOLFSSH */
    123 
    124 #ifdef WC_SRTP_KDF
    125 /* Label values for purpose. */
    126 #define WC_SRTP_LABEL_ENCRYPTION        0x00
    127 #define WC_SRTP_LABEL_MSG_AUTH          0x01
    128 #define WC_SRTP_LABEL_SALT              0x02
    129 #define WC_SRTCP_LABEL_ENCRYPTION       0x03
    130 #define WC_SRTCP_LABEL_MSG_AUTH         0x04
    131 #define WC_SRTCP_LABEL_SALT             0x05
    132 #define WC_SRTP_LABEL_HDR_ENCRYPTION    0x06
    133 #define WC_SRTP_LABEL_HDR_SALT          0x07
    134 
    135 /* Length of index for SRTP KDF. */
    136 #define WC_SRTP_INDEX_LEN               6
    137 /* Length of index for SRTCP KDF. */
    138 #define WC_SRTCP_INDEX_LEN              4
    139 
    140 /* Indicators */
    141 enum {
    142     WC_SRTCP_32BIT_IDX = 0,
    143     WC_SRTCP_48BIT_IDX = 1
    144 };
    145 
    146 /* Maximum length of salt that can be used with SRTP/SRTCP. */
    147 #define WC_SRTP_MAX_SALT    14
    148 
    149 WOLFSSL_API int wc_SRTP_KDF(const byte* key, word32 keySz, const byte* salt,
    150     word32 saltSz, int kdrIdx, const byte* idx, byte* key1, word32 key1Sz,
    151     byte* key2, word32 key2Sz, byte* key3, word32 key3Sz);
    152 WOLFSSL_API int wc_SRTCP_KDF(const byte* key, word32 keySz, const byte* salt,
    153     word32 saltSz, int kdrIdx, const byte* idx, byte* key1, word32 key1Sz,
    154     byte* key2, word32 key2Sz, byte* key3, word32 key3Sz);
    155 WOLFSSL_API int wc_SRTCP_KDF_ex(const byte* key, word32 keySz, const byte* salt,
    156     word32 saltSz, int kdrIdx, const byte* idx, byte* key1, word32 key1Sz,
    157     byte* key2, word32 key2Sz, byte* key3, word32 key3Sz, int idxLenIndicator);
    158 WOLFSSL_API int wc_SRTP_KDF_label(const byte* key, word32 keySz,
    159     const byte* salt, word32 saltSz, int kdrIdx, const byte* idx, byte label,
    160     byte* outKey, word32 outKeySz);
    161 WOLFSSL_API int wc_SRTCP_KDF_label(const byte* key, word32 keySz,
    162     const byte* salt, word32 saltSz, int kdrIdx, const byte* idx, byte label,
    163     byte* outKey, word32 outKeySz);
    164 
    165 WOLFSSL_API int wc_SRTP_KDF_kdr_to_idx(word32 kdr);
    166 
    167 #endif /* WC_SRTP_KDF */
    168 
    169 #ifdef WC_KDF_NIST_SP_800_56C
    170 WOLFSSL_API int wc_KDA_KDF_onestep(const byte* z, word32 zSz,
    171     const byte* fixedInfo, word32 fixedInfoSz, word32 derivedSecretSz,
    172     enum wc_HashType hashType, byte* output, word32 outputSz);
    173 #endif
    174 #ifdef __cplusplus
    175     } /* extern "C" */
    176 #endif
    177 
    178 #endif /* WOLF_CRYPT_KDF_H */
    179 
    180 #endif /* NO_KDF */
    181