diff options
author | Shane Lontis <shane.lontis@oracle.com> | 2019-09-05 11:23:57 +1000 |
---|---|---|
committer | Shane Lontis <shane.lontis@oracle.com> | 2019-09-05 11:23:57 +1000 |
commit | 1c3ace6898032b7b45d8106ba4e0d21d75b0997e (patch) | |
tree | 5e07997567a0c99c1a0d55a2a4d258f614b0f7e0 /providers | |
parent | bc5a80910dccbc1e417f96bb7f0a3814d3ad5a4d (diff) |
Change provider params from int to size_t
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9699)
Diffstat (limited to 'providers')
-rw-r--r-- | providers/common/ciphers/cipher_ccm.c | 4 | ||||
-rw-r--r-- | providers/common/ciphers/cipher_common.c | 58 | ||||
-rw-r--r-- | providers/common/ciphers/cipher_gcm.c | 28 | ||||
-rw-r--r-- | providers/common/ciphers/cipher_gcm_hw.c | 2 | ||||
-rw-r--r-- | providers/common/ciphers/cipher_locl.h | 8 | ||||
-rw-r--r-- | providers/common/digests/digest_common.c | 13 | ||||
-rw-r--r-- | providers/common/exchange/dh_exch.c | 10 | ||||
-rw-r--r-- | providers/common/include/internal/ciphers/cipher_aead.h | 2 | ||||
-rw-r--r-- | providers/common/include/internal/ciphers/cipher_ccm.h | 22 | ||||
-rw-r--r-- | providers/common/include/internal/ciphers/cipher_gcm.h | 30 | ||||
-rw-r--r-- | providers/common/include/internal/ciphers/ciphercommon.h | 25 | ||||
-rw-r--r-- | providers/common/include/internal/digestcommon.h | 2 | ||||
-rw-r--r-- | providers/legacy/digests/mdc2_prov.c | 4 |
13 files changed, 107 insertions, 101 deletions
diff --git a/providers/common/ciphers/cipher_ccm.c b/providers/common/ciphers/cipher_ccm.c index 211b64f768..8970b02670 100644 --- a/providers/common/ciphers/cipher_ccm.c +++ b/providers/common/ciphers/cipher_ccm.c @@ -143,7 +143,7 @@ int ccm_get_ctx_params(void *vctx, OSSL_PARAM params[]) OSSL_PARAM *p; p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_IVLEN); - if (p != NULL && !OSSL_PARAM_set_int(p, ccm_get_ivlen(ctx))) { + if (p != NULL && !OSSL_PARAM_set_size_t(p, ccm_get_ivlen(ctx))) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); return 0; } @@ -161,7 +161,7 @@ int ccm_get_ctx_params(void *vctx, OSSL_PARAM params[]) } p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_KEYLEN); - if (p != NULL && !OSSL_PARAM_set_int(p, ctx->keylen)) { + if (p != NULL && !OSSL_PARAM_set_size_t(p, ctx->keylen)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); return 0; } diff --git a/providers/common/ciphers/cipher_common.c b/providers/common/ciphers/cipher_common.c index 5abd2c0010..de67fc1341 100644 --- a/providers/common/ciphers/cipher_common.c +++ b/providers/common/ciphers/cipher_common.c @@ -19,10 +19,11 @@ * Generic cipher functions for OSSL_PARAM gettables and settables */ static const OSSL_PARAM cipher_known_gettable_params[] = { - OSSL_PARAM_int(OSSL_CIPHER_PARAM_MODE, NULL), - OSSL_PARAM_int(OSSL_CIPHER_PARAM_KEYLEN, NULL), - OSSL_PARAM_int(OSSL_CIPHER_PARAM_IVLEN, NULL), - OSSL_PARAM_int(OSSL_CIPHER_PARAM_BLOCK_SIZE, NULL), + OSSL_PARAM_uint(OSSL_CIPHER_PARAM_MODE, NULL), + OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_KEYLEN, NULL), + OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_IVLEN, NULL), + OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_BLOCK_SIZE, NULL), + OSSL_PARAM_ulong(OSSL_CIPHER_PARAM_FLAGS, NULL), OSSL_PARAM_END }; const OSSL_PARAM *cipher_generic_gettable_params(void) @@ -30,13 +31,14 @@ const OSSL_PARAM *cipher_generic_gettable_params(void) return cipher_known_gettable_params; } -int cipher_generic_get_params(OSSL_PARAM params[], int md, unsigned long flags, - int kbits, int blkbits, int ivbits) +int cipher_generic_get_params(OSSL_PARAM params[], unsigned int md, + unsigned long flags, + size_t kbits, size_t blkbits, size_t ivbits) { OSSL_PARAM *p; p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_MODE); - if (p != NULL && !OSSL_PARAM_set_int(p, md)) { + if (p != NULL && !OSSL_PARAM_set_uint(p, md)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); return 0; } @@ -46,17 +48,17 @@ int cipher_generic_get_params(OSSL_PARAM params[], int md, unsigned long flags, return 0; } p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_KEYLEN); - if (p != NULL && !OSSL_PARAM_set_int(p, kbits / 8)) { + if (p != NULL && !OSSL_PARAM_set_size_t(p, kbits / 8)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); return 0; } p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_BLOCK_SIZE); - if (p != NULL && !OSSL_PARAM_set_int(p, blkbits / 8)) { + if (p != NULL && !OSSL_PARAM_set_size_t(p, blkbits / 8)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); return 0; } p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_IVLEN); - if (p != NULL && !OSSL_PARAM_set_int(p, ivbits / 8)) { + if (p != NULL && !OSSL_PARAM_set_size_t(p, ivbits / 8)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); return 0; } @@ -67,9 +69,9 @@ CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_START(cipher_generic) CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_END(cipher_generic) static const OSSL_PARAM cipher_known_settable_ctx_params[] = { - OSSL_PARAM_int(OSSL_CIPHER_PARAM_KEYLEN, NULL), - OSSL_PARAM_int(OSSL_CIPHER_PARAM_PADDING, NULL), - OSSL_PARAM_int(OSSL_CIPHER_PARAM_NUM, NULL), + OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_KEYLEN, NULL), + OSSL_PARAM_uint(OSSL_CIPHER_PARAM_PADDING, NULL), + OSSL_PARAM_uint(OSSL_CIPHER_PARAM_NUM, NULL), OSSL_PARAM_END }; const OSSL_PARAM *cipher_generic_settable_ctx_params(void) @@ -81,8 +83,8 @@ const OSSL_PARAM *cipher_generic_settable_ctx_params(void) * AEAD cipher functions for OSSL_PARAM gettables and settables */ static const OSSL_PARAM cipher_aead_known_gettable_ctx_params[] = { - OSSL_PARAM_int(OSSL_CIPHER_PARAM_KEYLEN, NULL), - OSSL_PARAM_int(OSSL_CIPHER_PARAM_IVLEN, NULL), + OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_KEYLEN, NULL), + OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_IVLEN, NULL), OSSL_PARAM_octet_string(OSSL_CIPHER_PARAM_IV, NULL, 0), OSSL_PARAM_octet_string(OSSL_CIPHER_PARAM_AEAD_TAG, NULL, 0), OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_AEAD_TLS1_AAD_PAD, NULL), @@ -94,7 +96,7 @@ const OSSL_PARAM *cipher_aead_gettable_ctx_params(void) } static const OSSL_PARAM cipher_aead_known_settable_ctx_params[] = { - OSSL_PARAM_int(OSSL_CIPHER_PARAM_KEYLEN, NULL), + OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_KEYLEN, NULL), OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_AEAD_IVLEN, NULL), OSSL_PARAM_octet_string(OSSL_CIPHER_PARAM_AEAD_TAG, NULL, 0), OSSL_PARAM_octet_string(OSSL_CIPHER_PARAM_AEAD_TLS1_AAD, NULL, 0), @@ -111,7 +113,7 @@ static int cipher_generic_init_internal(PROV_CIPHER_CTX *ctx, const unsigned char *iv, size_t ivlen, int enc) { - ctx->enc = enc; + ctx->enc = enc ? 1 : 0; if (iv != NULL && ctx->mode != EVP_CIPH_ECB_MODE) { if (ivlen != ctx->ivlen) { @@ -312,12 +314,12 @@ int cipher_generic_get_ctx_params(void *vctx, OSSL_PARAM params[]) OSSL_PARAM *p; p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_IVLEN); - if (p != NULL && !OSSL_PARAM_set_int(p, ctx->ivlen)) { + if (p != NULL && !OSSL_PARAM_set_size_t(p, ctx->ivlen)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); return 0; } p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_PADDING); - if (p != NULL && !OSSL_PARAM_set_int(p, ctx->pad)) { + if (p != NULL && !OSSL_PARAM_set_uint(p, ctx->pad)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); return 0; } @@ -329,12 +331,12 @@ int cipher_generic_get_ctx_params(void *vctx, OSSL_PARAM params[]) return 0; } p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_NUM); - if (p != NULL && !OSSL_PARAM_set_size_t(p, ctx->num)) { + if (p != NULL && !OSSL_PARAM_set_uint(p, ctx->num)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); return 0; } p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_KEYLEN); - if (p != NULL && !OSSL_PARAM_set_int(p, ctx->keylen)) { + if (p != NULL && !OSSL_PARAM_set_size_t(p, ctx->keylen)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); return 0; } @@ -349,9 +351,9 @@ int cipher_generic_set_ctx_params(void *vctx, const OSSL_PARAM params[]) p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_PADDING); if (p != NULL) { - int pad; + unsigned int pad; - if (!OSSL_PARAM_get_int(p, &pad)) { + if (!OSSL_PARAM_get_uint(p, &pad)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); return 0; } @@ -359,9 +361,9 @@ int cipher_generic_set_ctx_params(void *vctx, const OSSL_PARAM params[]) } p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_NUM); if (p != NULL) { - int num; + unsigned int num; - if (!OSSL_PARAM_get_int(p, &num)) { + if (!OSSL_PARAM_get_uint(p, &num)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); return 0; } @@ -369,9 +371,9 @@ int cipher_generic_set_ctx_params(void *vctx, const OSSL_PARAM params[]) } p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_KEYLEN); if (p != NULL) { - int keylen; + size_t keylen; - if (!OSSL_PARAM_get_int(p, &keylen)) { + if (!OSSL_PARAM_get_size_t(p, &keylen)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); return 0; } @@ -381,7 +383,7 @@ int cipher_generic_set_ctx_params(void *vctx, const OSSL_PARAM params[]) } void cipher_generic_initkey(void *vctx, size_t kbits, size_t blkbits, - size_t ivbits, int mode, + size_t ivbits, unsigned int mode, const PROV_CIPHER_HW *hw, void *provctx) { PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx; diff --git a/providers/common/ciphers/cipher_gcm.c b/providers/common/ciphers/cipher_gcm.c index 7d0e47b823..4247319091 100644 --- a/providers/common/ciphers/cipher_gcm.c +++ b/providers/common/ciphers/cipher_gcm.c @@ -29,8 +29,8 @@ void gcm_initctx(void *provctx, PROV_GCM_CTX *ctx, size_t keybits, { ctx->pad = 1; ctx->mode = EVP_CIPH_GCM_MODE; - ctx->taglen = -1; - ctx->tls_aad_len = -1; + ctx->taglen = UNINITIALISED_SIZET; + ctx->tls_aad_len = UNINITIALISED_SIZET; ctx->ivlen_min = ivlen_min; ctx->ivlen = (EVP_GCM_TLS_FIXED_IV_LEN + EVP_GCM_TLS_EXPLICIT_IV_LEN); ctx->keylen = keybits / 8; @@ -89,12 +89,12 @@ int gcm_get_ctx_params(void *vctx, OSSL_PARAM params[]) size_t sz; p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_IVLEN); - if (p != NULL && !OSSL_PARAM_set_int(p, ctx->ivlen)) { + if (p != NULL && !OSSL_PARAM_set_size_t(p, ctx->ivlen)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); return 0; } p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_KEYLEN); - if (p != NULL && !OSSL_PARAM_set_int(p, ctx->keylen)) { + if (p != NULL && !OSSL_PARAM_set_size_t(p, ctx->keylen)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); return 0; } @@ -103,7 +103,7 @@ int gcm_get_ctx_params(void *vctx, OSSL_PARAM params[]) if (p != NULL) { if (ctx->iv_gen != 1 && ctx->iv_gen_rand != 1) return 0; - if (ctx->ivlen != (int)p->data_size) { + if (ctx->ivlen != p->data_size) { ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_IV_LENGTH); return 0; } @@ -121,7 +121,10 @@ int gcm_get_ctx_params(void *vctx, OSSL_PARAM params[]) p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_AEAD_TAG); if (p != NULL) { sz = p->data_size; - if (sz == 0 || sz > EVP_GCM_TLS_TAG_LEN || !ctx->enc || ctx->taglen < 0) { + if (sz == 0 + || sz > EVP_GCM_TLS_TAG_LEN + || !ctx->enc + || ctx->taglen == UNINITIALISED_SIZET) { ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_TAG); return 0; } @@ -201,14 +204,14 @@ int gcm_set_ctx_params(void *vctx, const OSSL_PARAM params[]) */ p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_KEYLEN); if (p != NULL) { - int keylen; + size_t keylen; - if (!OSSL_PARAM_get_int(p, &keylen)) { + if (!OSSL_PARAM_get_size_t(p, &keylen)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); return 0; } /* The key length can not be modified for gcm mode */ - if (keylen != (int)ctx->keylen) + if (keylen != ctx->keylen) return 0; } @@ -296,7 +299,7 @@ static int gcm_cipher_internal(PROV_GCM_CTX *ctx, unsigned char *out, int rv = 0; const PROV_GCM_HW *hw = ctx->hw; - if (ctx->tls_aad_len >= 0) + if (ctx->tls_aad_len != UNINITIALISED_SIZET) return gcm_tls_cipher(ctx, out, padlen, in, len); if (!ctx->key_set || ctx->iv_state == IV_STATE_FINISHED) @@ -425,7 +428,8 @@ static void ctr64_inc(unsigned char *counter) static int gcm_tls_cipher(PROV_GCM_CTX *ctx, unsigned char *out, size_t *padlen, const unsigned char *in, size_t len) { - int rv = 0, arg = EVP_GCM_TLS_EXPLICIT_IV_LEN; + int rv = 0; + size_t arg = EVP_GCM_TLS_EXPLICIT_IV_LEN; size_t plen = 0; unsigned char *tag = NULL; @@ -491,7 +495,7 @@ static int gcm_tls_cipher(PROV_GCM_CTX *ctx, unsigned char *out, size_t *padlen, rv = 1; err: ctx->iv_state = IV_STATE_FINISHED; - ctx->tls_aad_len = -1; + ctx->tls_aad_len = UNINITIALISED_SIZET; *padlen = plen; return rv; } diff --git a/providers/common/ciphers/cipher_gcm_hw.c b/providers/common/ciphers/cipher_gcm_hw.c index 4ef5190b5f..e2587f2e5e 100644 --- a/providers/common/ciphers/cipher_gcm_hw.c +++ b/providers/common/ciphers/cipher_gcm_hw.c @@ -90,7 +90,7 @@ int gcm_cipher_final(PROV_GCM_CTX *ctx, unsigned char *tag) CRYPTO_gcm128_tag(&ctx->gcm, tag, GCM_TAG_MAX_SIZE); ctx->taglen = GCM_TAG_MAX_SIZE; } else { - if (ctx->taglen < 0 + if (ctx->taglen == UNINITIALISED_SIZET || CRYPTO_gcm128_finish(&ctx->gcm, tag, ctx->taglen) != 0) return 0; } diff --git a/providers/common/ciphers/cipher_locl.h b/providers/common/ciphers/cipher_locl.h index 8313498e5e..7e0aaad438 100644 --- a/providers/common/ciphers/cipher_locl.h +++ b/providers/common/ciphers/cipher_locl.h @@ -11,10 +11,10 @@ #define CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_START(name) \ static const OSSL_PARAM name##_known_gettable_ctx_params[] = { \ - OSSL_PARAM_int(OSSL_CIPHER_PARAM_KEYLEN, NULL), \ - OSSL_PARAM_int(OSSL_CIPHER_PARAM_IVLEN, NULL), \ - OSSL_PARAM_int(OSSL_CIPHER_PARAM_PADDING, NULL), \ - OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_NUM, NULL), \ + OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_KEYLEN, NULL), \ + OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_IVLEN, NULL), \ + OSSL_PARAM_uint(OSSL_CIPHER_PARAM_PADDING, NULL), \ + OSSL_PARAM_uint(OSSL_CIPHER_PARAM_NUM, NULL), \ OSSL_PARAM_octet_string(OSSL_CIPHER_PARAM_IV, NULL, 0), #define CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_END(name) \ diff --git a/providers/common/digests/digest_common.c b/providers/common/digests/digest_common.c index de135b0a94..062209f329 100644 --- a/providers/common/digests/digest_common.c +++ b/providers/common/digests/digest_common.c @@ -11,18 +11,18 @@ #include "internal/digestcommon.h" #include "internal/providercommonerr.h" -int digest_default_get_params(OSSL_PARAM params[], int blksz, int paramsz, +int digest_default_get_params(OSSL_PARAM params[], size_t blksz, size_t paramsz, unsigned long flags) { OSSL_PARAM *p = NULL; p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_BLOCK_SIZE); - if (p != NULL && !OSSL_PARAM_set_int(p, blksz)) { + if (p != NULL && !OSSL_PARAM_set_size_t(p, blksz)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); return 0; } p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_SIZE); - if (p != NULL && !OSSL_PARAM_set_int(p, paramsz)) { + if (p != NULL && !OSSL_PARAM_set_size_t(p, paramsz)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); return 0; } @@ -35,10 +35,9 @@ int digest_default_get_params(OSSL_PARAM params[], int blksz, int paramsz, } static const OSSL_PARAM digest_default_known_gettable_params[] = { - { OSSL_DIGEST_PARAM_BLOCK_SIZE, OSSL_PARAM_INTEGER, NULL, sizeof(int), 0}, - { OSSL_DIGEST_PARAM_SIZE, OSSL_PARAM_INTEGER, NULL, sizeof(int), 0}, - { OSSL_DIGEST_PARAM_FLAGS, OSSL_PARAM_INTEGER, NULL, - sizeof(unsigned long), 0}, + OSSL_PARAM_size_t(OSSL_DIGEST_PARAM_BLOCK_SIZE, NULL), + OSSL_PARAM_size_t(OSSL_DIGEST_PARAM_SIZE, NULL), + OSSL_PARAM_ulong(OSSL_DIGEST_PARAM_FLAGS, NULL), OSSL_PARAM_END }; const OSSL_PARAM *digest_default_gettable_params(void) diff --git a/providers/common/exchange/dh_exch.c b/providers/common/exchange/dh_exch.c index 69980d8e97..5ff8318725 100644 --- a/providers/common/exchange/dh_exch.c +++ b/providers/common/exchange/dh_exch.c @@ -30,7 +30,7 @@ static OSSL_OP_keyexch_dupctx_fn dh_dupctx; typedef struct { DH *dh; DH *dhpeer; - int pad; + unsigned int pad : 1; } PROV_DH_CTX; static void *dh_newctx(void *provctx) @@ -128,17 +128,15 @@ static int dh_set_params(void *vpdhctx, const OSSL_PARAM params[]) { PROV_DH_CTX *pdhctx = (PROV_DH_CTX *)vpdhctx; const OSSL_PARAM *p; - int pad; + unsigned int pad; if (pdhctx == NULL || params == NULL) return 0; p = OSSL_PARAM_locate_const(params, OSSL_EXCHANGE_PARAM_PAD); - if (p == NULL || !OSSL_PARAM_get_int(p, &pad)) + if (p == NULL || !OSSL_PARAM_get_uint(p, &pad)) return 0; - - pdhctx->pad = pad; - + pdhctx->pad = pad ? 1 : 0; return 1; } diff --git a/providers/common/include/internal/ciphers/cipher_aead.h b/providers/common/include/internal/ciphers/cipher_aead.h index a2fe87e967..1ddba1c325 100644 --- a/providers/common/include/internal/ciphers/cipher_aead.h +++ b/providers/common/include/internal/ciphers/cipher_aead.h @@ -7,6 +7,8 @@ * https://www.openssl.org/source/license.html */ +#define UNINITIALISED_SIZET ((size_t)-1) + /* TODO(3.0) Figure out what flags are really needed */ #define AEAD_FLAGS (EVP_CIPH_FLAG_AEAD_CIPHER | EVP_CIPH_FLAG_DEFAULT_ASN1 \ | EVP_CIPH_CUSTOM_IV | EVP_CIPH_FLAG_CUSTOM_CIPHER \ diff --git a/providers/common/include/internal/ciphers/cipher_ccm.h b/providers/common/include/internal/ciphers/cipher_ccm.h index 503d077def..08a2d46858 100644 --- a/providers/common/include/internal/ciphers/cipher_ccm.h +++ b/providers/common/include/internal/ciphers/cipher_ccm.h @@ -28,24 +28,24 @@ typedef struct S390X_kmac_params_st { /* Base structure that is shared by AES & ARIA for CCM MODE */ typedef struct prov_ccm_st { - int enc; - int key_set; /* Set if key initialised */ - int iv_set; /* Set if an iv is set */ - int tag_set; /* Set if tag is valid */ - int len_set; /* Set if message length set */ - size_t l, m; /* L and M parameters from RFC3610 */ + unsigned int enc : 1; + unsigned int key_set : 1; /* Set if key initialised */ + unsigned int iv_set : 1; /* Set if an iv is set */ + unsigned int tag_set : 1; /* Set if tag is valid */ + unsigned int len_set : 1; /* Set if message length set */ + size_t l, m; /* L and M parameters from RFC3610 */ size_t keylen; - int tls_aad_len; /* TLS AAD length */ - int tls_aad_pad_sz; + int tls_aad_len; /* TLS AAD length */ + size_t tls_aad_pad_sz; unsigned char iv[AES_BLOCK_SIZE]; unsigned char buf[AES_BLOCK_SIZE]; CCM128_CONTEXT ccm_ctx; ccm128_f str; - const PROV_CCM_HW *hw; /* hardware specific methods */ + const PROV_CCM_HW *hw; /* hardware specific methods */ } PROV_CCM_CTX; typedef struct prov_aes_ccm_ctx_st { - PROV_CCM_CTX base; /* Must be first */ + PROV_CCM_CTX base; /* Must be first */ union { OSSL_UNION_ALIGN; /*- @@ -71,7 +71,7 @@ typedef struct prov_aes_ccm_ctx_st { unsigned char b[AES_BLOCK_SIZE]; } buf; unsigned char dummy_pad[168]; - unsigned int fc; /* fc has same offset as ks.ks.rounds */ + unsigned int fc; /* fc has same offset as ks.ks.rounds */ } s390x; #endif /* defined(OPENSSL_CPUID_OBJ) && defined(__s390__) */ } ccm; diff --git a/providers/common/include/internal/ciphers/cipher_gcm.h b/providers/common/include/internal/ciphers/cipher_gcm.h index 63600c38e7..f4e2894fe2 100644 --- a/providers/common/include/internal/ciphers/cipher_gcm.h +++ b/providers/common/include/internal/ciphers/cipher_gcm.h @@ -13,7 +13,7 @@ typedef struct prov_gcm_hw_st PROV_GCM_HW; -#define GCM_IV_DEFAULT_SIZE 12/* IV's for AES_GCM should normally be 12 bytes */ +#define GCM_IV_DEFAULT_SIZE 12 /* IV's for AES_GCM should normally be 12 bytes */ #define GCM_IV_MAX_SIZE 64 #define GCM_TAG_MAX_SIZE 16 @@ -45,18 +45,13 @@ typedef struct S390X_kma_params_st { #endif typedef struct prov_gcm_ctx_st { - int enc; /* Set to 1 if we are encrypting or 0 otherwise */ - int mode; /* The mode that we are using */ + unsigned int mode; /* The mode that we are using */ size_t keylen; - int ivlen; + size_t ivlen; size_t ivlen_min; - int taglen; - int key_set; /* Set if key initialised */ - int iv_state; /* set to one of IV_STATE_XXX */ - int iv_gen_rand; /* No IV was specified, so generate a rand IV */ - int iv_gen; /* It is OK to generate IVs */ - int tls_aad_pad_sz; - int tls_aad_len; /* TLS AAD length */ + size_t taglen; + size_t tls_aad_pad_sz; + size_t tls_aad_len; /* TLS AAD length */ uint64_t tls_enc_records; /* Number of TLS records encrypted */ /* @@ -64,13 +59,18 @@ typedef struct prov_gcm_ctx_st { * manage partial blocks themselves. */ size_t num; - size_t bufsz; /* Number of bytes in buf */ + size_t bufsz; /* Number of bytes in buf */ uint64_t flags; - unsigned int pad : 1; /* Whether padding should be used or not */ + unsigned int iv_state; /* set to one of IV_STATE_XXX */ + unsigned int enc:1; /* Set to 1 if we are encrypting or 0 otherwise */ + unsigned int pad:1; /* Whether padding should be used or not */ + unsigned int key_set:1; /* Set if key initialised */ + unsigned int iv_gen_rand:1; /* No IV was specified, so generate a rand IV */ + unsigned int iv_gen:1; /* It is OK to generate IVs */ unsigned char iv[GCM_IV_MAX_SIZE]; /* Buffer to use for IV's */ - unsigned char buf[AES_BLOCK_SIZE]; /* Buffer of partial blocks processed via update calls */ + unsigned char buf[AES_BLOCK_SIZE]; /* Buffer of partial blocks processed via update calls */ OPENSSL_CTX *libctx; /* needed for rand calls */ const PROV_GCM_HW *hw; /* hardware specific methods */ @@ -153,7 +153,7 @@ int gcm_one_shot(PROV_GCM_CTX *ctx, unsigned char *aad, size_t aad_len, int gcm_cipher_update(PROV_GCM_CTX *ctx, const unsigned char *in, size_t len, unsigned char *out); -#define GCM_HW_SET_KEY_CTR_FN(ks, fn_set_enc_key, fn_block, fn_ctr) \ +#define GCM_HW_SET_KEY_CTR_FN(ks, fn_set_enc_key, fn_block, fn_ctr) \ ctx->ks = ks; \ fn_set_enc_key(key, keylen * 8, ks); \ CRYPTO_gcm128_init(&ctx->gcm, ks, (block128_f)fn_block); \ diff --git a/providers/common/include/internal/ciphers/ciphercommon.h b/providers/common/include/internal/ciphers/ciphercommon.h index 38d0396902..5593447264 100644 --- a/providers/common/include/internal/ciphers/ciphercommon.h +++ b/providers/common/include/internal/ciphers/ciphercommon.h @@ -39,20 +39,20 @@ struct prov_cipher_ctx_st { ctr128_f ctr; } stream; + unsigned int mode; + size_t keylen; /* key size (in bytes) */ + size_t ivlen; + size_t blocksize; + size_t bufsz; /* Number of bytes in buf */ + unsigned int pad : 1; /* Whether padding should be used or not */ + unsigned int enc : 1; /* Set to 1 for encrypt, or 0 otherwise */ + /* * num contains the number of bytes of |iv| which are valid for modes that * manage partial blocks themselves. */ - size_t num; - - int mode; - int enc; /* Set to 1 for encrypt, or 0 otherwise */ - size_t bufsz; /* Number of bytes in buf */ - size_t keylen; /* key size (in bytes) */ - size_t ivlen; - size_t blocksize; + unsigned int num; uint64_t flags; - unsigned int pad : 1; /* Whether padding should be used or not */ /* Buffer of partial blocks processed via update calls */ unsigned char buf[GENERIC_BLOCK_SIZE]; @@ -81,10 +81,11 @@ OSSL_OP_cipher_gettable_ctx_params_fn cipher_generic_gettable_ctx_params; OSSL_OP_cipher_settable_ctx_params_fn cipher_generic_settable_ctx_params; OSSL_OP_cipher_gettable_ctx_params_fn cipher_aead_gettable_ctx_params; OSSL_OP_cipher_settable_ctx_params_fn cipher_aead_settable_ctx_params; -int cipher_generic_get_params(OSSL_PARAM params[], int md, unsigned long flags, - int kbits, int blkbits, int ivbits); +int cipher_generic_get_params(OSSL_PARAM params[], unsigned int md, + unsigned long flags, + size_t kbits, size_t blkbits, size_t ivbits); void cipher_generic_initkey(void *vctx, size_t kbits, size_t blkbits, - size_t ivbits, int mode, + size_t ivbits, unsigned int mode, const PROV_CIPHER_HW *hw, void *provctx); #define IMPLEMENT_generic_cipher(alg, UCALG, lcmode, UCMODE, flags, kbits, \ diff --git a/providers/common/include/internal/digestcommon.h b/providers/common/include/internal/digestcommon.h index 533e854e30..88caccf7cd 100644 --- a/providers/common/include/internal/digestcommon.h +++ b/providers/common/include/internal/digestcommon.h @@ -93,7 +93,7 @@ PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END const OSSL_PARAM *digest_default_gettable_params(void); -int digest_default_get_params(OSSL_PARAM params[], int blksz, int paramsz, +int digest_default_get_params(OSSL_PARAM params[], size_t blksz, size_t paramsz, unsigned long flags); # ifdef __cplusplus diff --git a/providers/legacy/digests/mdc2_prov.c b/providers/legacy/digests/mdc2_prov.c index b30d50327d..cf37b528e7 100644 --- a/providers/legacy/digests/mdc2_prov.c +++ b/providers/legacy/digests/mdc2_prov.c @@ -20,7 +20,7 @@ static OSSL_OP_digest_set_ctx_params_fn mdc2_set_ctx_params; static OSSL_OP_digest_settable_ctx_params_fn mdc2_settable_ctx_params; static const OSSL_PARAM known_mdc2_settable_ctx_params[] = { - {OSSL_DIGEST_PARAM_PAD_TYPE, OSSL_PARAM_INTEGER, NULL, sizeof(int), 0}, + OSSL_PARAM_uint(OSSL_DIGEST_PARAM_PAD_TYPE, NULL), OSSL_PARAM_END }; @@ -36,7 +36,7 @@ static int mdc2_set_ctx_params(void *vctx, const OSSL_PARAM params[]) if (ctx != NULL && params != NULL) { p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_PAD_TYPE); - if (p != NULL && !OSSL_PARAM_get_int(p, &ctx->pad_type)) { + if (p != NULL && !OSSL_PARAM_get_uint(p, &ctx->pad_type)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); return 0; } |