Latest update
This commit is contained in:
+45
-2
@@ -44,6 +44,7 @@ typedef struct {
|
||||
int ivlen; /* IV length */
|
||||
int taglen;
|
||||
int iv_gen; /* It is OK to generate IVs */
|
||||
int iv_gen_rand; /* No IV was specified, so generate a rand IV */
|
||||
int tls_aad_len; /* TLS AAD length */
|
||||
uint64_t tls_enc_records; /* Number of TLS records encrypted */
|
||||
ctr128_f ctr;
|
||||
@@ -1396,7 +1397,7 @@ static int s390x_aes_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
(OPENSSL_s390xcap_P.kma[0] & \
|
||||
S390X_CAPBIT(S390X_AES_256)))
|
||||
|
||||
/* iv + padding length for iv lenghts != 12 */
|
||||
/* iv + padding length for iv lengths != 12 */
|
||||
# define S390X_gcm_ivpadlen(i) ((((i) + 15) >> 4 << 4) + 16)
|
||||
|
||||
/*-
|
||||
@@ -2890,7 +2891,7 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
|
||||
return 1;
|
||||
|
||||
case EVP_CTRL_GET_IV:
|
||||
if (gctx->iv_gen != 1)
|
||||
if (gctx->iv_gen != 1 && gctx->iv_gen_rand != 1)
|
||||
return 0;
|
||||
if (gctx->ivlen != arg)
|
||||
return 0;
|
||||
@@ -3202,10 +3203,35 @@ static int aes_gcm_tls_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
return rv;
|
||||
}
|
||||
|
||||
#ifdef FIPS_MODE
|
||||
/*
|
||||
* See SP800-38D (GCM) Section 8 "Uniqueness requirement on IVS and keys"
|
||||
*
|
||||
* See also 8.2.2 RBG-based construction.
|
||||
* Random construction consists of a free field (which can be NULL) and a
|
||||
* random field which will use a DRBG that can return at least 96 bits of
|
||||
* entropy strength. (The DRBG must be seeded by the FIPS module).
|
||||
*/
|
||||
static int aes_gcm_iv_generate(EVP_AES_GCM_CTX *gctx, int offset)
|
||||
{
|
||||
int sz = gctx->ivlen - offset;
|
||||
|
||||
/* Must be at least 96 bits */
|
||||
if (sz <= 0 || gctx->ivlen < 12)
|
||||
return 0;
|
||||
|
||||
/* Use DRBG to generate random iv */
|
||||
if (RAND_bytes(gctx->iv + offset, sz) <= 0)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
#endif /* FIPS_MODE */
|
||||
|
||||
static int aes_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
const unsigned char *in, size_t len)
|
||||
{
|
||||
EVP_AES_GCM_CTX *gctx = EVP_C_DATA(EVP_AES_GCM_CTX,ctx);
|
||||
|
||||
/* If not set up, return error */
|
||||
if (!gctx->key_set)
|
||||
return -1;
|
||||
@@ -3213,8 +3239,25 @@ static int aes_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
if (gctx->tls_aad_len >= 0)
|
||||
return aes_gcm_tls_cipher(ctx, out, in, len);
|
||||
|
||||
#ifdef FIPS_MODE
|
||||
/*
|
||||
* FIPS requires generation of AES-GCM IV's inside the FIPS module.
|
||||
* The IV can still be set externally (the security policy will state that
|
||||
* this is not FIPS compliant). There are some applications
|
||||
* where setting the IV externally is the only option available.
|
||||
*/
|
||||
if (!gctx->iv_set) {
|
||||
if (!ctx->encrypt || !aes_gcm_iv_generate(gctx, 0))
|
||||
return -1;
|
||||
CRYPTO_gcm128_setiv(&gctx->gcm, gctx->iv, gctx->ivlen);
|
||||
gctx->iv_set = 1;
|
||||
gctx->iv_gen_rand = 1;
|
||||
}
|
||||
#else
|
||||
if (!gctx->iv_set)
|
||||
return -1;
|
||||
#endif /* FIPS_MODE */
|
||||
|
||||
if (in) {
|
||||
if (out == NULL) {
|
||||
if (CRYPTO_gcm128_aad(&gctx->gcm, in, len))
|
||||
|
||||
@@ -30,6 +30,8 @@ typedef struct {
|
||||
|
||||
#define data(ctx) ((EVP_CHACHA_KEY *)(ctx)->cipher_data)
|
||||
|
||||
#define CHACHA20_POLY1305_MAX_IVLEN 12
|
||||
|
||||
static int chacha_init_key(EVP_CIPHER_CTX *ctx,
|
||||
const unsigned char user_key[CHACHA_KEY_SIZE],
|
||||
const unsigned char iv[CHACHA_CTR_SIZE], int enc)
|
||||
@@ -575,7 +577,7 @@ static int chacha20_poly1305_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
|
||||
|
||||
case EVP_CTRL_AEAD_SET_IVLEN:
|
||||
if (actx->draft) return -1;
|
||||
if (arg <= 0 || arg > CHACHA_CTR_SIZE)
|
||||
if (arg <= 0 || arg > CHACHA20_POLY1305_MAX_IVLEN)
|
||||
return 0;
|
||||
actx->nonce_len = arg;
|
||||
return 1;
|
||||
|
||||
+1
-1
@@ -134,7 +134,7 @@ void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx)
|
||||
OPENSSL_free(ctx);
|
||||
}
|
||||
|
||||
int EVP_ENCODE_CTX_copy(EVP_ENCODE_CTX *dctx, EVP_ENCODE_CTX *sctx)
|
||||
int EVP_ENCODE_CTX_copy(EVP_ENCODE_CTX *dctx, const EVP_ENCODE_CTX *sctx)
|
||||
{
|
||||
memcpy(dctx, sctx, sizeof(EVP_ENCODE_CTX));
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ EVP_PKEY *EVP_PKCS82PKEY(const PKCS8_PRIV_KEY_INFO *p8)
|
||||
|
||||
/* Turn a private key into a PKCS8 structure */
|
||||
|
||||
PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey)
|
||||
PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(const EVP_PKEY *pkey)
|
||||
{
|
||||
PKCS8_PRIV_KEY_INFO *p8 = PKCS8_PRIV_KEY_INFO_new();
|
||||
if (p8 == NULL) {
|
||||
|
||||
@@ -29,7 +29,8 @@ static const EVP_KDF_METHOD *standard_methods[] = {
|
||||
&scrypt_kdf_meth,
|
||||
#endif
|
||||
&tls1_prf_kdf_meth,
|
||||
&hkdf_kdf_meth
|
||||
&hkdf_kdf_meth,
|
||||
&sshkdf_kdf_meth,
|
||||
};
|
||||
|
||||
DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_KDF_METHOD *, const EVP_KDF_METHOD *,
|
||||
|
||||
@@ -48,7 +48,7 @@ void EVP_MAC_CTX_free(EVP_MAC_CTX *ctx)
|
||||
OPENSSL_free(ctx);
|
||||
}
|
||||
|
||||
int EVP_MAC_CTX_copy(EVP_MAC_CTX *dst, EVP_MAC_CTX *src)
|
||||
int EVP_MAC_CTX_copy(EVP_MAC_CTX *dst, const EVP_MAC_CTX *src)
|
||||
{
|
||||
EVP_MAC_IMPL *macdata;
|
||||
|
||||
|
||||
+16
-25
@@ -14,16 +14,10 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/kdf.h>
|
||||
#include <openssl/hmac.h>
|
||||
#include <openssl/trace.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "evp_locl.h"
|
||||
|
||||
/* set this to print out info about the keygen algorithm */
|
||||
/* #define OPENSSL_DEBUG_PKCS5V2 */
|
||||
|
||||
#ifdef OPENSSL_DEBUG_PKCS5V2
|
||||
static void h__dump(const unsigned char *p, int len);
|
||||
#endif
|
||||
|
||||
int PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
|
||||
const unsigned char *salt, int saltlen, int iter,
|
||||
const EVP_MD *digest, int keylen, unsigned char *out)
|
||||
@@ -55,15 +49,21 @@ int PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
|
||||
|
||||
EVP_KDF_CTX_free(kctx);
|
||||
|
||||
# ifdef OPENSSL_DEBUG_PKCS5V2
|
||||
fprintf(stderr, "Password:\n");
|
||||
h__dump(pass, passlen);
|
||||
fprintf(stderr, "Salt:\n");
|
||||
h__dump(salt, saltlen);
|
||||
fprintf(stderr, "Iteration count %d\n", iter);
|
||||
fprintf(stderr, "Key:\n");
|
||||
h__dump(out, keylen);
|
||||
# endif
|
||||
OSSL_TRACE_BEGIN(PKCS5V2) {
|
||||
BIO_printf(trc_out, "Password:\n");
|
||||
BIO_hex_string(trc_out,
|
||||
0, passlen, pass, passlen);
|
||||
BIO_printf(trc_out, "\n");
|
||||
BIO_printf(trc_out, "Salt:\n");
|
||||
BIO_hex_string(trc_out,
|
||||
0, saltlen, salt, saltlen);
|
||||
BIO_printf(trc_out, "\n");
|
||||
BIO_printf(trc_out, "Iteration count %d\n", iter);
|
||||
BIO_printf(trc_out, "Key:\n");
|
||||
BIO_hex_string(trc_out,
|
||||
0, keylen, out, keylen);
|
||||
BIO_printf(trc_out, "\n");
|
||||
} OSSL_TRACE_END(PKCS5V2);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -200,12 +200,3 @@ int PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass,
|
||||
PBKDF2PARAM_free(kdf);
|
||||
return rv;
|
||||
}
|
||||
|
||||
# ifdef OPENSSL_DEBUG_PKCS5V2
|
||||
static void h__dump(const unsigned char *p, int len)
|
||||
{
|
||||
for (; len--; p++)
|
||||
fprintf(stderr, "%02X ", *p);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
# endif
|
||||
+4
-4
@@ -460,7 +460,7 @@ int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key)
|
||||
return ret;
|
||||
}
|
||||
|
||||
RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey)
|
||||
RSA *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey)
|
||||
{
|
||||
if (pkey->type != EVP_PKEY_RSA) {
|
||||
EVPerr(EVP_F_EVP_PKEY_GET0_RSA, EVP_R_EXPECTING_AN_RSA_KEY);
|
||||
@@ -487,7 +487,7 @@ int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key)
|
||||
return ret;
|
||||
}
|
||||
|
||||
DSA *EVP_PKEY_get0_DSA(EVP_PKEY *pkey)
|
||||
DSA *EVP_PKEY_get0_DSA(const EVP_PKEY *pkey)
|
||||
{
|
||||
if (pkey->type != EVP_PKEY_DSA) {
|
||||
EVPerr(EVP_F_EVP_PKEY_GET0_DSA, EVP_R_EXPECTING_A_DSA_KEY);
|
||||
@@ -515,7 +515,7 @@ int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key)
|
||||
return ret;
|
||||
}
|
||||
|
||||
EC_KEY *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey)
|
||||
EC_KEY *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey)
|
||||
{
|
||||
if (pkey->type != EVP_PKEY_EC) {
|
||||
EVPerr(EVP_F_EVP_PKEY_GET0_EC_KEY, EVP_R_EXPECTING_A_EC_KEY);
|
||||
@@ -543,7 +543,7 @@ int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key)
|
||||
return ret;
|
||||
}
|
||||
|
||||
DH *EVP_PKEY_get0_DH(EVP_PKEY *pkey)
|
||||
DH *EVP_PKEY_get0_DH(const EVP_PKEY *pkey)
|
||||
{
|
||||
if (pkey->type != EVP_PKEY_DH && pkey->type != EVP_PKEY_DHX) {
|
||||
EVPerr(EVP_F_EVP_PKEY_GET0_DH, EVP_R_EXPECTING_A_DH_KEY);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/kdf.h>
|
||||
#include "internal/numbers.h"
|
||||
|
||||
#ifndef OPENSSL_NO_SCRYPT
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/kdf.h>
|
||||
#include "internal/numbers.h"
|
||||
#include "internal/evp_int.h"
|
||||
|
||||
static int pkey_kdf_init(EVP_PKEY_CTX *ctx)
|
||||
|
||||
@@ -71,7 +71,7 @@ static int pkey_mac_init(EVP_PKEY_CTX *ctx)
|
||||
|
||||
static void pkey_mac_cleanup(EVP_PKEY_CTX *ctx);
|
||||
|
||||
static int pkey_mac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
|
||||
static int pkey_mac_copy(EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src)
|
||||
{
|
||||
MAC_PKEY_CTX *sctx, *dctx;
|
||||
|
||||
|
||||
@@ -250,7 +250,7 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_new_id(int id, ENGINE *e)
|
||||
return int_ctx_new(NULL, e, id);
|
||||
}
|
||||
|
||||
EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx)
|
||||
EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *pctx)
|
||||
{
|
||||
EVP_PKEY_CTX *rctx;
|
||||
if (!pctx->pmeth || !pctx->pmeth->copy)
|
||||
@@ -472,7 +472,7 @@ void EVP_PKEY_CTX_set_data(EVP_PKEY_CTX *ctx, void *data)
|
||||
ctx->data = data;
|
||||
}
|
||||
|
||||
void *EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx)
|
||||
void *EVP_PKEY_CTX_get_data(const EVP_PKEY_CTX *ctx)
|
||||
{
|
||||
return ctx->data;
|
||||
}
|
||||
@@ -505,7 +505,7 @@ void EVP_PKEY_meth_set_init(EVP_PKEY_METHOD *pmeth,
|
||||
|
||||
void EVP_PKEY_meth_set_copy(EVP_PKEY_METHOD *pmeth,
|
||||
int (*copy) (EVP_PKEY_CTX *dst,
|
||||
EVP_PKEY_CTX *src))
|
||||
const EVP_PKEY_CTX *src))
|
||||
{
|
||||
pmeth->copy = copy;
|
||||
}
|
||||
@@ -675,7 +675,7 @@ void EVP_PKEY_meth_get_init(const EVP_PKEY_METHOD *pmeth,
|
||||
|
||||
void EVP_PKEY_meth_get_copy(const EVP_PKEY_METHOD *pmeth,
|
||||
int (**pcopy) (EVP_PKEY_CTX *dst,
|
||||
EVP_PKEY_CTX *src))
|
||||
const EVP_PKEY_CTX *src))
|
||||
{
|
||||
*pcopy = pmeth->copy;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user