libapps + libcrypto: Silence warnings on Win64 builds

Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27806)
This commit is contained in:
Tomas Mraz 2025-06-11 10:48:01 +02:00
parent 2d978786f3
commit bb86c43fa8
201 changed files with 835 additions and 683 deletions

View File

@ -112,7 +112,7 @@ static void print_param_utf8(const char **s_ptr, size_t len)
}
BIO_puts(bio_out, "'");
if (len > 0)
BIO_write(bio_out, s, len);
BIO_write(bio_out, s, (int)len);
BIO_puts(bio_out, "'\n");
}

View File

@ -1595,7 +1595,7 @@ int save_serial(const char *serialfile, const char *suffix,
BIO *out = NULL;
int ret = 0;
ASN1_INTEGER *ai = NULL;
int j;
size_t j;
if (suffix == NULL)
j = strlen(serialfile);
@ -1643,7 +1643,7 @@ int rotate_serial(const char *serialfile, const char *new_suffix,
const char *old_suffix)
{
char buf[2][BSIZE];
int i, j;
size_t i, j;
i = strlen(serialfile) + strlen(old_suffix);
j = strlen(serialfile) + strlen(new_suffix);
@ -1807,7 +1807,7 @@ int save_index(const char *dbfile, const char *suffix, CA_DB *db)
BIO *out;
int j;
j = strlen(dbfile) + strlen(suffix);
j = (int)(strlen(dbfile) + strlen(suffix));
if (j + 6 >= BSIZE) {
BIO_printf(bio_err, "File name too long\n");
goto err;
@ -1852,7 +1852,7 @@ int rotate_index(const char *dbfile, const char *new_suffix,
const char *old_suffix)
{
char buf[5][BSIZE];
int i, j;
size_t i, j;
i = strlen(dbfile) + strlen(old_suffix);
j = strlen(dbfile) + strlen(new_suffix);
@ -2039,7 +2039,7 @@ X509_NAME *parse_name(const char *cp, int chtype, int canmulti,
continue;
}
if (!X509_NAME_add_entry_by_NID(n, nid, chtype,
valstr, strlen((char *)valstr),
valstr, (int)strlen((char *)valstr),
-1, ismulti ? -1 : 0)) {
ERR_print_errors(bio_err);
BIO_printf(bio_err,
@ -2764,12 +2764,12 @@ static int WIN32_rename(const char *from, const char *to)
goto err;
tto = tfrom + flen;
# if !defined(_WIN32_WCE) || _WIN32_WCE >= 101
if (!MultiByteToWideChar(CP_ACP, 0, from, flen, (WCHAR *)tfrom, flen))
if (!MultiByteToWideChar(CP_ACP, 0, from, (int)flen, (WCHAR *)tfrom, (int)flen))
# endif
for (i = 0; i < flen; i++)
tfrom[i] = (TCHAR)from[i];
# if !defined(_WIN32_WCE) || _WIN32_WCE >= 101
if (!MultiByteToWideChar(CP_ACP, 0, to, tlen, (WCHAR *)tto, tlen))
if (!MultiByteToWideChar(CP_ACP, 0, to, (int)tlen, (WCHAR *)tto, (int)tlen))
# endif
for (i = 0; i < tlen; i++)
tto[i] = (TCHAR)to[i];
@ -3275,7 +3275,7 @@ int mem_bio_to_file(BIO *in, const char *filename, int format, int private)
out = bio_open_owner(filename, format, private);
if (out == NULL)
goto end;
rv = BIO_write(out, mem_buffer->data, mem_buffer->length);
rv = BIO_write(out, mem_buffer->data, (int)mem_buffer->length);
if (rv < 0 || (size_t)rv != mem_buffer->length)
BIO_printf(bio_err, "Error writing to output file: '%s'\n", filename);
else

View File

@ -205,7 +205,7 @@ int password_callback(char *buf, int bufsiz, int verify, PW_CB_DATA *cb_data)
OPENSSL_clear_free(buff, (unsigned int)bufsiz);
if (ok >= 0)
res = strlen(buf);
res = (int)strlen(buf);
if (ok == -1) {
BIO_printf(bio_err, "User interface error\n");
ERR_print_errors(bio_err);

View File

@ -18,7 +18,7 @@ void calculate_columns(FUNCTION *functions, DISPLAY_COLUMNS *dc)
for (f = functions; f->name != NULL; ++f)
if (f->type == FT_general || f->type == FT_md || f->type == FT_cipher)
if ((len = strlen(f->name)) > maxlen)
if ((len = (int)strlen(f->name)) > maxlen)
maxlen = len;
dc->width = maxlen + 2;

View File

@ -1206,7 +1206,7 @@ void opt_help(const OPTIONS *list)
i = 2 + (int)strlen(o->name);
if (o->valtype != '-')
i += 1 + strlen(valtype2param(o));
i += 1 + (int)strlen(valtype2param(o));
if (i > width)
width = i;
@ -1243,7 +1243,7 @@ int opt_isdir(const char *name)
return -1;
# if !defined(_WIN32_WCE) || _WIN32_WCE>=101
if (!MultiByteToWideChar(CP_ACP, 0, name, len_0, tempname, MAX_PATH))
if (!MultiByteToWideChar(CP_ACP, 0, name, (int)len_0, tempname, MAX_PATH))
# endif
for (i = 0; i < len_0; i++)
tempname[i] = (WCHAR)name[i];

View File

@ -509,7 +509,8 @@ long bio_dump_callback(BIO *bio, int cmd, const char *argp, size_t len,
BIO_printf(out, "read from %p [%p] (%zu bytes => %zu (0x%zX))\n",
(void *)bio, (void *)msg->data, msg->data_len,
msg->data_len, msg->data_len);
BIO_dump(out, msg->data, msg->data_len);
if (msg->data_len <= INT_MAX)
BIO_dump(out, msg->data, (int)msg->data_len);
}
} else if (mmsgargs->num_msg > 0) {
BIO_MSG *msg = mmsgargs->msg;
@ -529,7 +530,8 @@ long bio_dump_callback(BIO *bio, int cmd, const char *argp, size_t len,
BIO_printf(out, "write to %p [%p] (%zu bytes => %zu (0x%zX))\n",
(void *)bio, (void *)msg->data, msg->data_len,
msg->data_len, msg->data_len);
BIO_dump(out, msg->data, msg->data_len);
if (msg->data_len <= INT_MAX)
BIO_dump(out, msg->data, (int)msg->data_len);
}
} else if (mmsgargs->num_msg > 0) {
BIO_MSG *msg = mmsgargs->msg;

View File

@ -159,9 +159,9 @@ void win32_utf8argv(int *argc, char **argv[])
/*
* make a copy of the command line, since we might have to modify it...
*/
wlen = wcslen(wcmdline);
wlen = (int)wcslen(wcmdline);
p = _alloca((wlen + 1) * sizeof(WCHAR));
wcscpy(p, wcmdline);
memcpy(p, wcmdline, (wlen + 1) * sizeof(WCHAR));
while (*p != L'\0') {
int in_quote = 0;
@ -205,14 +205,12 @@ void win32_utf8argv(int *argc, char **argv[])
*/
{
const WCHAR *q = p;
int i;
size_t i;
while (*p == L'\\')
p++;
if (*p == L'"') {
int i;
for (i = (p - q) / 2; i > 0; i--)
*wend++ = L'\\';
@ -248,7 +246,7 @@ void win32_utf8argv(int *argc, char **argv[])
}
}
wlen = wend - warg;
wlen = (int)(wend - warg);
if (wlen == 0 || !process_glob(warg, wlen)) {
if (!validate_argv(newargc + 1)) {

View File

@ -105,13 +105,13 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
do {
# ifdef CP_UTF8
if ((sz = MultiByteToWideChar((cp = CP_UTF8), 0,
directory, len_0,
directory, (int)len_0,
NULL, 0)) > 0 ||
GetLastError() != ERROR_NO_UNICODE_TRANSLATION)
break;
# endif
sz = MultiByteToWideChar((cp = CP_ACP), 0,
directory, len_0,
directory, (int)len_0,
NULL, 0);
} while (0);
@ -121,7 +121,7 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
* concatenate asterisk, |sz| covers trailing '\0'!
*/
wdir = _alloca((sz + 2) * sizeof(TCHAR));
if (!MultiByteToWideChar(cp, 0, directory, len_0,
if (!MultiByteToWideChar(cp, 0, directory, (int)len_0,
(WCHAR *)wdir, sz)) {
free(*ctx);
*ctx = NULL;
@ -131,7 +131,7 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
} else
#endif
{
sz = len_0;
sz = (int)len_0;
/*
* allocate two additional characters in case we need to
* concatenate asterisk, |sz| covers trailing '\0'!
@ -186,7 +186,7 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
len_0++;
#ifdef LP_MULTIBYTE_AVAILABLE
if (!WideCharToMultiByte(CP_DEFAULT, 0, (WCHAR *)wdir, len_0,
if (!WideCharToMultiByte(CP_DEFAULT, 0, (WCHAR *)wdir, (int)len_0,
(*ctx)->entry_name,
sizeof((*ctx)->entry_name), NULL, 0))
#endif

View File

@ -21,13 +21,13 @@ int AES_wrap_key(AES_KEY *key, const unsigned char *iv,
unsigned char *out,
const unsigned char *in, unsigned int inlen)
{
return CRYPTO_128_wrap(key, iv, out, in, inlen, (block128_f) AES_encrypt);
return (int)CRYPTO_128_wrap(key, iv, out, in, inlen, (block128_f) AES_encrypt);
}
int AES_unwrap_key(AES_KEY *key, const unsigned char *iv,
unsigned char *out,
const unsigned char *in, unsigned int inlen)
{
return CRYPTO_128_unwrap(key, iv, out, in, inlen,
(block128_f) AES_decrypt);
return (int)CRYPTO_128_unwrap(key, iv, out, in, inlen,
(block128_f) AES_decrypt);
}

View File

@ -110,7 +110,6 @@ int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
{
BUF_MEM *b;
unsigned char *p;
int i;
size_t want = HEADER_SIZE;
uint32_t eos = 0;
size_t off = 0;
@ -131,13 +130,15 @@ int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
for (;;) {
diff = len - off;
if (want >= diff) {
int i;
want -= diff;
if (len + want < len || !BUF_MEM_grow_clean(b, len + want)) {
ERR_raise(ERR_LIB_ASN1, ERR_R_BUF_LIB);
goto err;
}
i = BIO_read(in, &(b->data[len]), want);
i = BIO_read(in, &(b->data[len]), (int)want);
if (i < 0 && diff == 0) {
ERR_raise(ERR_LIB_ASN1, ASN1_R_NOT_ENOUGH_DATA);
goto err;
@ -160,7 +161,7 @@ int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
diff = len - off;
if (diff == 0)
goto err;
inf = ASN1_get_object(&q, &slen, &tag, &xclass, diff);
inf = ASN1_get_object(&q, &slen, &tag, &xclass, (int)diff);
if (inf & 0x80) {
unsigned long e;
@ -169,8 +170,7 @@ int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
goto err;
ERR_pop_to_mark();
}
i = q - p; /* header length */
off += i; /* end of data */
off += q - p; /* end of data */
if (inf & 1) {
/* no data body so go round again */
@ -207,6 +207,7 @@ int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
* in one go.
*/
size_t chunk = want > chunk_max ? chunk_max : want;
int i;
if (!BUF_MEM_grow_clean(b, len + chunk)) {
ERR_raise(ERR_LIB_ASN1, ERR_R_BUF_LIB);
@ -214,7 +215,7 @@ int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
}
want -= chunk;
while (chunk > 0) {
i = BIO_read(in, &(b->data[len]), chunk);
i = BIO_read(in, &(b->data[len]), (int)chunk);
if (i <= 0) {
ERR_raise(ERR_LIB_ASN1, ASN1_R_NOT_ENOUGH_DATA);
goto err;
@ -248,7 +249,7 @@ int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
}
*pb = b;
return off;
return (int)off;
err:
ERR_clear_last_mark();
BUF_MEM_free(b);

View File

@ -38,9 +38,13 @@ int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *d)
int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str)
{
ASN1_GENERALIZEDTIME t;
size_t len;
if ((len = strlen(str)) >= INT_MAX)
return 0;
t.type = V_ASN1_GENERALIZEDTIME;
t.length = strlen(str);
t.length = (int)len;
t.data = (unsigned char *)str;
t.flags = 0;

View File

@ -206,7 +206,16 @@ static size_t c2i_ibuf(unsigned char *b, int *pneg,
int ossl_i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
{
return i2c_ibuf(a->data, a->length, a->type & V_ASN1_NEG, pp);
unsigned char *ptr = pp != NULL ? *pp : NULL;
size_t ret = i2c_ibuf(a->data, a->length, a->type & V_ASN1_NEG, &ptr);
if (ret > INT_MAX) {
ERR_raise(ERR_LIB_ASN1, ASN1_R_TOO_LARGE);
return 0;
}
if (pp != NULL)
*pp = ptr;
return (int)ret;
}
/* Convert big endian buffer into uint64_t, return 0 on error */
@ -307,7 +316,7 @@ ASN1_INTEGER *ossl_c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
} else
ret = *a;
if (ASN1_STRING_set(ret, NULL, r) == 0) {
if (r > INT_MAX || ASN1_STRING_set(ret, NULL, (int)r) == 0) {
ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
@ -362,7 +371,7 @@ static int asn1_string_set_int64(ASN1_STRING *a, int64_t r, int itype)
off = asn1_put_uint64(tbuf, r);
a->type &= ~V_ASN1_NEG;
}
return ASN1_STRING_set(a, tbuf + off, sizeof(tbuf) - off);
return ASN1_STRING_set(a, tbuf + off, (int)(sizeof(tbuf) - off));
}
static int asn1_string_get_uint64(uint64_t *pr, const ASN1_STRING *a,
@ -390,7 +399,7 @@ static int asn1_string_set_uint64(ASN1_STRING *a, uint64_t r, int itype)
a->type = itype;
off = asn1_put_uint64(tbuf, r);
return ASN1_STRING_set(a, tbuf + off, sizeof(tbuf) - off);
return ASN1_STRING_set(a, tbuf + off, (int)(sizeof(tbuf) - off));
}
/*
@ -642,6 +651,6 @@ int ossl_i2c_uint64_int(unsigned char *p, uint64_t r, int neg)
size_t off;
off = asn1_put_uint64(buf, r);
return i2c_ibuf(buf + off, sizeof(buf) - off, neg, &p);
return (int)i2c_ibuf(buf + off, sizeof(buf) - off, neg, &p);
}

View File

@ -51,12 +51,21 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
unsigned char *p;
int nchar;
int (*cpyfunc) (unsigned long, void *) = NULL;
if (len == -1)
len = strlen((const char *)in);
if (len == -1) {
size_t len_s = strlen((const char *)in);
if (len_s >= INT_MAX) {
ERR_raise(ERR_LIB_ASN1, ASN1_R_STRING_TOO_LONG);
return -1;
}
len = (int)len_s;
}
if (!mask)
mask = DIRSTRING_TYPE;
if (len < 0)
if (len < 0) {
ERR_raise(ERR_LIB_ASN1, ERR_R_PASSED_INVALID_ARGUMENT);
return -1;
}
/* First do a string check and work out the number of characters */
switch (inform) {

View File

@ -57,10 +57,17 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
unsigned long l;
BIGNUM *bl = NULL;
if (num == 0)
if (num == 0) {
return 0;
else if (num == -1)
num = strlen(buf);
} else if (num == -1) {
size_t num_s = strlen(buf);
if (num_s >= INT_MAX) {
ERR_raise(ERR_LIB_ASN1, ASN1_R_LENGTH_TOO_LONG);
goto err;
}
num = (int)num_s;
}
p = buf;
c = *(p++);

View File

@ -22,7 +22,7 @@ int ASN1_PRINTABLE_type(const unsigned char *s, int len)
return V_ASN1_PRINTABLESTRING;
if (len < 0)
len = strlen((const char *)s);
len = (int)strlen((const char *)s);
while (len-- > 0) {
c = *(s++);

View File

@ -191,7 +191,7 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1,
if (algor1 != NULL) {
const unsigned char *pp = aid;
if (d2i_X509_ALGOR(&algor1, &pp, aid_len) == NULL) {
if (d2i_X509_ALGOR(&algor1, &pp, (long)aid_len) == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_INTERNAL_ERROR);
goto err;
}
@ -200,7 +200,7 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1,
if (algor2 != NULL) {
const unsigned char *pp = aid;
if (d2i_X509_ALGOR(&algor2, &pp, aid_len) == NULL) {
if (d2i_X509_ALGOR(&algor2, &pp, (long)aid_len) == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_INTERNAL_ERROR);
goto err;
}
@ -277,7 +277,7 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1,
ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
goto err;
}
ASN1_STRING_set0(signature, buf_out, outl);
ASN1_STRING_set0(signature, buf_out, (int)outl);
buf_out = NULL;
/*
* In the interests of compatibility, I'll make sure that the bit string
@ -287,5 +287,5 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1,
err:
OPENSSL_clear_free((char *)buf_in, inl);
OPENSSL_clear_free((char *)buf_out, outll);
return outl;
return (int)outl;
}

View File

@ -527,7 +527,7 @@ static int do_name_ex(char_io *io_ch, void *arg, const X509_NAME *n,
objbuf = "";
}
}
objlen = strlen(objbuf);
objlen = (int)strlen(objbuf);
if (!io_ch(arg, objbuf, objlen))
return -1;
if ((objlen < fld_len) && (flags & XN_FLAG_FN_ALIGN)) {

View File

@ -266,7 +266,7 @@ ASN1_TIME *ossl_asn1_time_from_tm(ASN1_TIME *s, struct tm *ts, int type)
{
char* p;
ASN1_TIME *tmps = NULL;
const size_t len = 20;
const int len = 20;
if (type == V_ASN1_UNDEF) {
if (is_utc(ts->tm_year))
@ -386,8 +386,11 @@ int ASN1_TIME_set_string_X509(ASN1_TIME *s, const char *str)
ASN1_TIME t;
struct tm tm;
int rv = 0;
size_t len;
t.length = strlen(str);
if ((len = strlen(str)) >= INT_MAX)
goto out;
t.length = (int)len;
t.data = (unsigned char *)str;
t.flags = ASN1_STRING_FLAG_X509_TIME;

View File

@ -34,9 +34,12 @@ int ASN1_UTCTIME_check(const ASN1_UTCTIME *d)
int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str)
{
ASN1_UTCTIME t;
size_t len;
if ((len = strlen(str)) >= INT_MAX)
return 0;
t.type = V_ASN1_UTCTIME;
t.length = strlen(str);
t.length = (int)len;
t.data = (unsigned char *)str;
t.flags = 0;

View File

@ -110,7 +110,7 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe,
const EVP_PKEY_ASN1_METHOD *ameth = NULL;
if (len == -1)
len = strlen(str);
len = (int)strlen(str);
if (pe) {
#ifndef OPENSSL_NO_ENGINE
ENGINE *e;

View File

@ -160,7 +160,7 @@ static ASN1_TYPE *generate_v3(const char *str, X509V3_CTX *cnf, int depth,
if (r & 0x80)
goto err;
/* Update copy length */
cpy_len -= cpy_start - orig_der;
cpy_len -= (int)(cpy_start - orig_der);
/*
* For IMPLICIT tagging the length should match the original length
* and constructed flag should be consistent.
@ -255,8 +255,8 @@ static int asn1_cb(const char *elem, int len, void *bitstr)
/* Look for the ':' in name value pairs */
if (*p == ':') {
vstart = p + 1;
vlen = len - (vstart - elem);
len = p - elem;
vlen = len - (int)(vstart - elem);
len = (int)(p - elem);
break;
}
}
@ -362,7 +362,7 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass)
*ptag = tag_num;
/* If we have non numeric characters, parse them */
if (eptr)
vlen -= eptr - vstart;
vlen -= (int)(eptr - vstart);
else
vlen = 0;
if (vlen) {
@ -562,7 +562,7 @@ static int asn1_str2tag(const char *tagstr, int len)
};
if (len == -1)
len = strlen(tagstr);
len = (int)strlen(tagstr);
tntmp = tnst;
for (i = 0; i < OSSL_NELEM(tnst); i++, tntmp++) {

View File

@ -318,7 +318,7 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len_in)
return 0;
}
}
str->length = len;
str->length = (int)len;
if (data != NULL) {
memcpy(str->data, data, len);
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION

View File

@ -69,7 +69,7 @@ void ossl_asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it);
void ossl_asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
int ossl_asn1_enc_restore(int *len, unsigned char **out, const ASN1_VALUE **pval,
const ASN1_ITEM *it);
int ossl_asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
int ossl_asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, long inlen,
const ASN1_ITEM *it);
void ossl_asn1_item_embed_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed);

View File

@ -120,7 +120,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
BIO_puts(bp, "Error in encoding\n");
goto end;
}
hl = (p - op);
hl = (int)(p - op);
length -= hl;
/*
* if j == 0x21 it is a constructed indefinite length object
@ -141,12 +141,12 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
if ((j == 0x21) && (len == 0)) {
for (;;) {
r = asn1_parse2(bp, &p, (long)(tot - p),
offset + (p - *pp), depth + 1,
offset + (int)(p - *pp), depth + 1,
indent, dump);
if (r == 0)
goto end;
if ((r == 2) || (p >= tot)) {
len = p - sp;
len = (long)(p - sp);
break;
}
}
@ -156,11 +156,11 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length,
while (p < ep) {
sp = p;
r = asn1_parse2(bp, &p, tmp,
offset + (p - *pp), depth + 1,
offset + (int)(p - *pp), depth + 1,
indent, dump);
if (r == 0)
goto end;
tmp -= p - sp;
tmp -= (long)(p - sp);
}
}
} else if (xclass != 0) {

View File

@ -647,12 +647,15 @@ static int multi_split(BIO *bio, int flags, const char *bound, STACK_OF(BIO) **r
{
char linebuf[MAX_SMLEN];
int len, blen;
size_t blen_s = strlen(bound);
int eol = 0, next_eol = 0;
BIO *bpart = NULL;
STACK_OF(BIO) *parts;
char state, part, first;
blen = strlen(bound);
if (blen_s > MAX_SMLEN)
return 0;
blen = (int)blen_s;
part = 0;
state = 0;
first = 1;
@ -1028,10 +1031,8 @@ static void mime_param_free(MIME_PARAM *param)
*/
static int mime_bound_check(char *line, int linelen, const char *bound, int blen)
{
if (linelen == -1)
linelen = strlen(line);
if (blen == -1)
blen = strlen(bound);
if (linelen < 0 || blen < 0)
return 0;
/* Quickly eliminate if line length too short */
if (blen + 2 > linelen)
return 0;

View File

@ -302,7 +302,12 @@ static int asn1_bio_read(BIO *b, char *in, int inl)
static int asn1_bio_puts(BIO *b, const char *str)
{
return asn1_bio_write(b, str, strlen(str));
size_t len = strlen(str);
if (len > INT_MAX)
return -1;
return asn1_bio_write(b, str, (int)len);
}
static int asn1_bio_gets(BIO *b, char *str, int size)

View File

@ -150,7 +150,7 @@ static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
if (*ndef_aux->boundary == NULL)
return 0;
*plen = *ndef_aux->boundary - *pbuf;
*plen = (int)(*ndef_aux->boundary - *pbuf);
return 1;
}
@ -223,7 +223,7 @@ static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
if (*ndef_aux->boundary == NULL)
return 0;
*pbuf = *ndef_aux->boundary;
*plen = derlen - (*ndef_aux->boundary - ndef_aux->derbuf);
*plen = derlen - (int)(*ndef_aux->boundary - ndef_aux->derbuf);
return 1;
}

View File

@ -49,7 +49,7 @@ d2i_PrivateKey_decoder(int keytype, EVP_PKEY **a, const unsigned char **pp,
/* This is just a probe. It might fail, so we ignore errors */
ERR_set_mark();
p8info = d2i_PKCS8_PRIV_KEY_INFO(NULL, pp, len);
p8info = d2i_PKCS8_PRIV_KEY_INFO(NULL, pp, length);
ERR_pop_to_mark();
if (p8info != NULL) {
int64_t v;

View File

@ -30,7 +30,7 @@ ASN1_SEQUENCE(SCRYPT_PARAMS) = {
IMPLEMENT_ASN1_FUNCTIONS(SCRYPT_PARAMS)
static X509_ALGOR *pkcs5_scrypt_set(const unsigned char *salt, size_t saltlen,
static X509_ALGOR *pkcs5_scrypt_set(const unsigned char *salt, int saltlen,
size_t keylen, uint64_t N, uint64_t r,
uint64_t p);
@ -153,7 +153,7 @@ X509_ALGOR *PKCS5_pbe2_set_scrypt(const EVP_CIPHER *cipher,
return NULL;
}
static X509_ALGOR *pkcs5_scrypt_set(const unsigned char *salt, size_t saltlen,
static X509_ALGOR *pkcs5_scrypt_set(const unsigned char *salt, int saltlen,
size_t keylen, uint64_t N, uint64_t r,
uint64_t p)
{

View File

@ -351,7 +351,7 @@ static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,
} else if (ret == -1)
return -1;
if (aux && (aux->flags & ASN1_AFLG_BROKEN)) {
len = tmplen - (p - *in);
len = tmplen - (long)(p - *in);
seq_nolen = 1;
}
/* If indefinite we don't do a length check */
@ -401,7 +401,7 @@ static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,
ERR_raise(ERR_LIB_ASN1, ASN1_R_UNEXPECTED_EOC);
goto err;
}
len -= p - q;
len -= (long)(p - q);
seq_eoc = 0;
break;
}
@ -432,7 +432,7 @@ static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,
continue;
}
/* Update length */
len -= p - q;
len -= (long)(p - q);
}
/* Check for EOC if expecting one */
@ -467,7 +467,7 @@ static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,
}
}
/* Save encoding */
if (!ossl_asn1_enc_save(pval, *in, p - *in, it))
if (!ossl_asn1_enc_save(pval, *in, (long)(p - *in), it))
goto auxerr;
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))
goto auxerr;
@ -538,7 +538,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val,
return 0;
}
/* We read the field in OK so update length */
len -= p - q;
len -= (long)(p - q);
if (exp_eoc) {
/* If NDEF we must have an EOC here */
if (!asn1_check_eoc(&p, len)) {
@ -643,7 +643,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
ERR_raise(ERR_LIB_ASN1, ASN1_R_UNEXPECTED_EOC);
goto err;
}
len -= p - q;
len -= (long)(p - q);
sk_eoc = 0;
break;
}
@ -656,7 +656,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
ASN1_item_free(skfield, ASN1_ITEM_ptr(tt->item));
goto err;
}
len -= p - q;
len -= (long)(p - q);
if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, skfield)) {
ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB);
ASN1_item_free(skfield, ASN1_ITEM_ptr(tt->item));
@ -775,9 +775,9 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
if (inf) {
if (!asn1_find_end(&p, plen, inf))
goto err;
len = p - cont;
len = (long)(p - cont);
} else {
len = p - cont + plen;
len = (long)(p - cont) + plen;
p += plen;
}
} else if (cst) {
@ -799,7 +799,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL, 0)) {
goto err;
}
len = buf.length;
len = (long)buf.length;
/* Append a final null to string */
if (!BUF_MEM_grow_clean(&buf, len + 1)) {
ERR_raise(ERR_LIB_ASN1, ERR_R_BUF_LIB);
@ -1017,7 +1017,7 @@ static int asn1_find_end(const unsigned char **in, long len, char inf)
} else {
p += plen;
}
len -= p - q;
len -= (long)(p - q);
}
if (expected_eoc) {
ERR_raise(ERR_LIB_ASN1, ASN1_R_MISSING_EOC);
@ -1090,7 +1090,7 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
return 0;
} else if (plen && !collect_data(buf, &p, plen))
return 0;
len -= p - q;
len -= (long)(p - q);
}
if (inf) {
ERR_raise(ERR_LIB_ASN1, ASN1_R_MISSING_EOC);
@ -1102,9 +1102,14 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen)
{
int len;
long len;
if (buf) {
len = buf->length;
len = (long)buf->length;
if (len + plen < 0) {
/* resulting buffer length will not fit into long */
ERR_raise(ERR_LIB_ASN1, ASN1_R_LENGTH_TOO_LONG);
return 0;
}
if (!BUF_MEM_grow_clean(buf, len + plen)) {
ERR_raise(ERR_LIB_ASN1, ERR_R_BUF_LIB);
return 0;
@ -1167,7 +1172,7 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
ctx->plen = plen;
ctx->pclass = pclass;
ctx->ptag = ptag;
ctx->hdrlen = p - q;
ctx->hdrlen = (int)(p - q);
ctx->valid = 1;
/*
* If definite length, and no error, length + header can't exceed
@ -1202,7 +1207,7 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
}
if ((i & 1) != 0)
plen = len - (p - q);
plen = len - (long)(p - q);
if (inf != NULL)
*inf = i & 1;

View File

@ -161,7 +161,7 @@ void ossl_asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
}
}
int ossl_asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
int ossl_asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, long inlen,
const ASN1_ITEM *it)
{
ASN1_ENCODING *enc = asn1_get_enc_ptr(pval, it);
@ -170,8 +170,10 @@ int ossl_asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
return 1;
OPENSSL_free(enc->enc);
if (inlen <= 0)
if (inlen <= 0) {
enc->enc = NULL;
return 0;
}
if ((enc->enc = OPENSSL_malloc(inlen)) == NULL)
return 0;
memcpy(enc->enc, in, inlen);

View File

@ -344,7 +344,7 @@ int ASYNC_init_thread(size_t max_size, size_t init_size)
async_pool *pool;
size_t curr_size = 0;
if (init_size > max_size) {
if (init_size > max_size || max_size > INT_MAX) {
ERR_raise(ERR_LIB_ASYNC, ASYNC_R_INVALID_POOL_SIZE);
return 0;
}
@ -359,7 +359,7 @@ int ASYNC_init_thread(size_t max_size, size_t init_size)
if (pool == NULL)
return 0;
pool->jobs = sk_ASYNC_JOB_new_reserve(NULL, init_size);
pool->jobs = sk_ASYNC_JOB_new_reserve(NULL, (int)init_size);
if (pool->jobs == NULL) {
ERR_raise(ERR_LIB_ASYNC, ERR_R_CRYPTO_LIB);
OPENSSL_free(pool);

View File

@ -465,5 +465,9 @@ static int buffer_gets(BIO *b, char *buf, int size)
static int buffer_puts(BIO *b, const char *str)
{
return buffer_write(b, str, strlen(str));
size_t len = strlen(str);
if (len > INT_MAX)
return -1;
return buffer_write(b, str, (int)len);
}

View File

@ -133,14 +133,15 @@ static int linebuffer_write(BIO *b, const char *in, int inl)
while ((foundnl || p - in > ctx->obuf_size - ctx->obuf_len)
&& ctx->obuf_len > 0) {
int orig_olen = ctx->obuf_len;
int llen = (int)(p - in);
i = ctx->obuf_size - ctx->obuf_len;
if (p - in > 0) {
if (i >= p - in) {
memcpy(&(ctx->obuf[ctx->obuf_len]), in, p - in);
ctx->obuf_len += p - in;
inl -= p - in;
num += p - in;
if (llen > 0) {
if (i >= llen) {
memcpy(&(ctx->obuf[ctx->obuf_len]), in, llen);
ctx->obuf_len += llen;
inl -= llen;
num += llen;
in = p;
} else {
memcpy(&(ctx->obuf[ctx->obuf_len]), in, i);
@ -170,7 +171,7 @@ static int linebuffer_write(BIO *b, const char *in, int inl)
* if a NL was found and there is anything to write.
*/
if ((foundnl || p - in > ctx->obuf_size) && p - in > 0) {
i = BIO_write(b->next_bio, in, p - in);
i = BIO_write(b->next_bio, in, (int)(p - in));
if (i <= 0) {
BIO_copy_next_retry(b);
if (i < 0)
@ -311,5 +312,9 @@ static int linebuffer_gets(BIO *b, char *buf, int size)
static int linebuffer_puts(BIO *b, const char *str)
{
return linebuffer_write(b, str, strlen(str));
size_t len = strlen(str);
if (len > INT_MAX)
return -1;
return linebuffer_write(b, str, (int)len);
}

View File

@ -203,5 +203,9 @@ static int prefix_gets(BIO *b, char *buf, int size)
static int prefix_puts(BIO *b, const char *str)
{
return BIO_write(b, str, strlen(str));
size_t len = strlen(str);
if (len > INT_MAX)
return -1;
return BIO_write(b, str, (int)len);
}

View File

@ -427,7 +427,7 @@ int BIO_ADDRINFO_protocol(const BIO_ADDRINFO *bai)
socklen_t BIO_ADDRINFO_sockaddr_size(const BIO_ADDRINFO *bai)
{
if (bai != NULL)
return bai->bai_addrlen;
return (socklen_t)bai->bai_addrlen;
return 0;
}

View File

@ -111,7 +111,7 @@ long BIO_debug_callback_ex(BIO *bio, int cmd, const char *argp, size_t len,
b = (BIO *)bio->cb_arg;
if (b != NULL)
BIO_write(b, buf, strlen(buf));
BIO_write(b, buf, (int)strlen(buf));
#if !defined(OPENSSL_NO_STDIO)
else
fputs(buf, stderr);

View File

@ -99,7 +99,7 @@ int BIO_dump_indent_cb(int (*cb) (const void *data, size_t len, void *u),
#ifndef OPENSSL_NO_STDIO
static int write_fp(const void *data, size_t len, void *fp)
{
return UP_fwrite(data, len, 1, fp);
return (int)UP_fwrite(data, len, 1, fp);
}
int BIO_dump_fp(FILE *fp, const void *s, int len)
@ -115,7 +115,9 @@ int BIO_dump_indent_fp(FILE *fp, const void *s, int len, int indent)
static int write_bio(const void *data, size_t len, void *bp)
{
return BIO_write((BIO *)bp, (const char *)data, len);
if (len > INT_MAX)
return -1;
return BIO_write((BIO *)bp, (const char *)data, (int)len);
}
int BIO_dump(BIO *bp, const void *s, int len)

View File

@ -65,7 +65,7 @@ static long bio_call_callback(BIO *b, int oper, const char *argp, size_t len,
if (inret > 0 && (oper & BIO_CB_RETURN) && bareoper != BIO_CB_CTRL) {
if (*processed > INT_MAX)
return -1;
inret = *processed;
inret = (long)*processed;
}
ret = b->callback(b, oper, argp, argi, argl, inret);
@ -433,9 +433,9 @@ int BIO_sendmmsg(BIO *b, BIO_MSG *msg,
if (HAS_CALLBACK(b))
ret = (size_t)bio_call_callback(b, BIO_CB_SENDMMSG | BIO_CB_RETURN,
(void *)&args, ret, 0, 0, ret, NULL);
(void *)&args, ret, 0, 0, (long)ret, NULL);
return ret;
return ret > 0;
}
int BIO_recvmmsg(BIO *b, BIO_MSG *msg,
@ -480,9 +480,9 @@ int BIO_recvmmsg(BIO *b, BIO_MSG *msg,
if (HAS_CALLBACK(b))
ret = (size_t)bio_call_callback(b, BIO_CB_RECVMMSG | BIO_CB_RETURN,
(void *)&args, ret, 0, 0, ret, NULL);
(void *)&args, ret, 0, 0, (long)ret, NULL);
return ret;
return ret > 0;
}
int BIO_get_rpoll_descriptor(BIO *b, BIO_POLL_DESCRIPTOR *desc)
@ -624,7 +624,7 @@ int BIO_get_line(BIO *bio, char *buf, int size)
if (*ptr++ == '\n')
break;
*ptr = '\0';
return ret > 0 || BIO_eof(bio) ? ptr - buf : ret;
return ret > 0 || BIO_eof(bio) ? (int)(ptr - buf) : ret;
}
int BIO_indent(BIO *b, int indent, int max)

View File

@ -103,7 +103,8 @@ _dopr(char **sbuffer,
size_t currlen;
state = DP_S_DEFAULT;
flags = currlen = cflags = min = 0;
currlen = 0;
flags = cflags = min = 0;
max = -1;
ch = *format++;
@ -316,10 +317,10 @@ _dopr(char **sbuffer,
case 's':
strvalue = va_arg(args, char *);
if (max < 0) {
if (buffer)
if (buffer || *maxlen > INT_MAX)
max = INT_MAX;
else
max = *maxlen;
max = (int)*maxlen;
}
if (!fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,
flags, min, max))
@ -334,8 +335,9 @@ _dopr(char **sbuffer,
case 'n':
{
int *num;
num = va_arg(args, int *);
*num = currlen;
*num = (int)currlen;
}
break;
case '%':
@ -391,7 +393,7 @@ fmtstr(char **sbuffer,
strln = OPENSSL_strnlen(value, max < 0 ? SIZE_MAX : (size_t)max);
padlen = min - strln;
padlen = (int)(min - strln);
if (min < 0 || padlen < 0)
padlen = 0;
if (max >= 0) {
@ -474,7 +476,7 @@ fmtint(char **sbuffer,
zpadlen = max - place;
spadlen =
min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) - strlen(prefix);
min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) - (int)strlen(prefix);
if (zpadlen < 0)
zpadlen = 0;
if (spadlen < 0)

View File

@ -554,10 +554,12 @@ static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
static int acpt_puts(BIO *bp, const char *str)
{
int n, ret;
int ret;
size_t n = strlen(str);
n = strlen(str);
ret = acpt_write(bp, str, n);
if (n > INT_MAX)
return -1;
ret = acpt_write(bp, str, (int)n);
return ret;
}

View File

@ -183,7 +183,7 @@ static int bio_read(BIO *bio, char *buf, int size_)
}
while (rest);
return size;
return (int)size;
}
/*-
@ -332,7 +332,7 @@ static int bio_write(BIO *bio, const char *buf, int num_)
}
while (rest);
return num;
return (int)num;
}
/*-
@ -474,7 +474,7 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
if (b->peer == NULL || b->closed)
ret = 0;
else
ret = (long)b->size - b->len;
ret = (long)(b->size - b->len);
break;
case BIO_C_GET_READ_REQUEST:
@ -600,7 +600,11 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
static int bio_puts(BIO *bio, const char *str)
{
return bio_write(bio, str, strlen(str));
size_t len = strlen(str);
if (len > INT_MAX)
return -1;
return bio_write(bio, str, (int)len);
}
static int bio_make_pair(BIO *bio1, BIO *bio2)
@ -683,6 +687,9 @@ int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1,
long r;
int ret = 0;
if (writebuf1 > LONG_MAX || writebuf2 > LONG_MAX)
goto err;
bio1 = BIO_new(BIO_s_bio());
if (bio1 == NULL)
goto err;
@ -691,12 +698,12 @@ int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1,
goto err;
if (writebuf1) {
r = BIO_set_write_buf_size(bio1, writebuf1);
r = BIO_set_write_buf_size(bio1, (long)writebuf1);
if (!r)
goto err;
}
if (writebuf2) {
r = BIO_set_write_buf_size(bio2, writebuf2);
r = BIO_set_write_buf_size(bio2, (long)writebuf2);
if (!r)
goto err;
}

View File

@ -751,10 +751,12 @@ static long conn_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
static int conn_puts(BIO *bp, const char *str)
{
int n, ret;
int ret;
size_t n = strlen(str);
n = strlen(str);
ret = conn_write(bp, str, n);
if (n > INT_MAX)
return -1;
ret = conn_write(bp, str, (int)n);
return ret;
}
@ -810,7 +812,7 @@ int conn_gets(BIO *bio, char *buf, int size)
break;
}
*ptr = '\0';
return ret > 0 || (bio->flags & BIO_FLAGS_IN_EOF) != 0 ? ptr - buf : ret;
return ret > 0 || (bio->flags & BIO_FLAGS_IN_EOF) != 0 ? (int)(ptr - buf) : ret;
}
static int conn_sendmmsg(BIO *bio, BIO_MSG *msg, size_t stride, size_t num_msgs,

View File

@ -1028,10 +1028,12 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
static int dgram_puts(BIO *bp, const char *str)
{
int n, ret;
int ret;
size_t n = strlen(str);
n = strlen(str);
ret = dgram_write(bp, str, n);
if (n > INT_MAX)
return -1;
ret = dgram_write(bp, str, (int)n);
return ret;
}

View File

@ -620,7 +620,7 @@ static int dgram_pair_ctrl_get_mtu(BIO *bio)
{
struct bio_dgram_pair_st *b = bio->ptr;
return b->mtu;
return (int)b->mtu;
}
/* BIO_dgram_set_mtu (BIO_CTRL_DGRAM_SET_MTU) */
@ -807,6 +807,9 @@ int BIO_new_bio_dgram_pair(BIO **pbio1, size_t writebuf1,
long r;
BIO *bio1 = NULL, *bio2 = NULL;
if (writebuf1 > LONG_MAX || writebuf2 > LONG_MAX)
goto err;
bio1 = BIO_new(BIO_s_dgram_pair());
if (bio1 == NULL)
goto err;
@ -816,13 +819,13 @@ int BIO_new_bio_dgram_pair(BIO **pbio1, size_t writebuf1,
goto err;
if (writebuf1 > 0) {
r = BIO_set_write_buf_size(bio1, writebuf1);
r = BIO_set_write_buf_size(bio1, (long)writebuf1);
if (r == 0)
goto err;
}
if (writebuf2 > 0) {
r = BIO_set_write_buf_size(bio2, writebuf2);
r = BIO_set_write_buf_size(bio2, (long)writebuf2);
if (r == 0)
goto err;
}
@ -1037,7 +1040,7 @@ static int dgram_pair_read(BIO *bio, char *buf, int sz_)
l = dgram_pair_read_actual(bio, buf, (size_t)sz_, NULL, NULL, 0);
if (l < 0) {
if (l != -BIO_R_NON_FATAL)
ERR_raise(ERR_LIB_BIO, -l);
ERR_raise(ERR_LIB_BIO, (int)-l);
ret = -1;
} else {
ret = (int)l;
@ -1090,7 +1093,7 @@ static int dgram_pair_recvmmsg(BIO *bio, BIO_MSG *msg,
if (i > 0) {
ret = 1;
} else {
ERR_raise(ERR_LIB_BIO, -l);
ERR_raise(ERR_LIB_BIO, (int)-l);
ret = 0;
}
goto out;
@ -1127,7 +1130,7 @@ static int dgram_mem_read(BIO *bio, char *buf, int sz_)
l = dgram_pair_read_actual(bio, buf, (size_t)sz_, NULL, NULL, 0);
if (l < 0) {
if (l != -BIO_R_NON_FATAL)
ERR_raise(ERR_LIB_BIO, -l);
ERR_raise(ERR_LIB_BIO, (int)-l);
ret = -1;
} else {
ret = (int)l;
@ -1289,7 +1292,7 @@ static int dgram_pair_write(BIO *bio, const char *buf, int sz_)
l = dgram_pair_write_actual(bio, buf, (size_t)sz_, NULL, NULL, 0);
if (l < 0) {
ERR_raise(ERR_LIB_BIO, -l);
ERR_raise(ERR_LIB_BIO, (int)-l);
ret = -1;
} else {
ret = (int)l;
@ -1304,10 +1307,11 @@ static int dgram_pair_sendmmsg(BIO *bio, BIO_MSG *msg,
size_t stride, size_t num_msg,
uint64_t flags, size_t *num_processed)
{
ossl_ssize_t ret, l;
ossl_ssize_t l;
BIO_MSG *m;
size_t i;
struct bio_dgram_pair_st *b = bio->ptr;
int ret = 0;
if (num_msg == 0) {
*num_processed = 0;
@ -1329,8 +1333,7 @@ static int dgram_pair_sendmmsg(BIO *bio, BIO_MSG *msg,
if (i > 0) {
ret = 1;
} else {
ERR_raise(ERR_LIB_BIO, -l);
ret = 0;
ERR_raise(ERR_LIB_BIO, (int)-l);
}
goto out;
}

View File

@ -116,7 +116,7 @@ static int fd_read(BIO *b, char *out, int outl)
if (out != NULL) {
clear_sys_error();
ret = UP_read(b->num, out, outl);
ret = (int)UP_read(b->num, out, outl);
BIO_clear_retry_flags(b);
if (ret <= 0) {
if (BIO_fd_should_retry(ret))
@ -132,7 +132,7 @@ static int fd_write(BIO *b, const char *in, int inl)
{
int ret;
clear_sys_error();
ret = UP_write(b->num, in, inl);
ret = (int)UP_write(b->num, in, inl);
BIO_clear_retry_flags(b);
if (ret <= 0) {
if (BIO_fd_should_retry(ret))
@ -198,10 +198,12 @@ static long fd_ctrl(BIO *b, int cmd, long num, void *ptr)
static int fd_puts(BIO *bp, const char *str)
{
int n, ret;
int ret;
size_t n = strlen(str);
n = strlen(str);
ret = fd_write(bp, str, n);
if (n > INT_MAX)
return -1;
ret = fd_write(bp, str, (int)n);
return ret;
}
@ -219,7 +221,7 @@ static int fd_gets(BIO *bp, char *buf, int size)
ptr[0] = '\0';
if (buf[0] != '\0')
ret = strlen(buf);
ret = (int)strlen(buf);
return ret;
}

View File

@ -139,9 +139,9 @@ static int file_read(BIO *b, char *out, int outl)
if (b->init && (out != NULL)) {
if (b->flags & BIO_FLAGS_UPLINK_INTERNAL)
ret = UP_fread(out, 1, (int)outl, b->ptr);
ret = (int)UP_fread(out, 1, outl, b->ptr);
else
ret = fread(out, 1, (int)outl, (FILE *)b->ptr);
ret = (int)fread(out, 1, outl, (FILE *)b->ptr);
if (ret == 0
&& (b->flags & BIO_FLAGS_UPLINK_INTERNAL
? UP_ferror((FILE *)b->ptr) : ferror((FILE *)b->ptr))) {
@ -160,9 +160,9 @@ static int file_write(BIO *b, const char *in, int inl)
if (b->init && (in != NULL)) {
if (b->flags & BIO_FLAGS_UPLINK_INTERNAL)
ret = UP_fwrite(in, (int)inl, 1, b->ptr);
ret = (int)UP_fwrite(in, inl, 1, b->ptr);
else
ret = fwrite(in, (int)inl, 1, (FILE *)b->ptr);
ret = (int)fwrite(in, inl, 1, (FILE *)b->ptr);
if (ret)
ret = inl;
/* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */
@ -348,17 +348,19 @@ static int file_gets(BIO *bp, char *buf, int size)
goto err;
}
if (buf[0] != '\0')
ret = strlen(buf);
ret = (int)strlen(buf);
err:
return ret;
}
static int file_puts(BIO *bp, const char *str)
{
int n, ret;
int ret;
size_t n = strlen(str);
n = strlen(str);
ret = file_write(bp, str, n);
if (n > INT_MAX)
return -1;
ret = file_write(bp, str, (int)n);
return ret;
}

View File

@ -214,7 +214,7 @@ static int mem_read(BIO *b, char *out, int outl)
static int mem_write(BIO *b, const char *in, int inl)
{
int ret = -1;
int blen;
size_t blen;
BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)b->ptr;
if (b->flags & BIO_FLAGS_MEM_RDONLY) {
@ -245,7 +245,7 @@ static long mem_ctrl(BIO *b, int cmd, long num, void *ptr)
char **pptr;
BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)b->ptr;
BUF_MEM *bm, *bo; /* bio_mem, bio_other */
long off, remain;
ossl_ssize_t off, remain;
if (b->flags & BIO_FLAGS_MEM_RDONLY) {
bm = bbm->buf;
@ -280,10 +280,12 @@ static long mem_ctrl(BIO *b, int cmd, long num, void *ptr)
bm->data = (num != 0) ? bo->data + num : bo->data;
bm->length = bo->length - num;
bm->max = bo->max - num;
off = num;
off = (ossl_ssize_t)num;
/* FALLTHRU */
case BIO_C_FILE_TELL:
ret = off;
ret = (long)off;
if (off > LONG_MAX)
ret = -1;
break;
case BIO_CTRL_EOF:
ret = (long)(bm->length == 0);
@ -349,7 +351,7 @@ static int mem_gets(BIO *bp, char *buf, int size)
if (bp->flags & BIO_FLAGS_MEM_RDONLY)
bm = bbm->buf;
BIO_clear_retry_flags(bp);
j = bm->length;
j = bm->length < INT_MAX ? (int)bm->length: INT_MAX;
if ((size - 1) < j)
j = size - 1;
if (j <= 0) {
@ -378,10 +380,12 @@ static int mem_gets(BIO *bp, char *buf, int size)
static int mem_puts(BIO *bp, const char *str)
{
int n, ret;
int ret;
size_t n = strlen(str);
n = strlen(str);
ret = mem_write(bp, str, n);
if (n > INT_MAX)
return -1;
ret = mem_write(bp, str, (int)n);
/* memory semantics is that it will always work */
return ret;
}

View File

@ -79,7 +79,12 @@ static int null_gets(BIO *bp, char *buf, int size)
static int null_puts(BIO *bp, const char *str)
{
size_t n;
if (str == NULL)
return 0;
return strlen(str);
n = strlen(str);
if (n > INT_MAX)
return -1;
return (int)n;
}

View File

@ -286,10 +286,12 @@ static long sock_ctrl(BIO *b, int cmd, long num, void *ptr)
static int sock_puts(BIO *bp, const char *str)
{
int n, ret;
int ret;
size_t n = strlen(str);
n = strlen(str);
ret = sock_write(bp, str, n);
if (n > INT_MAX)
return -1;
ret = sock_write(bp, str, (int)n);
return ret;
}

View File

@ -114,7 +114,7 @@ int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
carry &= (t2 == 0);
}
*rp = carry;
r->top += carry;
r->top += (int)carry;
r->neg = 0;
bn_check_top(r);

View File

@ -186,7 +186,7 @@ int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b,
}
mask = (BN_ULONG)0 - ((rtop - ntop) >> (8 * sizeof(ntop) - 1));
/* always true, if (rtop >= ntop) n->top = r->top; */
n->top = (int)(rtop & ~mask) | (ntop & mask);
n->top = (int)((rtop & ~mask) | (ntop & mask));
n->flags |= (BN_FLG_FIXED_TOP & ~mask);
}
ret = bn_mul_mont_fixed_top(n, n, r, b->m_ctx, ctx);

View File

@ -619,7 +619,7 @@ int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)
pow2_numbits_temp = r->d[i] | g->d[i];
pow2_condition_mask = constant_time_is_zero_bn(pow2_flag);
pow2_flag &= constant_time_is_zero_bn(pow2_numbits_temp);
pow2_shifts += pow2_flag;
pow2_shifts += (int)pow2_flag;
pow2_numbits = constant_time_select_bn(pow2_condition_mask,
pow2_numbits, pow2_numbits_temp);
}
@ -628,7 +628,7 @@ int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)
pow2_flag = 1;
for (j = 0; j < BN_BITS2; j++) {
pow2_flag &= pow2_numbits;
pow2_shifts += pow2_flag;
pow2_shifts += (int)pow2_flag;
pow2_numbits >>= 1;
}

View File

@ -114,7 +114,7 @@ signed char *bn_compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
r[j++] = sign * digit;
window_val >>= 1;
window_val += bit * BN_is_bit_set(scalar, j + w);
window_val += bit * BN_is_bit_set(scalar, (int)(j + w));
if (window_val > next_bit) {
ERR_raise(ERR_LIB_BN, ERR_R_INTERNAL_ERROR);

View File

@ -718,9 +718,9 @@ int BN_ucmp(const BIGNUM *a, const BIGNUM *b)
int res = 0;
for (i = 0; i < b->top; i++) {
res = constant_time_select_int(constant_time_lt_bn(ap[i], bp[i]),
res = constant_time_select_int((int)constant_time_lt_bn(ap[i], bp[i]),
-1, res);
res = constant_time_select_int(constant_time_lt_bn(bp[i], ap[i]),
res = constant_time_select_int((int)constant_time_lt_bn(bp[i], ap[i]),
1, res);
}
return res;
@ -1057,10 +1057,10 @@ int ossl_bn_is_word_fixed_top(const BIGNUM *a, const BN_ULONG w)
if (a->neg || a->top == 0)
return 0;
res = constant_time_select_int(constant_time_eq_bn(ap[0], w), 1, 0);
res = constant_time_select_int((int)constant_time_eq_bn(ap[0], w), 1, 0);
for (i = 1; i < a->top; i++)
res = constant_time_select_int(constant_time_is_zero_bn(ap[i]),
res = constant_time_select_int((int)constant_time_is_zero_bn(ap[i]),
res, 0);
return res;
}

View File

@ -59,7 +59,7 @@ int bn_mod_add_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
BN_ULONG carry, temp, mask, *rp, *tp = storage;
const BN_ULONG *ap, *bp;
if (bn_wexpand(r, mtop) == NULL)
if (bn_wexpand(r, (int)mtop) == NULL)
return 0;
if (mtop > OSSL_NELEM(storage)) {
@ -85,12 +85,12 @@ int bn_mod_add_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
bi += (i - b->dmax) >> (8 * sizeof(i) - 1);
}
rp = r->d;
carry -= bn_sub_words(rp, tp, m->d, mtop);
carry -= bn_sub_words(rp, tp, m->d, (int)mtop);
for (i = 0; i < mtop; i++) {
rp[i] = (carry & tp[i]) | (~carry & rp[i]);
((volatile BN_ULONG *)tp)[i] = 0;
}
r->top = mtop;
r->top = (int)mtop;
r->flags |= BN_FLG_FIXED_TOP;
r->neg = 0;
@ -140,7 +140,7 @@ int bn_mod_sub_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
BN_ULONG borrow, carry, ta, tb, mask, *rp;
const BN_ULONG *ap, *bp;
if (bn_wexpand(r, mtop) == NULL)
if (bn_wexpand(r, (int)mtop) == NULL)
return 0;
rp = r->d;
@ -176,7 +176,7 @@ int bn_mod_sub_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
carry += (rp[i] < ta);
}
r->top = mtop;
r->top = (int)mtop;
r->flags |= BN_FLG_FIXED_TOP;
r->neg = 0;

View File

@ -467,7 +467,7 @@ BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, CRYPTO_RWLOCK *lock,
}
int ossl_bn_mont_ctx_set(BN_MONT_CTX *ctx, const BIGNUM *modulus, int ri, const unsigned char *rr,
size_t rrlen, uint32_t nlo, uint32_t nhi)
int rrlen, uint32_t nlo, uint32_t nhi)
{
if (BN_copy(&ctx->N, modulus) == NULL)
return 0;

View File

@ -37,7 +37,7 @@ int BN_lshift1(BIGNUM *r, const BIGNUM *a)
c = t >> (BN_BITS2 - 1);
}
*rp = c;
r->top += c;
r->top += (int)c;
bn_check_top(r);
return 1;
}

View File

@ -72,7 +72,7 @@ static ossl_inline BN_ULONG bn_reduce_once_in_place(BN_ULONG *r,
const BN_ULONG *m,
BN_ULONG *tmp, size_t num)
{
carry -= bn_sub_words(tmp, r, m, num);
carry -= bn_sub_words(tmp, r, m, (int)num);
bn_select_words(r, carry, r /* tmp < 0 */, tmp /* tmp >= 0 */, num);
return carry;
}

View File

@ -149,7 +149,8 @@ int ossl_cmac_init(CMAC_CTX *ctx, const void *key, size_t keylen,
ctx->nlast_block = -1;
if (EVP_CIPHER_CTX_get0_cipher(ctx->cctx) == NULL)
return 0;
if (EVP_CIPHER_CTX_set_key_length(ctx->cctx, keylen) <= 0)
if (keylen > INT_MAX
|| EVP_CIPHER_CTX_set_key_length(ctx->cctx, (int)keylen) <= 0)
return 0;
if (!EVP_EncryptInit_ex2(ctx->cctx, NULL, key, zero_iv, param))
return 0;
@ -198,7 +199,7 @@ int CMAC_Update(CMAC_CTX *ctx, const void *in, size_t dlen)
nleft = dlen;
memcpy(ctx->last_block + ctx->nlast_block, data, nleft);
dlen -= nleft;
ctx->nlast_block += nleft;
ctx->nlast_block += (int)nleft;
/* If no more to process return */
if (dlen == 0)
return 1;
@ -224,14 +225,14 @@ int CMAC_Update(CMAC_CTX *ctx, const void *in, size_t dlen)
}
} else {
while (cipher_blocks > max_burst_blocks) {
if (EVP_Cipher(ctx->cctx, buf, data, max_burst_blocks * bl) <= 0)
if (EVP_Cipher(ctx->cctx, buf, data, (int)(max_burst_blocks * bl)) <= 0)
return 0;
dlen -= max_burst_blocks * bl;
data += max_burst_blocks * bl;
cipher_blocks -= max_burst_blocks;
}
if (cipher_blocks > 0) {
if (EVP_Cipher(ctx->cctx, buf, data, cipher_blocks * bl) <= 0)
if (EVP_Cipher(ctx->cctx, buf, data, (int)(cipher_blocks * bl)) <= 0)
return 0;
dlen -= cipher_blocks * bl;
data += cipher_blocks * bl;
@ -240,7 +241,7 @@ int CMAC_Update(CMAC_CTX *ctx, const void *in, size_t dlen)
}
/* Copy any data left to last block buffer */
memcpy(ctx->last_block, data, dlen);
ctx->nlast_block = dlen;
ctx->nlast_block = (int)dlen;
return 1;
}

View File

@ -124,7 +124,7 @@ static OSSL_CMP_ITAV *get_genm_itav(OSSL_CMP_CTX *ctx,
return itav;
}
if (OBJ_obj2txt(name + offset, sizeof(name) - offset, obj, 0) < 0)
if (OBJ_obj2txt(name + offset, (int)(sizeof(name) - offset), obj, 0) < 0)
strcat(name, "<unknown>");
ossl_cmp_log2(WARN, ctx, "%s' while expecting 'id-it-%s'", name, desc);
OSSL_CMP_ITAV_free(itav);

View File

@ -119,7 +119,7 @@ int ossl_cmp_hdr_update_messageTime(OSSL_CMP_PKIHEADER *hdr)
}
/* assign to *tgt a random byte array of given length */
static int set_random(ASN1_OCTET_STRING **tgt, OSSL_CMP_CTX *ctx, size_t len)
static int set_random(ASN1_OCTET_STRING **tgt, OSSL_CMP_CTX *ctx, int len)
{
unsigned char *bytes = OPENSSL_malloc(len);
int res = 0;

View File

@ -92,11 +92,11 @@ ASN1_BIT_STRING *ossl_cmp_calc_protection(const OSSL_CMP_CTX *ctx,
&protection, &sig_len))
goto end;
if ((prot = ASN1_BIT_STRING_new()) == NULL)
if (sig_len > INT_MAX || (prot = ASN1_BIT_STRING_new()) == NULL)
goto end;
/* OpenSSL by default encodes all bit strings as ASN.1 NamedBitList */
ossl_asn1_string_set_bits_left(prot, 0);
if (!ASN1_BIT_STRING_set(prot, protection, sig_len)) {
if (!ASN1_BIT_STRING_set(prot, protection, (int)sig_len)) {
ASN1_BIT_STRING_free(prot);
prot = NULL;
}

View File

@ -55,7 +55,7 @@ static OSSL_CMP_severity parse_level(const char *level)
if (HAS_PREFIX(level, OSSL_CMP_LOG_PREFIX))
level += strlen(OSSL_CMP_LOG_PREFIX);
len = end_level - level;
len = (int)(end_level - level);
if (len > max_level_len)
return -1;
OPENSSL_strlcpy(level_copy, level, len + 1);

View File

@ -85,7 +85,7 @@ static int dh_cms_set_shared_info(EVP_PKEY_CTX *pctx, CMS_RecipientInfo *ri)
ASN1_OCTET_STRING *ukm;
const unsigned char *p;
unsigned char *dukm = NULL;
size_t dukmlen = 0;
int dukmlen = 0;
int keylen, plen;
EVP_CIPHER *kekcipher = NULL;
EVP_CIPHER_CTX *kekctx;
@ -201,7 +201,7 @@ static int dh_cms_encrypt(CMS_RecipientInfo *ri)
ASN1_OCTET_STRING *ukm;
unsigned char *penc = NULL, *dukm = NULL;
int penclen;
size_t dukmlen = 0;
int dukmlen = 0;
int rv = 0;
int kdf_type, wrap_nid;
const EVP_MD *kdf_md;

View File

@ -107,7 +107,7 @@ BIO *ossl_cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec,
piv = aparams.iv;
if (ec->taglen > 0
&& EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
ec->taglen, ec->tag) <= 0) {
(int)ec->taglen, ec->tag) <= 0) {
ERR_raise(ERR_LIB_CMS, CMS_R_CIPHER_AEAD_SET_TAG_ERROR);
goto err;
}
@ -140,7 +140,7 @@ BIO *ossl_cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec,
if (ec->keylen != tkeylen) {
/* If necessary set key length */
if (EVP_CIPHER_CTX_set_key_length(ctx, ec->keylen) <= 0) {
if (EVP_CIPHER_CTX_set_key_length(ctx, (int)ec->keylen) <= 0) {
/*
* Only reveal failure if debugging so we don't leak information
* which may be useful in MMA.

View File

@ -552,7 +552,7 @@ static int cms_RecipientInfo_ktri_encrypt(const CMS_ContentInfo *cms,
if (EVP_PKEY_encrypt(pctx, ek, &eklen, ec->key, ec->keylen) <= 0)
goto err;
ASN1_STRING_set0(ktri->encryptedKey, ek, eklen);
ASN1_STRING_set0(ktri->encryptedKey, ek, (int)eklen);
ek = NULL;
ret = 1;
@ -700,7 +700,7 @@ CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid,
CMS_KEKRecipientInfo *kekri;
STACK_OF(CMS_RecipientInfo) *ris = CMS_get0_RecipientInfos(cms);
if (ris == NULL)
if (ris == NULL || idlen > INT_MAX)
goto err;
if (nid == NID_undef) {
@ -774,7 +774,7 @@ CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid,
kekri->key = key;
kekri->keylen = keylen;
ASN1_STRING_set0(kekri->kekid->keyIdentifier, id, idlen);
ASN1_STRING_set0(kekri->kekid->keyIdentifier, id, (int)idlen);
kekri->kekid->date = date;
@ -909,7 +909,7 @@ static int cms_RecipientInfo_kekri_encrypt(const CMS_ContentInfo *cms,
EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);
if (!EVP_EncryptInit_ex(ctx, cipher, NULL, kekri->key, NULL)
|| !EVP_EncryptUpdate(ctx, wkey, &wkeylen, ec->key, ec->keylen)
|| !EVP_EncryptUpdate(ctx, wkey, &wkeylen, ec->key, (int)ec->keylen)
|| !EVP_EncryptFinal_ex(ctx, wkey + wkeylen, &outlen)) {
ERR_raise(ERR_LIB_CMS, CMS_R_WRAP_ERROR);
goto err;

View File

@ -219,7 +219,7 @@ static int cms_kek_cipher(unsigned char **pout, size_t *poutlen,
int outlen;
keklen = EVP_CIPHER_CTX_get_key_length(kari->ctx);
if (keklen > EVP_MAX_KEY_LENGTH)
if (keklen > EVP_MAX_KEY_LENGTH || inlen > INT_MAX)
return 0;
/* Derive KEK */
if (EVP_PKEY_derive(kari->pctx, kek, &keklen) <= 0)
@ -228,12 +228,12 @@ static int cms_kek_cipher(unsigned char **pout, size_t *poutlen,
if (!EVP_CipherInit_ex(kari->ctx, NULL, NULL, kek, NULL, enc))
goto err;
/* obtain output length of ciphered key */
if (!EVP_CipherUpdate(kari->ctx, NULL, &outlen, in, inlen))
if (!EVP_CipherUpdate(kari->ctx, NULL, &outlen, in, (int)inlen))
goto err;
out = OPENSSL_malloc(outlen);
if (out == NULL)
goto err;
if (!EVP_CipherUpdate(kari->ctx, out, &outlen, in, inlen))
if (!EVP_CipherUpdate(kari->ctx, out, &outlen, in, (int)inlen))
goto err;
*pout = out;
*poutlen = (size_t)outlen;
@ -525,7 +525,7 @@ int ossl_cms_RecipientInfo_kari_encrypt(const CMS_ContentInfo *cms,
if (!cms_kek_cipher(&enckey, &enckeylen, ec->key, ec->keylen,
kari, 1))
return 0;
ASN1_STRING_set0(rek->encryptedKey, enckey, enckeylen);
ASN1_STRING_set0(rek->encryptedKey, enckey, (int)enckeylen);
}
return 1;

View File

@ -203,18 +203,18 @@ static int kek_unwrap_key(unsigned char *out, size_t *outlen,
const unsigned char *in, size_t inlen,
EVP_CIPHER_CTX *ctx)
{
size_t blocklen = EVP_CIPHER_CTX_get_block_size(ctx);
int blocklen = EVP_CIPHER_CTX_get_block_size(ctx);
unsigned char *tmp;
int outl, rv = 0;
if (blocklen == 0)
if (blocklen <= 0)
return 0;
if (inlen < 2 * blocklen) {
if (inlen < 2 * (size_t)blocklen) {
/* too small */
return 0;
}
if (inlen % blocklen) {
if (inlen > INT_MAX || inlen % blocklen) {
/* Invalid size */
return 0;
}
@ -231,12 +231,12 @@ static int kek_unwrap_key(unsigned char *out, size_t *outlen,
|| !EVP_DecryptUpdate(ctx, tmp, &outl,
tmp + inlen - blocklen, blocklen)
/* Can now decrypt first n - 1 blocks */
|| !EVP_DecryptUpdate(ctx, tmp, &outl, in, inlen - blocklen)
|| !EVP_DecryptUpdate(ctx, tmp, &outl, in, (int)(inlen - blocklen))
/* Reset IV to original value */
|| !EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, NULL)
/* Decrypt again */
|| !EVP_DecryptUpdate(ctx, tmp, &outl, tmp, inlen))
|| !EVP_DecryptUpdate(ctx, tmp, &outl, tmp, (int)inlen))
goto err;
/* Check check bytes */
if (((tmp[1] ^ tmp[4]) & (tmp[2] ^ tmp[5]) & (tmp[3] ^ tmp[6])) != 0xff) {
@ -294,8 +294,8 @@ static int kek_wrap_key(unsigned char *out, size_t *outlen,
olen - 4 - inlen, 0) <= 0)
return 0;
/* Encrypt twice */
if (!EVP_EncryptUpdate(ctx, out, &dummy, out, olen)
|| !EVP_EncryptUpdate(ctx, out, &dummy, out, olen))
if (!EVP_EncryptUpdate(ctx, out, &dummy, out, (int)olen)
|| !EVP_EncryptUpdate(ctx, out, &dummy, out, (int)olen))
return 0;
}
@ -371,7 +371,7 @@ int ossl_cms_RecipientInfo_pwri_crypt(const CMS_ContentInfo *cms,
/* Finish password based key derivation to setup key in "ctx" */
if (EVP_PBE_CipherInit_ex(algtmp->algorithm,
(char *)pwri->pass, pwri->passlen,
(char *)pwri->pass, (int)pwri->passlen,
algtmp->parameter, kekctx, en_de,
cms_ctx->libctx, cms_ctx->propq) < 0) {
ERR_raise(ERR_LIB_CMS, ERR_R_EVP_LIB);
@ -393,7 +393,7 @@ int ossl_cms_RecipientInfo_pwri_crypt(const CMS_ContentInfo *cms,
if (!kek_wrap_key(key, &keylen, ec->key, ec->keylen, kekctx, cms_ctx))
goto err;
pwri->encryptedKey->data = key;
pwri->encryptedKey->length = keylen;
pwri->encryptedKey->length = (int)keylen;
} else {
key = OPENSSL_malloc(pwri->encryptedKey->length);
if (key == NULL)

View File

@ -236,7 +236,7 @@ static int rsa_cms_sign(CMS_SignerInfo *si)
return 0;
if ((aid_len = params[0].return_size) == 0)
return 0;
if (d2i_X509_ALGOR(&alg, &pp, aid_len) == NULL)
if (d2i_X509_ALGOR(&alg, &pp, (long)aid_len) == NULL)
return 0;
return 1;
}

View File

@ -799,7 +799,7 @@ static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
OPENSSL_free(sig);
goto err;
}
ASN1_STRING_set0(si->signature, sig, siglen);
ASN1_STRING_set0(si->signature, sig, (int)siglen);
} else {
unsigned char *sig;
unsigned int siglen;
@ -910,7 +910,7 @@ int CMS_SignerInfo_sign(CMS_SignerInfo *si)
EVP_MD_CTX_reset(mctx);
ASN1_STRING_set0(si->signature, abuf, siglen);
ASN1_STRING_set0(si->signature, abuf, (int)siglen);
return 1;

View File

@ -553,10 +553,10 @@ static int bio_brotli_read(BIO *b, char *out, int outl)
* No data in input buffer try to read some in, if an error then
* return the total data read.
*/
ret = BIO_read(next, ctx->decode.buf, ctx->decode.bufsize);
ret = BIO_read(next, ctx->decode.buf, (int)ctx->decode.bufsize);
if (ret <= 0) {
/* Total data read */
int tot = outl - ctx->decode.avail_out;
int tot = outl - (int)ctx->decode.avail_out;
BIO_copy_next_retry(b);
if (ret < 0)
@ -608,10 +608,10 @@ static int bio_brotli_write(BIO *b, const char *in, int inl)
for (;;) {
/* If data in output buffer write it first */
while (ctx->encode.count > 0) {
ret = BIO_write(next, ctx->encode.ptr, ctx->encode.count);
ret = BIO_write(next, ctx->encode.ptr, (int)ctx->encode.count);
if (ret <= 0) {
/* Total data written */
int tot = inl - ctx->encode.avail_in;
int tot = inl - (int)ctx->encode.avail_in;
BIO_copy_next_retry(b);
if (ret < 0)
@ -664,7 +664,7 @@ static int bio_brotli_flush(BIO *b)
for (;;) {
/* If data in output buffer write it first */
while (ctx->encode.count > 0) {
ret = BIO_write(next, ctx->encode.ptr, ctx->encode.count);
ret = BIO_write(next, ctx->encode.ptr, (int)ctx->encode.count);
if (ret <= 0) {
BIO_copy_next_retry(b);
return ret;

View File

@ -613,19 +613,19 @@ static int bio_zstd_read(BIO *b, char *out, int outl)
}
/* No more output space */
if (outBuf.pos == outBuf.size)
return outBuf.pos;
return (int)outBuf.pos;
} while (ctx->decompress.inbuf.pos < ctx->decompress.inbuf.size);
/*
* No data in input buffer try to read some in, if an error then
* return the total data read.
*/
ret = BIO_read(next, ctx->decompress.buffer, ctx->decompress.bufsize);
ret = BIO_read(next, ctx->decompress.buffer, (int)ctx->decompress.bufsize);
if (ret <= 0) {
BIO_copy_next_retry(b);
if (ret < 0 && outBuf.pos == 0)
return ret;
return outBuf.pos;
return (int)outBuf.pos;
}
ctx->decompress.inbuf.size = ret;
ctx->decompress.inbuf.pos = 0;
@ -665,19 +665,19 @@ static int bio_zstd_write(BIO *b, const char *in, int inl)
/* If data in output buffer write it first */
while (ctx->compress.write_pos < ctx->compress.outbuf.pos) {
ret = BIO_write(next, (unsigned char*)ctx->compress.outbuf.dst + ctx->compress.write_pos,
ctx->compress.outbuf.pos - ctx->compress.write_pos);
(int)(ctx->compress.outbuf.pos - ctx->compress.write_pos));
if (ret <= 0) {
BIO_copy_next_retry(b);
if (ret < 0 && inBuf.pos == 0)
return ret;
return inBuf.pos;
return (int)inBuf.pos;
}
ctx->compress.write_pos += ret;
}
/* Have we consumed all supplied data? */
if (done)
return inBuf.pos;
return (int)inBuf.pos;
/* Reset buffer */
ctx->compress.outbuf.pos = 0;
@ -717,7 +717,7 @@ static int bio_zstd_flush(BIO *b)
/* If data in output buffer write it first */
while (ctx->compress.write_pos < ctx->compress.outbuf.pos) {
ret = BIO_write(next, (unsigned char*)ctx->compress.outbuf.dst + ctx->compress.write_pos,
ctx->compress.outbuf.pos - ctx->compress.write_pos);
(int)(ctx->compress.outbuf.pos - ctx->compress.write_pos));
if (ret <= 0) {
BIO_copy_next_retry(b);
return ret;

View File

@ -68,7 +68,7 @@ int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
if (ctx->meth->compress == NULL) {
return -1;
}
ret = ctx->meth->compress(ctx, out, olen, in, ilen);
ret = (int)ctx->meth->compress(ctx, out, olen, in, ilen);
if (ret > 0) {
ctx->compress_in += ilen;
ctx->compress_out += ret;
@ -84,7 +84,7 @@ int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
if (ctx->meth->expand == NULL) {
return -1;
}
ret = ctx->meth->expand(ctx, out, olen, in, ilen);
ret = (int)ctx->meth->expand(ctx, out, olen, in, ilen);
if (ret > 0) {
ctx->expand_in += ilen;
ctx->expand_out += ret;

View File

@ -192,7 +192,7 @@ CONF_VALUE *_CONF_new_section(CONF *conf, const char *section)
goto err;
if ((v = OPENSSL_malloc(sizeof(*v))) == NULL)
goto err;
i = strlen(section) + 1;
i = (int)strlen(section) + 1;
if ((v->section = OPENSSL_malloc(i)) == NULL)
goto err;

View File

@ -263,7 +263,7 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
if (in != NULL && BIO_gets(in, p, CONFBUFSIZE - 1) < 0)
goto err;
p[CONFBUFSIZE - 1] = '\0';
ii = i = strlen(p);
ii = i = (int)strlen(p);
if (first_call) {
/* Other BOMs imply unsupported multibyte encoding,
* so don't strip them and let the error raise */
@ -641,15 +641,14 @@ static void clear_comments(CONF *conf, char *p)
static int str_copy(CONF *conf, char *section, char **pto, char *from)
{
int q, r, rr = 0, to = 0, len = 0;
int q, r, rr = 0, to = 0;
char *s, *e, *rp, *p, *rrp, *np, *cp, v;
BUF_MEM *buf;
if ((buf = BUF_MEM_new()) == NULL)
return 0;
len = strlen(from) + 1;
if (!BUF_MEM_grow(buf, len))
if (!BUF_MEM_grow(buf, strlen(from) + 1))
goto err;
for (;;) {
@ -771,11 +770,6 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from)
while (*p)
buf->data[to++] = *(p++);
/*
* Since we change the pointer 'from', we also have to change the
* perceived length of the string it points at. /RL
*/
len -= e - from;
from = e;
/*

View File

@ -396,7 +396,8 @@ static CONF_MODULE *module_add(DSO *dso, const char *name,
static CONF_MODULE *module_find(const char *name)
{
CONF_MODULE *tmod;
int i, nchar;
int i;
size_t nchar;
char *p;
STACK_OF(CONF_MODULE) *mods;
@ -754,7 +755,7 @@ int CONF_parse_list(const char *list_, int sep, int nospc,
while (isspace((unsigned char)*tmpend))
tmpend--;
}
ret = list_cb(lstart, tmpend - lstart + 1, arg);
ret = list_cb(lstart, (int)(tmpend - lstart + 1), arg);
}
if (ret <= 0)
return ret;

View File

@ -179,7 +179,7 @@ int ossl_namemap_name2num_n(const OSSL_NAMEMAP *namemap,
return 0;
HT_INIT_KEY(&key);
HT_SET_KEY_STRING_CASE_N(&key, name, name, name_len);
HT_SET_KEY_STRING_CASE_N(&key, name, name, (int)name_len);
val = ossl_ht_get(namemap->namenum_ht, TO_HT_KEY(&key));
@ -191,7 +191,7 @@ int ossl_namemap_name2num_n(const OSSL_NAMEMAP *namemap,
}
const char *ossl_namemap_num2name(const OSSL_NAMEMAP *namemap, int number,
size_t idx)
int idx)
{
NAMES *names;
const char *ret = NULL;

View File

@ -89,7 +89,7 @@ OSSL_CRMF_PBMPARAMETER *OSSL_CRMF_pbmp_new(OSSL_LIB_CTX *libctx, size_t slen,
goto err;
}
if (!ASN1_INTEGER_set(pbm->iterationCount, itercnt)) {
if (!ASN1_INTEGER_set(pbm->iterationCount, (long)itercnt)) {
ERR_raise(ERR_LIB_CRMF, CRMF_R_CRMFERROR);
goto err;
}

View File

@ -60,7 +60,7 @@ int OPENSSL_isservice(void)
}
if (_OPENSSL_isservice.p != (void *)-1)
return (*_OPENSSL_isservice.f) ();
return (int)((*_OPENSSL_isservice.f)());
h = GetProcessWindowStation();
if (h == NULL)
@ -144,7 +144,7 @@ void OPENSSL_showfatal(const char *fmta, ...)
fmt = (const TCHAR *)L"no stack?";
break;
}
if (!MultiByteToWideChar(CP_ACP, 0, fmta, len_0, fmtw, len_0))
if (!MultiByteToWideChar(CP_ACP, 0, fmta, (int)len_0, fmtw, (int)len_0))
for (i = 0; i < len_0; i++)
fmtw[i] = (WCHAR)fmta[i];
for (i = 0; i < len_0; i++) {

View File

@ -27,17 +27,17 @@ static int ct_base64_decode(const char *in, unsigned char **out)
int outlen, i;
unsigned char *outbuf = NULL;
if (inlen == 0) {
if (inlen == 0 || inlen > INT_MAX) {
*out = NULL;
return 0;
}
outlen = (inlen / 4) * 3;
outlen = (int)((inlen / 4) * 3);
outbuf = OPENSSL_malloc(outlen);
if (outbuf == NULL)
goto err;
outlen = EVP_DecodeBlock(outbuf, (unsigned char *)in, inlen);
outlen = EVP_DecodeBlock(outbuf, (unsigned char *)in, (int)inlen);
if (outlen < 0) {
ERR_raise(ERR_LIB_CT, CT_R_BASE64_DECODE_ERROR);
goto err;

View File

@ -64,7 +64,7 @@ int o2i_SCT_signature(SCT *sct, const unsigned char **in, size_t len)
len_remaining -= siglen;
*in = p + siglen;
return len - len_remaining;
return (int)(len - len_remaining);
}
SCT *o2i_SCT(SCT **psct, const unsigned char **in, size_t len)
@ -189,7 +189,7 @@ int i2o_SCT_signature(const SCT *sct, unsigned char **out)
memcpy(p, sct->sig, sct->sig_len);
}
return len;
return (int)len;
err:
OPENSSL_free(pstart);
return -1;
@ -215,8 +215,10 @@ int i2o_SCT(const SCT *sct, unsigned char **out)
else
len = sct->sct_len;
if (len > INT_MAX)
return -1;
if (out == NULL)
return len;
return (int)len;
if (*out != NULL) {
p = *out;
@ -244,7 +246,7 @@ int i2o_SCT(const SCT *sct, unsigned char **out)
memcpy(p, sct->sct, len);
}
return len;
return (int)len;
err:
OPENSSL_free(pstart);
return -1;
@ -357,7 +359,7 @@ int i2o_SCT_LIST(const STACK_OF(SCT) *a, unsigned char **pp)
if (!is_pp_new)
*pp += len2;
}
return len2;
return (int)len2;
err:
if (is_pp_new) {

View File

@ -82,7 +82,7 @@ void SCT_print(const SCT *sct, BIO *out, int indent,
if (sct->version != SCT_VERSION_V1) {
BIO_printf(out, "unknown\n%*s", indent + 16, "");
BIO_hex_string(out, indent + 16, 16, sct->sct, sct->sct_len);
BIO_hex_string(out, indent + 16, 16, sct->sct, (int)sct->sct_len);
return;
}
@ -94,7 +94,7 @@ void SCT_print(const SCT *sct, BIO *out, int indent,
}
BIO_printf(out, "\n%*sLog ID : ", indent + 4, "");
BIO_hex_string(out, indent + 16, 16, sct->log_id, sct->log_id_len);
BIO_hex_string(out, indent + 16, 16, sct->log_id, (int)sct->log_id_len);
BIO_printf(out, "\n%*sTimestamp : ", indent + 4, "");
timestamp_print(sct->timestamp, out);
@ -103,12 +103,12 @@ void SCT_print(const SCT *sct, BIO *out, int indent,
if (sct->ext_len == 0)
BIO_printf(out, "none");
else
BIO_hex_string(out, indent + 16, 16, sct->ext, sct->ext_len);
BIO_hex_string(out, indent + 16, 16, sct->ext, (int)sct->ext_len);
BIO_printf(out, "\n%*sSignature : ", indent + 4, "");
SCT_signature_algorithms_print(sct, out);
BIO_printf(out, "\n%*s ", indent + 4, "");
BIO_hex_string(out, indent + 16, 16, sct->sig, sct->sig_len);
BIO_hex_string(out, indent + 16, 16, sct->sig, (int)sct->sig_len);
}
void SCT_LIST_print(const STACK_OF(SCT) *sct_list, BIO *out, int indent,

View File

@ -19,11 +19,14 @@
void DES_string_to_key(const char *str, DES_cblock *key)
{
DES_key_schedule ks;
int i, length;
int i;
size_t length;
memset(key, 0, 8);
length = strlen(str);
for (i = 0; i < length; i++) {
if (length > INT_MAX)
length = INT_MAX;
for (i = 0; i < (int)length; i++) {
register unsigned char j = str[i];
if ((i % 16) < 8)
@ -38,7 +41,7 @@ void DES_string_to_key(const char *str, DES_cblock *key)
}
DES_set_odd_parity(key);
DES_set_key_unchecked(key, &ks);
DES_cbc_cksum((const unsigned char *)str, key, length, &ks, key);
DES_cbc_cksum((const unsigned char *)str, key, (int)length, &ks, key);
OPENSSL_cleanse(&ks, sizeof(ks));
DES_set_odd_parity(key);
}
@ -46,12 +49,15 @@ void DES_string_to_key(const char *str, DES_cblock *key)
void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2)
{
DES_key_schedule ks;
int i, length;
int i;
size_t length;
memset(key1, 0, 8);
memset(key2, 0, 8);
length = strlen(str);
for (i = 0; i < length; i++) {
if (length > INT_MAX)
length = INT_MAX;
for (i = 0; i < (int)length; i++) {
register unsigned char j = str[i];
if ((i % 32) < 16) {
@ -74,9 +80,9 @@ void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2)
DES_set_odd_parity(key1);
DES_set_odd_parity(key2);
DES_set_key_unchecked(key1, &ks);
DES_cbc_cksum((const unsigned char *)str, key1, length, &ks, key1);
DES_cbc_cksum((const unsigned char *)str, key1, (int)length, &ks, key1);
DES_set_key_unchecked(key2, &ks);
DES_cbc_cksum((const unsigned char *)str, key2, length, &ks, key2);
DES_cbc_cksum((const unsigned char *)str, key2, (int)length, &ks, key2);
OPENSSL_cleanse(&ks, sizeof(ks));
DES_set_odd_parity(key1);
DES_set_odd_parity(key2);

View File

@ -28,7 +28,7 @@
static int bits2int(BIGNUM *out, int qlen_bits,
const unsigned char *in, size_t inlen)
{
int blen_bits = inlen * 8;
int blen_bits = (int)(inlen * 8);
int shift;
if (BN_bin2bn(in, (int)inlen, out) == NULL)
@ -55,7 +55,7 @@ static int bits2int(BIGNUM *out, int qlen_bits,
static int bits2int_consttime(BIGNUM *out, int qlen_bits,
const unsigned char *in, size_t inlen)
{
int blen_bits = (inlen - sizeof(BN_ULONG)) * 8;
int blen_bits = (int)((inlen - sizeof(BN_ULONG)) * 8);
int shift;
if (BN_bin2bn(in, (int)inlen, out) == NULL)

View File

@ -410,7 +410,7 @@ static int dh_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
dh = (DH *) EVP_PKEY_get0_DH(pkey);
if (dh == NULL)
return 0;
return ossl_dh_key2buf(dh, arg2, 0, 1);
return (int)ossl_dh_key2buf(dh, arg2, 0, 1);
default:
return -2;
}

View File

@ -116,7 +116,7 @@ DH *d2i_DHxparams(DH **a, const unsigned char **pp, long length)
if (dhx->vparams != NULL) {
/* The counter has a maximum value of 4 * numbits(p) - 1 */
size_t counter = (size_t)BN_get_word(dhx->vparams->counter);
int counter = (int)BN_get_word(dhx->vparams->counter);
ossl_ffc_params_set_validate_params(params, dhx->vparams->seed->data,
dhx->vparams->seed->length,
counter);

View File

@ -114,7 +114,7 @@ int ossl_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
{
int ret = 0, i;
volatile size_t npad = 0, mask = 1;
volatile int npad = 0, mask = 1;
/* compute the key; ret is constant unless compute_key is external */
#ifdef FIPS_MODULE
@ -392,7 +392,7 @@ int ossl_dh_buf2key(DH *dh, const unsigned char *buf, size_t len)
const BIGNUM *p;
int ret;
if ((pubkey = BN_bin2bn(buf, len, NULL)) == NULL)
if (len > INT_MAX || (pubkey = BN_bin2bn(buf, (int)len, NULL)) == NULL)
goto err;
DH_get0_pqg(dh, &p, NULL, NULL);
if (p == NULL || BN_num_bytes(p) == 0) {

View File

@ -188,7 +188,7 @@ static int pkey_dh_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
return 1;
case EVP_PKEY_CTRL_GET_DH_KDF_OUTLEN:
*(int *)p2 = dctx->kdf_outlen;
*(int *)p2 = (int)dctx->kdf_outlen;
return 1;
case EVP_PKEY_CTRL_DH_KDF_UKM:
@ -202,7 +202,7 @@ static int pkey_dh_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
case EVP_PKEY_CTRL_GET_DH_KDF_UKM:
*(unsigned char **)p2 = dctx->kdf_ukm;
return dctx->kdf_ukmlen;
return (int)dctx->kdf_ukmlen;
case EVP_PKEY_CTRL_DH_KDF_OID:
ASN1_OBJECT_free(dctx->kdf_oid);

View File

@ -96,7 +96,7 @@ static int pkey_dsa_sign(EVP_PKEY_CTX *ctx, unsigned char *sig,
return 0;
}
ret = DSA_sign(0, tbs, tbslen, sig, &sltmp, dsa);
ret = DSA_sign(0, tbs, (int)tbslen, sig, &sltmp, dsa);
if (ret <= 0)
return ret;
@ -125,7 +125,7 @@ static int pkey_dsa_verify(EVP_PKEY_CTX *ctx,
return 0;
}
ret = DSA_verify(0, tbs, tbslen, sig, siglen, dsa);
ret = DSA_verify(0, tbs, (int)tbslen, sig, (int)siglen, dsa);
return ret;
}

View File

@ -449,9 +449,9 @@ static char *win32_name_converter(DSO *dso, const char *filename)
(strstr(filename, ":") == NULL));
/* If transform != 0, then we convert to %s.dll, else just dupe filename */
len = strlen(filename) + 1;
len = (int)strlen(filename) + 1;
if (transform)
len += strlen(".dll");
len += (int)strlen(".dll");
translated = OPENSSL_malloc(len);
if (translated == NULL) {
ERR_raise(ERR_LIB_DSO, DSO_R_NAME_TRANSLATION_FAILED);

View File

@ -260,7 +260,7 @@ int ossl_ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
point_conversion_form_t form;
int y_bit, m;
BIGNUM *x, *y, *yxi;
size_t field_len, enc_len;
int field_len, enc_len;
int ret = 0;
#ifndef FIPS_MODULE
BN_CTX *new_ctx = NULL;
@ -312,7 +312,7 @@ int ossl_ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
(form ==
POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2 * field_len;
if (len != enc_len) {
if (len != (size_t)enc_len) {
ERR_raise(ERR_LIB_EC, EC_R_INVALID_ENCODING);
return 0;
}

View File

@ -412,8 +412,8 @@ static int ec_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
return EC_KEY_oct2key(evp_pkey_get0_EC_KEY_int(pkey), arg2, arg1, NULL);
case ASN1_PKEY_CTRL_GET1_TLS_ENCPT:
return EC_KEY_key2buf(EVP_PKEY_get0_EC_KEY(pkey),
POINT_CONVERSION_UNCOMPRESSED, arg2, NULL);
return (int)EC_KEY_key2buf(EVP_PKEY_get0_EC_KEY(pkey),
POINT_CONVERSION_UNCOMPRESSED, arg2, NULL);
default:
return -2;

View File

@ -312,7 +312,7 @@ static int ec_asn1_group2curve(const EC_GROUP *group, X9_62_CURVE *curve)
int ok = 0;
BIGNUM *tmp_1 = NULL, *tmp_2 = NULL;
unsigned char *a_buf = NULL, *b_buf = NULL;
size_t len;
int len;
if (!group || !curve || !curve->a || !curve->b)
return 0;
@ -333,7 +333,7 @@ static int ec_asn1_group2curve(const EC_GROUP *group, X9_62_CURVE *curve)
* definition of Curve, C.1's definition of FieldElement, and 2.3.5's
* definition of how to encode the field elements.
*/
len = ((size_t)EC_GROUP_get_degree(group) + 7) / 8;
len = (EC_GROUP_get_degree(group) + 7) / 8;
if ((a_buf = OPENSSL_malloc(len)) == NULL
|| (b_buf = OPENSSL_malloc(len)) == NULL)
goto err;
@ -421,7 +421,7 @@ ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group,
form = EC_GROUP_get_point_conversion_form(group);
len = EC_POINT_point2buf(group, point, form, &buffer, NULL);
if (len == 0) {
if (len == 0 || len > INT_MAX) {
ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);
goto err;
}
@ -430,7 +430,7 @@ ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group,
ERR_raise(ERR_LIB_EC, ERR_R_ASN1_LIB);
goto err;
}
ASN1_STRING_set0(ret->base, buffer, len);
ASN1_STRING_set0(ret->base, buffer, (int)len);
/* set the order */
tmp = EC_GROUP_get0_order(group);
@ -1037,12 +1037,12 @@ int i2d_ECPrivateKey(const EC_KEY *a, unsigned char **out)
privlen = EC_KEY_priv2buf(a, &priv);
if (privlen == 0) {
if (privlen == 0 || privlen > INT_MAX) {
ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);
goto err;
}
ASN1_STRING_set0(priv_key->privateKey, priv, privlen);
ASN1_STRING_set0(priv_key->privateKey, priv, (int)privlen);
priv = NULL;
if (!(a->enc_flag & EC_PKEY_NO_PARAMETERS)) {
@ -1063,13 +1063,13 @@ int i2d_ECPrivateKey(const EC_KEY *a, unsigned char **out)
publen = EC_KEY_key2buf(a, a->conv_form, &pub, NULL);
if (publen == 0) {
if (publen == 0 || publen > INT_MAX) {
ERR_raise(ERR_LIB_EC, ERR_R_EC_LIB);
goto err;
}
ossl_asn1_string_set_bits_left(priv_key->publicKey, 0);
ASN1_STRING_set0(priv_key->publicKey, pub, publen);
ASN1_STRING_set0(priv_key->publicKey, pub, (int)publen);
pub = NULL;
}
@ -1164,9 +1164,13 @@ int i2o_ECPublicKey(const EC_KEY *a, unsigned char **out)
buf_len = EC_POINT_point2oct(a->group, a->pub_key,
a->conv_form, NULL, 0, NULL);
if (buf_len > INT_MAX) {
ERR_raise(ERR_LIB_EC, ERR_R_PASSED_INVALID_ARGUMENT);
return 0;
}
if (out == NULL || buf_len == 0)
/* out == NULL => just return the length of the octet string */
return buf_len;
return (int)buf_len;
if (*out == NULL) {
if ((*out = OPENSSL_malloc(buf_len)) == NULL)
@ -1184,7 +1188,7 @@ int i2o_ECPublicKey(const EC_KEY *a, unsigned char **out)
}
if (!new_buffer)
*out += buf_len;
return buf_len;
return (int)buf_len;
}
DECLARE_ASN1_FUNCTIONS(ECDSA_SIG)

View File

@ -28,10 +28,10 @@ BIGNUM *EC_POINT_point2bn(const EC_GROUP *group,
buf_len = EC_POINT_point2buf(group, point, form, &buf, ctx);
if (buf_len == 0)
if (buf_len == 0 || buf_len > INT_MAX)
return NULL;
ret = BN_bin2bn(buf, buf_len, ret);
ret = BN_bin2bn(buf, (int)buf_len, ret);
OPENSSL_free(buf);
@ -41,7 +41,7 @@ BIGNUM *EC_POINT_point2bn(const EC_GROUP *group,
EC_POINT *EC_POINT_bn2point(const EC_GROUP *group,
const BIGNUM *bn, EC_POINT *point, BN_CTX *ctx)
{
size_t buf_len = 0;
int buf_len = 0;
unsigned char *buf;
EC_POINT *ret;

View File

@ -1007,14 +1007,14 @@ size_t EC_KEY_priv2oct(const EC_KEY *eckey,
size_t ossl_ec_key_simple_priv2oct(const EC_KEY *eckey,
unsigned char *buf, size_t len)
{
size_t buf_len;
int buf_len;
buf_len = (EC_GROUP_order_bits(eckey->group) + 7) / 8;
if (eckey->priv_key == NULL)
return 0;
if (buf == NULL)
return buf_len;
else if (len < buf_len)
else if (len < (size_t)buf_len)
return 0;
/* Octetstring may need leading zeros if BN is to short */
@ -1046,13 +1046,17 @@ int EC_KEY_oct2priv(EC_KEY *eckey, const unsigned char *buf, size_t len)
int ossl_ec_key_simple_oct2priv(EC_KEY *eckey, const unsigned char *buf,
size_t len)
{
if (len > INT_MAX) {
ERR_raise(ERR_LIB_EC, ERR_R_PASSED_INVALID_ARGUMENT);
return 0;
}
if (eckey->priv_key == NULL)
eckey->priv_key = BN_secure_new();
if (eckey->priv_key == NULL) {
ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
return 0;
}
if (BN_bin2bn(buf, len, eckey->priv_key) == NULL) {
if (BN_bin2bn(buf, (int)len, eckey->priv_key) == NULL) {
ERR_raise(ERR_LIB_EC, ERR_R_BN_LIB);
return 0;
}

View File

@ -171,7 +171,7 @@ int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
memcpy(out, sec, outlen);
}
OPENSSL_clear_free(sec, seclen);
return outlen;
return (int)outlen;
}
EC_KEY_METHOD *EC_KEY_METHOD_new(const EC_KEY_METHOD *meth)

View File

@ -530,7 +530,7 @@ int ossl_ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
num_val += (size_t)1 << (wsize[i] - 1);
wNAF[i + 1] = NULL; /* make sure we always have a pivot */
wNAF[i] =
bn_compute_wNAF((i < num ? scalars[i] : scalar), wsize[i],
bn_compute_wNAF((i < num ? scalars[i] : scalar), (int)wsize[i],
&wNAF_len[i]);
if (wNAF[i] == NULL)
goto err;
@ -560,7 +560,7 @@ int ossl_ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
* use the window size for which we have precomputation
*/
wsize[num] = pre_comp->w;
tmp_wNAF = bn_compute_wNAF(scalar, wsize[num], &tmp_len);
tmp_wNAF = bn_compute_wNAF(scalar, (int)wsize[num], &tmp_len);
if (!tmp_wNAF)
goto err;
@ -708,7 +708,9 @@ int ossl_ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
r_is_at_infinity = 1;
for (k = max_len - 1; k >= 0; k--) {
if (max_len > INT_MAX)
goto err;
for (k = (int)(max_len - 1); k >= 0; k--) {
if (!r_is_at_infinity) {
if (!EC_POINT_dbl(group, r, r, ctx))
goto err;

View File

@ -131,7 +131,7 @@ static int pkey_ec_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
type = (dctx->md != NULL) ? EVP_MD_get_type(dctx->md) : NID_sha1;
ret = ECDSA_sign(type, tbs, tbslen, sig, &sltmp, ec);
ret = ECDSA_sign(type, tbs, (int)tbslen, sig, &sltmp, ec);
if (ret <= 0)
return ret;
@ -157,7 +157,7 @@ static int pkey_ec_verify(EVP_PKEY_CTX *ctx,
else
type = NID_sha1;
ret = ECDSA_verify(type, tbs, tbslen, sig, siglen, ec);
ret = ECDSA_verify(type, tbs, (int)tbslen, sig, (int)siglen, ec);
return ret;
}
@ -334,7 +334,7 @@ static int pkey_ec_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
return 1;
case EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN:
*(int *)p2 = dctx->kdf_outlen;
*(int *)p2 = (int)dctx->kdf_outlen;
return 1;
case EVP_PKEY_CTRL_EC_KDF_UKM:
@ -348,7 +348,7 @@ static int pkey_ec_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
case EVP_PKEY_CTRL_GET_EC_KDF_UKM:
*(unsigned char **)p2 = dctx->kdf_ukm;
return dctx->kdf_ukmlen;
return (int)dctx->kdf_ukmlen;
case EVP_PKEY_CTRL_MD:
if (EVP_MD_get_type((const EVP_MD *)p2) != NID_sha1 &&

View File

@ -279,7 +279,7 @@ int ossl_ec_GFp_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
int y_bit;
BN_CTX *new_ctx = NULL;
BIGNUM *x, *y;
size_t field_len, enc_len;
int field_len, enc_len;
int ret = 0;
if (len == 0) {
@ -314,7 +314,7 @@ int ossl_ec_GFp_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
(form ==
POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2 * field_len;
if (len != enc_len) {
if (len != (size_t)enc_len) {
ERR_raise(ERR_LIB_EC, EC_R_INVALID_ENCODING);
return 0;
}

Some files were not shown because too many files have changed in this diff Show More