提交 8686c474 编写于 作者: P Paul Yang 提交者: Matt Caswell

Fix coding style in crypto/rsa directory

this part contains only the return (x) fix.
Reviewed-by: NRichard Levitte <levitte@openssl.org>
Reviewed-by: NMatt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4223)
上级 b5fe5dfb
/* /*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -17,41 +17,41 @@ ...@@ -17,41 +17,41 @@
int RSA_bits(const RSA *r) int RSA_bits(const RSA *r)
{ {
return (BN_num_bits(r->n)); return BN_num_bits(r->n);
} }
int RSA_size(const RSA *r) int RSA_size(const RSA *r)
{ {
return (BN_num_bytes(r->n)); return BN_num_bytes(r->n);
} }
int RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to, int RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to,
RSA *rsa, int padding) RSA *rsa, int padding)
{ {
return (rsa->meth->rsa_pub_enc(flen, from, to, rsa, padding)); return rsa->meth->rsa_pub_enc(flen, from, to, rsa, padding);
} }
int RSA_private_encrypt(int flen, const unsigned char *from, int RSA_private_encrypt(int flen, const unsigned char *from,
unsigned char *to, RSA *rsa, int padding) unsigned char *to, RSA *rsa, int padding)
{ {
return (rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding)); return rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding);
} }
int RSA_private_decrypt(int flen, const unsigned char *from, int RSA_private_decrypt(int flen, const unsigned char *from,
unsigned char *to, RSA *rsa, int padding) unsigned char *to, RSA *rsa, int padding)
{ {
return (rsa->meth->rsa_priv_dec(flen, from, to, rsa, padding)); return rsa->meth->rsa_priv_dec(flen, from, to, rsa, padding);
} }
int RSA_public_decrypt(int flen, const unsigned char *from, unsigned char *to, int RSA_public_decrypt(int flen, const unsigned char *from, unsigned char *to,
RSA *rsa, int padding) RSA *rsa, int padding)
{ {
return (rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding)); return rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding);
} }
int RSA_flags(const RSA *r) int RSA_flags(const RSA *r)
{ {
return ((r == NULL) ? 0 : r->meth->flags); return r == NULL ? 0 : r->meth->flags;
} }
void RSA_blinding_off(RSA *rsa) void RSA_blinding_off(RSA *rsa)
...@@ -77,7 +77,7 @@ int RSA_blinding_on(RSA *rsa, BN_CTX *ctx) ...@@ -77,7 +77,7 @@ int RSA_blinding_on(RSA *rsa, BN_CTX *ctx)
rsa->flags &= ~RSA_FLAG_NO_BLINDING; rsa->flags &= ~RSA_FLAG_NO_BLINDING;
ret = 1; ret = 1;
err: err:
return (ret); return ret;
} }
static BIGNUM *rsa_get_public_exp(const BIGNUM *d, const BIGNUM *p, static BIGNUM *rsa_get_public_exp(const BIGNUM *d, const BIGNUM *p,
......
/* /*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -148,17 +148,17 @@ int RSA_up_ref(RSA *r) ...@@ -148,17 +148,17 @@ int RSA_up_ref(RSA *r)
REF_PRINT_COUNT("RSA", r); REF_PRINT_COUNT("RSA", r);
REF_ASSERT_ISNT(i < 2); REF_ASSERT_ISNT(i < 2);
return ((i > 1) ? 1 : 0); return i > 1 ? 1 : 0;
} }
int RSA_set_ex_data(RSA *r, int idx, void *arg) int RSA_set_ex_data(RSA *r, int idx, void *arg)
{ {
return (CRYPTO_set_ex_data(&r->ex_data, idx, arg)); return CRYPTO_set_ex_data(&r->ex_data, idx, arg);
} }
void *RSA_get_ex_data(const RSA *r, int idx) void *RSA_get_ex_data(const RSA *r, int idx)
{ {
return (CRYPTO_get_ex_data(&r->ex_data, idx)); return CRYPTO_get_ex_data(&r->ex_data, idx);
} }
int RSA_security_bits(const RSA *rsa) int RSA_security_bits(const RSA *rsa)
......
/* /*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -16,16 +16,16 @@ int RSA_padding_add_none(unsigned char *to, int tlen, ...@@ -16,16 +16,16 @@ int RSA_padding_add_none(unsigned char *to, int tlen,
{ {
if (flen > tlen) { if (flen > tlen) {
RSAerr(RSA_F_RSA_PADDING_ADD_NONE, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); RSAerr(RSA_F_RSA_PADDING_ADD_NONE, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
return (0); return 0;
} }
if (flen < tlen) { if (flen < tlen) {
RSAerr(RSA_F_RSA_PADDING_ADD_NONE, RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE); RSAerr(RSA_F_RSA_PADDING_ADD_NONE, RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE);
return (0); return 0;
} }
memcpy(to, from, (unsigned int)flen); memcpy(to, from, (unsigned int)flen);
return (1); return 1;
} }
int RSA_padding_check_none(unsigned char *to, int tlen, int RSA_padding_check_none(unsigned char *to, int tlen,
...@@ -34,10 +34,10 @@ int RSA_padding_check_none(unsigned char *to, int tlen, ...@@ -34,10 +34,10 @@ int RSA_padding_check_none(unsigned char *to, int tlen,
if (flen > tlen) { if (flen > tlen) {
RSAerr(RSA_F_RSA_PADDING_CHECK_NONE, RSA_R_DATA_TOO_LARGE); RSAerr(RSA_F_RSA_PADDING_CHECK_NONE, RSA_R_DATA_TOO_LARGE);
return (-1); return -1;
} }
memset(to, 0, tlen - flen); memset(to, 0, tlen - flen);
memcpy(to + tlen - flen, from, flen); memcpy(to + tlen - flen, from, flen);
return (tlen); return tlen;
} }
...@@ -155,7 +155,7 @@ static int rsa_ossl_public_encrypt(int flen, const unsigned char *from, ...@@ -155,7 +155,7 @@ static int rsa_ossl_public_encrypt(int flen, const unsigned char *from,
BN_CTX_end(ctx); BN_CTX_end(ctx);
BN_CTX_free(ctx); BN_CTX_free(ctx);
OPENSSL_clear_free(buf, num); OPENSSL_clear_free(buf, num);
return (r); return r;
} }
static BN_BLINDING *rsa_get_blinding(RSA *rsa, int *local, BN_CTX *ctx) static BN_BLINDING *rsa_get_blinding(RSA *rsa, int *local, BN_CTX *ctx)
...@@ -365,7 +365,7 @@ static int rsa_ossl_private_encrypt(int flen, const unsigned char *from, ...@@ -365,7 +365,7 @@ static int rsa_ossl_private_encrypt(int flen, const unsigned char *from,
BN_CTX_end(ctx); BN_CTX_end(ctx);
BN_CTX_free(ctx); BN_CTX_free(ctx);
OPENSSL_clear_free(buf, num); OPENSSL_clear_free(buf, num);
return (r); return r;
} }
static int rsa_ossl_private_decrypt(int flen, const unsigned char *from, static int rsa_ossl_private_decrypt(int flen, const unsigned char *from,
...@@ -496,7 +496,7 @@ static int rsa_ossl_private_decrypt(int flen, const unsigned char *from, ...@@ -496,7 +496,7 @@ static int rsa_ossl_private_decrypt(int flen, const unsigned char *from,
BN_CTX_end(ctx); BN_CTX_end(ctx);
BN_CTX_free(ctx); BN_CTX_free(ctx);
OPENSSL_clear_free(buf, num); OPENSSL_clear_free(buf, num);
return (r); return r;
} }
/* signature verification */ /* signature verification */
...@@ -595,7 +595,7 @@ static int rsa_ossl_public_decrypt(int flen, const unsigned char *from, ...@@ -595,7 +595,7 @@ static int rsa_ossl_public_decrypt(int flen, const unsigned char *from,
BN_CTX_end(ctx); BN_CTX_end(ctx);
BN_CTX_free(ctx); BN_CTX_free(ctx);
OPENSSL_clear_free(buf, num); OPENSSL_clear_free(buf, num);
return (r); return r;
} }
static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
...@@ -787,13 +787,13 @@ static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) ...@@ -787,13 +787,13 @@ static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
ret = 1; ret = 1;
err: err:
BN_CTX_end(ctx); BN_CTX_end(ctx);
return (ret); return ret;
} }
static int rsa_ossl_init(RSA *rsa) static int rsa_ossl_init(RSA *rsa)
{ {
rsa->flags |= RSA_FLAG_CACHE_PUBLIC | RSA_FLAG_CACHE_PRIVATE; rsa->flags |= RSA_FLAG_CACHE_PUBLIC | RSA_FLAG_CACHE_PRIVATE;
return (1); return 1;
} }
static int rsa_ossl_finish(RSA *rsa) static int rsa_ossl_finish(RSA *rsa)
...@@ -801,5 +801,5 @@ static int rsa_ossl_finish(RSA *rsa) ...@@ -801,5 +801,5 @@ static int rsa_ossl_finish(RSA *rsa)
BN_MONT_CTX_free(rsa->_method_mod_n); BN_MONT_CTX_free(rsa->_method_mod_n);
BN_MONT_CTX_free(rsa->_method_mod_p); BN_MONT_CTX_free(rsa->_method_mod_p);
BN_MONT_CTX_free(rsa->_method_mod_q); BN_MONT_CTX_free(rsa->_method_mod_q);
return (1); return 1;
} }
/* /*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -24,7 +24,7 @@ int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen, ...@@ -24,7 +24,7 @@ int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
if (flen > (tlen - RSA_PKCS1_PADDING_SIZE)) { if (flen > (tlen - RSA_PKCS1_PADDING_SIZE)) {
RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1, RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,
RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
return (0); return 0;
} }
p = (unsigned char *)to; p = (unsigned char *)to;
...@@ -38,7 +38,7 @@ int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen, ...@@ -38,7 +38,7 @@ int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
p += j; p += j;
*(p++) = '\0'; *(p++) = '\0';
memcpy(p, from, (unsigned int)flen); memcpy(p, from, (unsigned int)flen);
return (1); return 1;
} }
int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen, int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
...@@ -73,7 +73,7 @@ int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen, ...@@ -73,7 +73,7 @@ int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
if ((num != (flen + 1)) || (*(p++) != 0x01)) { if ((num != (flen + 1)) || (*(p++) != 0x01)) {
RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,
RSA_R_BLOCK_TYPE_IS_NOT_01); RSA_R_BLOCK_TYPE_IS_NOT_01);
return (-1); return -1;
} }
/* scan over padding data */ /* scan over padding data */
...@@ -86,7 +86,7 @@ int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen, ...@@ -86,7 +86,7 @@ int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
} else { } else {
RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,
RSA_R_BAD_FIXED_HEADER_DECRYPT); RSA_R_BAD_FIXED_HEADER_DECRYPT);
return (-1); return -1;
} }
} }
p++; p++;
...@@ -95,23 +95,23 @@ int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen, ...@@ -95,23 +95,23 @@ int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
if (i == j) { if (i == j) {
RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,
RSA_R_NULL_BEFORE_BLOCK_MISSING); RSA_R_NULL_BEFORE_BLOCK_MISSING);
return (-1); return -1;
} }
if (i < 8) { if (i < 8) {
RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,
RSA_R_BAD_PAD_BYTE_COUNT); RSA_R_BAD_PAD_BYTE_COUNT);
return (-1); return -1;
} }
i++; /* Skip over the '\0' */ i++; /* Skip over the '\0' */
j -= i; j -= i;
if (j > tlen) { if (j > tlen) {
RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, RSA_R_DATA_TOO_LARGE); RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, RSA_R_DATA_TOO_LARGE);
return (-1); return -1;
} }
memcpy(to, p, (unsigned int)j); memcpy(to, p, (unsigned int)j);
return (j); return j;
} }
int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen, int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
...@@ -123,7 +123,7 @@ int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen, ...@@ -123,7 +123,7 @@ int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
if (flen > (tlen - 11)) { if (flen > (tlen - 11)) {
RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2, RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,
RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
return (0); return 0;
} }
p = (unsigned char *)to; p = (unsigned char *)to;
...@@ -135,12 +135,12 @@ int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen, ...@@ -135,12 +135,12 @@ int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
j = tlen - 3 - flen; j = tlen - 3 - flen;
if (RAND_bytes(p, j) <= 0) if (RAND_bytes(p, j) <= 0)
return (0); return 0;
for (i = 0; i < j; i++) { for (i = 0; i < j; i++) {
if (*p == '\0') if (*p == '\0')
do { do {
if (RAND_bytes(p, 1) <= 0) if (RAND_bytes(p, 1) <= 0)
return (0); return 0;
} while (*p == '\0'); } while (*p == '\0');
p++; p++;
} }
...@@ -148,7 +148,7 @@ int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen, ...@@ -148,7 +148,7 @@ int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
*(p++) = '\0'; *(p++) = '\0';
memcpy(p, from, (unsigned int)flen); memcpy(p, from, (unsigned int)flen);
return (1); return 1;
} }
int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen, int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
......
/* /*
* Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 2006-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -20,12 +20,12 @@ int RSA_print_fp(FILE *fp, const RSA *x, int off) ...@@ -20,12 +20,12 @@ int RSA_print_fp(FILE *fp, const RSA *x, int off)
if ((b = BIO_new(BIO_s_file())) == NULL) { if ((b = BIO_new(BIO_s_file())) == NULL) {
RSAerr(RSA_F_RSA_PRINT_FP, ERR_R_BUF_LIB); RSAerr(RSA_F_RSA_PRINT_FP, ERR_R_BUF_LIB);
return (0); return 0;
} }
BIO_set_fp(b, fp, BIO_NOCLOSE); BIO_set_fp(b, fp, BIO_NOCLOSE);
ret = RSA_print(b, x, off); ret = RSA_print(b, x, off);
BIO_free(b); BIO_free(b);
return (ret); return ret;
} }
#endif #endif
......
/* /*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -32,12 +32,12 @@ int RSA_sign_ASN1_OCTET_STRING(int type, ...@@ -32,12 +32,12 @@ int RSA_sign_ASN1_OCTET_STRING(int type,
if (i > (j - RSA_PKCS1_PADDING_SIZE)) { if (i > (j - RSA_PKCS1_PADDING_SIZE)) {
RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING, RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,
RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY); RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
return (0); return 0;
} }
s = OPENSSL_malloc((unsigned int)j + 1); s = OPENSSL_malloc((unsigned int)j + 1);
if (s == NULL) { if (s == NULL) {
RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING, ERR_R_MALLOC_FAILURE); RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING, ERR_R_MALLOC_FAILURE);
return (0); return 0;
} }
p = s; p = s;
i2d_ASN1_OCTET_STRING(&sig, &p); i2d_ASN1_OCTET_STRING(&sig, &p);
...@@ -48,7 +48,7 @@ int RSA_sign_ASN1_OCTET_STRING(int type, ...@@ -48,7 +48,7 @@ int RSA_sign_ASN1_OCTET_STRING(int type,
*siglen = i; *siglen = i;
OPENSSL_clear_free(s, (unsigned int)j + 1); OPENSSL_clear_free(s, (unsigned int)j + 1);
return (ret); return ret;
} }
int RSA_verify_ASN1_OCTET_STRING(int dtype, int RSA_verify_ASN1_OCTET_STRING(int dtype,
...@@ -64,7 +64,7 @@ int RSA_verify_ASN1_OCTET_STRING(int dtype, ...@@ -64,7 +64,7 @@ int RSA_verify_ASN1_OCTET_STRING(int dtype,
if (siglen != (unsigned int)RSA_size(rsa)) { if (siglen != (unsigned int)RSA_size(rsa)) {
RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING, RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,
RSA_R_WRONG_SIGNATURE_LENGTH); RSA_R_WRONG_SIGNATURE_LENGTH);
return (0); return 0;
} }
s = OPENSSL_malloc((unsigned int)siglen); s = OPENSSL_malloc((unsigned int)siglen);
...@@ -90,5 +90,5 @@ int RSA_verify_ASN1_OCTET_STRING(int dtype, ...@@ -90,5 +90,5 @@ int RSA_verify_ASN1_OCTET_STRING(int dtype,
err: err:
ASN1_OCTET_STRING_free(sig); ASN1_OCTET_STRING_free(sig);
OPENSSL_clear_free(s, (unsigned int)siglen); OPENSSL_clear_free(s, (unsigned int)siglen);
return (ret); return ret;
} }
/* /*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -22,7 +22,7 @@ int RSA_padding_add_SSLv23(unsigned char *to, int tlen, ...@@ -22,7 +22,7 @@ int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
if (flen > (tlen - 11)) { if (flen > (tlen - 11)) {
RSAerr(RSA_F_RSA_PADDING_ADD_SSLV23, RSAerr(RSA_F_RSA_PADDING_ADD_SSLV23,
RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
return (0); return 0;
} }
p = (unsigned char *)to; p = (unsigned char *)to;
...@@ -34,12 +34,12 @@ int RSA_padding_add_SSLv23(unsigned char *to, int tlen, ...@@ -34,12 +34,12 @@ int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
j = tlen - 3 - 8 - flen; j = tlen - 3 - 8 - flen;
if (RAND_bytes(p, j) <= 0) if (RAND_bytes(p, j) <= 0)
return (0); return 0;
for (i = 0; i < j; i++) { for (i = 0; i < j; i++) {
if (*p == '\0') if (*p == '\0')
do { do {
if (RAND_bytes(p, 1) <= 0) if (RAND_bytes(p, 1) <= 0)
return (0); return 0;
} while (*p == '\0'); } while (*p == '\0');
p++; p++;
} }
...@@ -49,7 +49,7 @@ int RSA_padding_add_SSLv23(unsigned char *to, int tlen, ...@@ -49,7 +49,7 @@ int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
*(p++) = '\0'; *(p++) = '\0';
memcpy(p, from, (unsigned int)flen); memcpy(p, from, (unsigned int)flen);
return (1); return 1;
} }
int RSA_padding_check_SSLv23(unsigned char *to, int tlen, int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
...@@ -61,11 +61,11 @@ int RSA_padding_check_SSLv23(unsigned char *to, int tlen, ...@@ -61,11 +61,11 @@ int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
p = from; p = from;
if (flen < 10) { if (flen < 10) {
RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSA_R_DATA_TOO_SMALL); RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSA_R_DATA_TOO_SMALL);
return (-1); return -1;
} }
if ((num != (flen + 1)) || (*(p++) != 02)) { if ((num != (flen + 1)) || (*(p++) != 02)) {
RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSA_R_BLOCK_TYPE_IS_NOT_02); RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSA_R_BLOCK_TYPE_IS_NOT_02);
return (-1); return -1;
} }
/* scan over padding data */ /* scan over padding data */
...@@ -77,7 +77,7 @@ int RSA_padding_check_SSLv23(unsigned char *to, int tlen, ...@@ -77,7 +77,7 @@ int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
if ((i == j) || (i < 8)) { if ((i == j) || (i < 8)) {
RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,
RSA_R_NULL_BEFORE_BLOCK_MISSING); RSA_R_NULL_BEFORE_BLOCK_MISSING);
return (-1); return -1;
} }
for (k = -9; k < -1; k++) { for (k = -9; k < -1; k++) {
if (p[k] != 0x03) if (p[k] != 0x03)
...@@ -85,16 +85,16 @@ int RSA_padding_check_SSLv23(unsigned char *to, int tlen, ...@@ -85,16 +85,16 @@ int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
} }
if (k == -1) { if (k == -1) {
RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSA_R_SSLV3_ROLLBACK_ATTACK); RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSA_R_SSLV3_ROLLBACK_ATTACK);
return (-1); return -1;
} }
i++; /* Skip over the '\0' */ i++; /* Skip over the '\0' */
j -= i; j -= i;
if (j > tlen) { if (j > tlen) {
RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSA_R_DATA_TOO_LARGE); RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSA_R_DATA_TOO_LARGE);
return (-1); return -1;
} }
memcpy(to, p, (unsigned int)j); memcpy(to, p, (unsigned int)j);
return (j); return j;
} }
/* /*
* Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved. * Copyright 2005-2017 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
...@@ -47,7 +47,7 @@ int RSA_padding_add_X931(unsigned char *to, int tlen, ...@@ -47,7 +47,7 @@ int RSA_padding_add_X931(unsigned char *to, int tlen,
memcpy(p, from, (unsigned int)flen); memcpy(p, from, (unsigned int)flen);
p += flen; p += flen;
*p = 0xCC; *p = 0xCC;
return (1); return 1;
} }
int RSA_padding_check_X931(unsigned char *to, int tlen, int RSA_padding_check_X931(unsigned char *to, int tlen,
...@@ -91,7 +91,7 @@ int RSA_padding_check_X931(unsigned char *to, int tlen, ...@@ -91,7 +91,7 @@ int RSA_padding_check_X931(unsigned char *to, int tlen,
memcpy(to, p, (unsigned int)j); memcpy(to, p, (unsigned int)j);
return (j); return j;
} }
/* Translate between X931 hash ids and NIDs */ /* Translate between X931 hash ids and NIDs */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册