diff options
Diffstat (limited to 'src/lib/libcrypto/rsa/rsa_sign.c')
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_sign.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c index 2a440901de..8a1e642183 100644 --- a/src/lib/libcrypto/rsa/rsa_sign.c +++ b/src/lib/libcrypto/rsa/rsa_sign.c | |||
@@ -62,7 +62,6 @@ | |||
62 | #include <openssl/rsa.h> | 62 | #include <openssl/rsa.h> |
63 | #include <openssl/objects.h> | 63 | #include <openssl/objects.h> |
64 | #include <openssl/x509.h> | 64 | #include <openssl/x509.h> |
65 | #include <openssl/engine.h> | ||
66 | 65 | ||
67 | /* Size of an SSL signature: MD5+SHA1 */ | 66 | /* Size of an SSL signature: MD5+SHA1 */ |
68 | #define SSL_SIG_LENGTH 36 | 67 | #define SSL_SIG_LENGTH 36 |
@@ -77,10 +76,11 @@ int RSA_sign(int type, const unsigned char *m, unsigned int m_len, | |||
77 | const unsigned char *s = NULL; | 76 | const unsigned char *s = NULL; |
78 | X509_ALGOR algor; | 77 | X509_ALGOR algor; |
79 | ASN1_OCTET_STRING digest; | 78 | ASN1_OCTET_STRING digest; |
80 | if((rsa->flags & RSA_FLAG_SIGN_VER) | 79 | if((rsa->flags & RSA_FLAG_SIGN_VER) && rsa->meth->rsa_sign) |
81 | && ENGINE_get_RSA(rsa->engine)->rsa_sign) | 80 | { |
82 | return ENGINE_get_RSA(rsa->engine)->rsa_sign(type, | 81 | return rsa->meth->rsa_sign(type, m, m_len, |
83 | m, m_len, sigret, siglen, rsa); | 82 | sigret, siglen, rsa); |
83 | } | ||
84 | /* Special case: SSL signature, just check the length */ | 84 | /* Special case: SSL signature, just check the length */ |
85 | if(type == NID_md5_sha1) { | 85 | if(type == NID_md5_sha1) { |
86 | if(m_len != SSL_SIG_LENGTH) { | 86 | if(m_len != SSL_SIG_LENGTH) { |
@@ -113,7 +113,7 @@ int RSA_sign(int type, const unsigned char *m, unsigned int m_len, | |||
113 | i=i2d_X509_SIG(&sig,NULL); | 113 | i=i2d_X509_SIG(&sig,NULL); |
114 | } | 114 | } |
115 | j=RSA_size(rsa); | 115 | j=RSA_size(rsa); |
116 | if ((i-RSA_PKCS1_PADDING) > j) | 116 | if (i > (j-RSA_PKCS1_PADDING_SIZE)) |
117 | { | 117 | { |
118 | RSAerr(RSA_F_RSA_SIGN,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY); | 118 | RSAerr(RSA_F_RSA_SIGN,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY); |
119 | return(0); | 119 | return(0); |
@@ -136,7 +136,7 @@ int RSA_sign(int type, const unsigned char *m, unsigned int m_len, | |||
136 | *siglen=i; | 136 | *siglen=i; |
137 | 137 | ||
138 | if(type != NID_md5_sha1) { | 138 | if(type != NID_md5_sha1) { |
139 | memset(tmps,0,(unsigned int)j+1); | 139 | OPENSSL_cleanse(tmps,(unsigned int)j+1); |
140 | OPENSSL_free(tmps); | 140 | OPENSSL_free(tmps); |
141 | } | 141 | } |
142 | return(ret); | 142 | return(ret); |
@@ -155,10 +155,11 @@ int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len, | |||
155 | return(0); | 155 | return(0); |
156 | } | 156 | } |
157 | 157 | ||
158 | if((rsa->flags & RSA_FLAG_SIGN_VER) | 158 | if((rsa->flags & RSA_FLAG_SIGN_VER) && rsa->meth->rsa_verify) |
159 | && ENGINE_get_RSA(rsa->engine)->rsa_verify) | 159 | { |
160 | return ENGINE_get_RSA(rsa->engine)->rsa_verify(dtype, | 160 | return rsa->meth->rsa_verify(dtype, m, m_len, |
161 | m, m_len, sigbuf, siglen, rsa); | 161 | sigbuf, siglen, rsa); |
162 | } | ||
162 | 163 | ||
163 | s=(unsigned char *)OPENSSL_malloc((unsigned int)siglen); | 164 | s=(unsigned char *)OPENSSL_malloc((unsigned int)siglen); |
164 | if (s == NULL) | 165 | if (s == NULL) |
@@ -221,7 +222,7 @@ int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len, | |||
221 | } | 222 | } |
222 | err: | 223 | err: |
223 | if (sig != NULL) X509_SIG_free(sig); | 224 | if (sig != NULL) X509_SIG_free(sig); |
224 | memset(s,0,(unsigned int)siglen); | 225 | OPENSSL_cleanse(s,(unsigned int)siglen); |
225 | OPENSSL_free(s); | 226 | OPENSSL_free(s); |
226 | return(ret); | 227 | return(ret); |
227 | } | 228 | } |