diff options
Diffstat (limited to 'lib/crypto-api.c')
-rw-r--r-- | lib/crypto-api.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/lib/crypto-api.c b/lib/crypto-api.c index 4db6812c29..45be64ed1f 100644 --- a/lib/crypto-api.c +++ b/lib/crypto-api.c @@ -1401,3 +1401,98 @@ void gnutls_aead_cipher_deinit(gnutls_aead_cipher_hd_t handle) _gnutls_aead_cipher_deinit(handle); gnutls_free(handle); } + +extern gnutls_crypto_kdf_st _gnutls_kdf_ops; + +/** + * gnutls_hkdf_extract: + * @mac: the mac algorithm used internally + * @key: the initial keying material + * @salt: the optional salt + * @output: the output value of the extract operation + * + * This function will derive a fixed-size key using the HKDF-Extract + * function as defined in RFC 5869. + * + * Returns: Zero or a negative error code on error. + * + * Since: 3.6.13 + */ +int +gnutls_hkdf_extract(gnutls_mac_algorithm_t mac, + const gnutls_datum_t *key, + const gnutls_datum_t *salt, + void *output) +{ + /* MD5 is only allowed internally for TLS */ + if (is_mac_algo_forbidden(mac)) + return gnutls_assert_val(GNUTLS_E_UNWANTED_ALGORITHM); + + return _gnutls_kdf_ops.hkdf_extract(mac, key->data, key->size, + salt ? salt->data : NULL, + salt ? salt->size : 0, + output); +} + +/** + * gnutls_hkdf_expand: + * @mac: the mac algorithm used internally + * @key: the pseudorandom key created with HKDF-Extract + * @info: the optional informational data + * @output: the output value of the expand operation + * @length: the desired length of the output key + * + * This function will derive a variable length keying material from + * the pseudorandom key using the HKDF-Expand function as defined in + * RFC 5869. + * + * Returns: Zero or a negative error code on error. + * + * Since: 3.6.13 + */ +int +gnutls_hkdf_expand(gnutls_mac_algorithm_t mac, + const gnutls_datum_t *key, + const gnutls_datum_t *info, + void *output, size_t length) +{ + /* MD5 is only allowed internally for TLS */ + if (is_mac_algo_forbidden(mac)) + return gnutls_assert_val(GNUTLS_E_UNWANTED_ALGORITHM); + + return _gnutls_kdf_ops.hkdf_expand(mac, key->data, key->size, + info->data, info->size, + output, length); +} + +/** + * gnutls_pbkdf2: + * @mac: the mac algorithm used internally + * @key: the initial keying material + * @salt: the salt + * @iter_count: the iteration count + * @output: the output value + * @length: the desired length of the output key + * + * This function will derive a variable length keying material from + * a password according to PKCS #5 PBKDF2. + * + * Returns: Zero or a negative error code on error. + * + * Since: 3.6.13 + */ +int +gnutls_pbkdf2(gnutls_mac_algorithm_t mac, + const gnutls_datum_t *key, + const gnutls_datum_t *salt, + unsigned iter_count, + void *output, size_t length) +{ + /* MD5 is only allowed internally for TLS */ + if (is_mac_algo_forbidden(mac)) + return gnutls_assert_val(GNUTLS_E_UNWANTED_ALGORITHM); + + return _gnutls_kdf_ops.pbkdf2(mac, key->data, key->size, + salt->data, salt->size, iter_count, + output, length); +} |