diff options
Diffstat (limited to 'src/lib/libcrypto/rsa/rsa_pk1.c')
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_pk1.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_pk1.c b/src/lib/libcrypto/rsa/rsa_pk1.c index f0ae51f234..48a32bc264 100644 --- a/src/lib/libcrypto/rsa/rsa_pk1.c +++ b/src/lib/libcrypto/rsa/rsa_pk1.c | |||
@@ -79,7 +79,7 @@ int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen, | |||
79 | *(p++)=0; | 79 | *(p++)=0; |
80 | *(p++)=1; /* Private Key BT (Block Type) */ | 80 | *(p++)=1; /* Private Key BT (Block Type) */ |
81 | 81 | ||
82 | /* padd out with 0xff data */ | 82 | /* pad out with 0xff data */ |
83 | j=tlen-3-flen; | 83 | j=tlen-3-flen; |
84 | memset(p,0xff,j); | 84 | memset(p,0xff,j); |
85 | p+=j; | 85 | p+=j; |
@@ -130,6 +130,11 @@ int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen, | |||
130 | } | 130 | } |
131 | i++; /* Skip over the '\0' */ | 131 | i++; /* Skip over the '\0' */ |
132 | j-=i; | 132 | j-=i; |
133 | if (j > tlen) | ||
134 | { | ||
135 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_DATA_TOO_LARGE); | ||
136 | return(-1); | ||
137 | } | ||
133 | memcpy(to,p,(unsigned int)j); | 138 | memcpy(to,p,(unsigned int)j); |
134 | 139 | ||
135 | return(j); | 140 | return(j); |
@@ -155,12 +160,14 @@ int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen, | |||
155 | /* pad out with non-zero random data */ | 160 | /* pad out with non-zero random data */ |
156 | j=tlen-3-flen; | 161 | j=tlen-3-flen; |
157 | 162 | ||
158 | RAND_bytes(p,j); | 163 | if (RAND_bytes(p,j) <= 0) |
164 | return(0); | ||
159 | for (i=0; i<j; i++) | 165 | for (i=0; i<j; i++) |
160 | { | 166 | { |
161 | if (*p == '\0') | 167 | if (*p == '\0') |
162 | do { | 168 | do { |
163 | RAND_bytes(p,1); | 169 | if (RAND_bytes(p,1) <= 0) |
170 | return(0); | ||
164 | } while (*p == '\0'); | 171 | } while (*p == '\0'); |
165 | p++; | 172 | p++; |
166 | } | 173 | } |
@@ -205,6 +212,11 @@ int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen, | |||
205 | } | 212 | } |
206 | i++; /* Skip over the '\0' */ | 213 | i++; /* Skip over the '\0' */ |
207 | j-=i; | 214 | j-=i; |
215 | if (j > tlen) | ||
216 | { | ||
217 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_DATA_TOO_LARGE); | ||
218 | return(-1); | ||
219 | } | ||
208 | memcpy(to,p,(unsigned int)j); | 220 | memcpy(to,p,(unsigned int)j); |
209 | 221 | ||
210 | return(j); | 222 | return(j); |