diff options
| author | beck <> | 2002-05-15 02:29:21 +0000 |
|---|---|---|
| committer | beck <> | 2002-05-15 02:29:21 +0000 |
| commit | b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9 (patch) | |
| tree | fa27cf82a1250b64ed3bf5f4a18c7354d470bbcc /src/lib/libcrypto/rsa/rsa_sign.c | |
| parent | e471e1ea98d673597b182ea85f29e30c97cd08b5 (diff) | |
| download | openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.gz openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.bz2 openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.zip | |
OpenSSL 0.9.7 stable 2002 05 08 merge
Diffstat (limited to 'src/lib/libcrypto/rsa/rsa_sign.c')
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa_sign.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c index cf00876292..2a440901de 100644 --- a/src/lib/libcrypto/rsa/rsa_sign.c +++ b/src/lib/libcrypto/rsa/rsa_sign.c | |||
| @@ -67,16 +67,18 @@ | |||
| 67 | /* Size of an SSL signature: MD5+SHA1 */ | 67 | /* Size of an SSL signature: MD5+SHA1 */ |
| 68 | #define SSL_SIG_LENGTH 36 | 68 | #define SSL_SIG_LENGTH 36 |
| 69 | 69 | ||
| 70 | int RSA_sign(int type, unsigned char *m, unsigned int m_len, | 70 | int RSA_sign(int type, const unsigned char *m, unsigned int m_len, |
| 71 | unsigned char *sigret, unsigned int *siglen, RSA *rsa) | 71 | unsigned char *sigret, unsigned int *siglen, RSA *rsa) |
| 72 | { | 72 | { |
| 73 | X509_SIG sig; | 73 | X509_SIG sig; |
| 74 | ASN1_TYPE parameter; | 74 | ASN1_TYPE parameter; |
| 75 | int i,j,ret=1; | 75 | int i,j,ret=1; |
| 76 | unsigned char *p,*s = NULL; | 76 | unsigned char *p, *tmps = NULL; |
| 77 | const unsigned char *s = NULL; | ||
| 77 | X509_ALGOR algor; | 78 | X509_ALGOR algor; |
| 78 | ASN1_OCTET_STRING digest; | 79 | ASN1_OCTET_STRING digest; |
| 79 | if(rsa->flags & RSA_FLAG_SIGN_VER) | 80 | if((rsa->flags & RSA_FLAG_SIGN_VER) |
| 81 | && ENGINE_get_RSA(rsa->engine)->rsa_sign) | ||
| 80 | return ENGINE_get_RSA(rsa->engine)->rsa_sign(type, | 82 | return ENGINE_get_RSA(rsa->engine)->rsa_sign(type, |
| 81 | m, m_len, sigret, siglen, rsa); | 83 | m, m_len, sigret, siglen, rsa); |
| 82 | /* Special case: SSL signature, just check the length */ | 84 | /* Special case: SSL signature, just check the length */ |
| @@ -105,7 +107,7 @@ int RSA_sign(int type, unsigned char *m, unsigned int m_len, | |||
| 105 | sig.algor->parameter= ¶meter; | 107 | sig.algor->parameter= ¶meter; |
| 106 | 108 | ||
| 107 | sig.digest= &digest; | 109 | sig.digest= &digest; |
| 108 | sig.digest->data=m; | 110 | sig.digest->data=(unsigned char *)m; /* TMP UGLY CAST */ |
| 109 | sig.digest->length=m_len; | 111 | sig.digest->length=m_len; |
| 110 | 112 | ||
| 111 | i=i2d_X509_SIG(&sig,NULL); | 113 | i=i2d_X509_SIG(&sig,NULL); |
| @@ -117,14 +119,15 @@ int RSA_sign(int type, unsigned char *m, unsigned int m_len, | |||
| 117 | return(0); | 119 | return(0); |
| 118 | } | 120 | } |
| 119 | if(type != NID_md5_sha1) { | 121 | if(type != NID_md5_sha1) { |
| 120 | s=(unsigned char *)OPENSSL_malloc((unsigned int)j+1); | 122 | tmps=(unsigned char *)OPENSSL_malloc((unsigned int)j+1); |
| 121 | if (s == NULL) | 123 | if (tmps == NULL) |
| 122 | { | 124 | { |
| 123 | RSAerr(RSA_F_RSA_SIGN,ERR_R_MALLOC_FAILURE); | 125 | RSAerr(RSA_F_RSA_SIGN,ERR_R_MALLOC_FAILURE); |
| 124 | return(0); | 126 | return(0); |
| 125 | } | 127 | } |
| 126 | p=s; | 128 | p=tmps; |
| 127 | i2d_X509_SIG(&sig,&p); | 129 | i2d_X509_SIG(&sig,&p); |
| 130 | s=tmps; | ||
| 128 | } | 131 | } |
| 129 | i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING); | 132 | i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING); |
| 130 | if (i <= 0) | 133 | if (i <= 0) |
| @@ -133,13 +136,13 @@ int RSA_sign(int type, unsigned char *m, unsigned int m_len, | |||
| 133 | *siglen=i; | 136 | *siglen=i; |
| 134 | 137 | ||
| 135 | if(type != NID_md5_sha1) { | 138 | if(type != NID_md5_sha1) { |
| 136 | memset(s,0,(unsigned int)j+1); | 139 | memset(tmps,0,(unsigned int)j+1); |
| 137 | OPENSSL_free(s); | 140 | OPENSSL_free(tmps); |
| 138 | } | 141 | } |
| 139 | return(ret); | 142 | return(ret); |
| 140 | } | 143 | } |
| 141 | 144 | ||
| 142 | int RSA_verify(int dtype, unsigned char *m, unsigned int m_len, | 145 | int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len, |
| 143 | unsigned char *sigbuf, unsigned int siglen, RSA *rsa) | 146 | unsigned char *sigbuf, unsigned int siglen, RSA *rsa) |
| 144 | { | 147 | { |
| 145 | int i,ret=0,sigtype; | 148 | int i,ret=0,sigtype; |
| @@ -152,7 +155,8 @@ int RSA_verify(int dtype, unsigned char *m, unsigned int m_len, | |||
| 152 | return(0); | 155 | return(0); |
| 153 | } | 156 | } |
| 154 | 157 | ||
| 155 | if(rsa->flags & RSA_FLAG_SIGN_VER) | 158 | if((rsa->flags & RSA_FLAG_SIGN_VER) |
| 159 | && ENGINE_get_RSA(rsa->engine)->rsa_verify) | ||
| 156 | return ENGINE_get_RSA(rsa->engine)->rsa_verify(dtype, | 160 | return ENGINE_get_RSA(rsa->engine)->rsa_verify(dtype, |
| 157 | m, m_len, sigbuf, siglen, rsa); | 161 | m, m_len, sigbuf, siglen, rsa); |
| 158 | 162 | ||
| @@ -196,9 +200,9 @@ int RSA_verify(int dtype, unsigned char *m, unsigned int m_len, | |||
| 196 | (sigtype == NID_md2WithRSAEncryption))) | 200 | (sigtype == NID_md2WithRSAEncryption))) |
| 197 | { | 201 | { |
| 198 | /* ok, we will let it through */ | 202 | /* ok, we will let it through */ |
| 199 | #if !defined(NO_STDIO) && !defined(WIN16) | 203 | #if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) |
| 200 | fprintf(stderr,"signature has problems, re-make with post SSLeay045\n"); | 204 | fprintf(stderr,"signature has problems, re-make with post SSLeay045\n"); |
| 201 | #endif | 205 | #endif |
| 202 | } | 206 | } |
| 203 | else | 207 | else |
| 204 | { | 208 | { |
