diff options
author | miod <> | 2014-07-09 08:20:08 +0000 |
---|---|---|
committer | miod <> | 2014-07-09 08:20:08 +0000 |
commit | 8cbe58f0d357b14b0ce292d336469d0554a567bc (patch) | |
tree | 07872a7ef59da8cea3b3b4a101fa3580e4d658c0 /src/lib/libcrypto/rsa/rsa_ssl.c | |
parent | bc1209e388500a20f5e75cab35d1b543ce0bbe74 (diff) | |
download | openbsd-8cbe58f0d357b14b0ce292d336469d0554a567bc.tar.gz openbsd-8cbe58f0d357b14b0ce292d336469d0554a567bc.tar.bz2 openbsd-8cbe58f0d357b14b0ce292d336469d0554a567bc.zip |
KNF
Diffstat (limited to 'src/lib/libcrypto/rsa/rsa_ssl.c')
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_ssl.c | 137 |
1 files changed, 68 insertions, 69 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_ssl.c b/src/lib/libcrypto/rsa/rsa_ssl.c index 3f4ec95a6e..c6ab71c674 100644 --- a/src/lib/libcrypto/rsa/rsa_ssl.c +++ b/src/lib/libcrypto/rsa/rsa_ssl.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rsa_ssl.c,v 1.7 2014/06/12 15:49:30 deraadt Exp $ */ | 1 | /* $OpenBSD: rsa_ssl.c,v 1.8 2014/07/09 08:20:08 miod Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -62,93 +62,92 @@ | |||
62 | #include <openssl/rsa.h> | 62 | #include <openssl/rsa.h> |
63 | #include <openssl/rand.h> | 63 | #include <openssl/rand.h> |
64 | 64 | ||
65 | int RSA_padding_add_SSLv23(unsigned char *to, int tlen, | 65 | int |
66 | const unsigned char *from, int flen) | 66 | RSA_padding_add_SSLv23(unsigned char *to, int tlen, const unsigned char *from, |
67 | { | 67 | int flen) |
68 | { | ||
68 | int i,j; | 69 | int i,j; |
69 | unsigned char *p; | 70 | unsigned char *p; |
70 | 71 | ||
71 | if (flen > (tlen-11)) | 72 | if (flen > tlen - 11) { |
72 | { | 73 | RSAerr(RSA_F_RSA_PADDING_ADD_SSLV23, |
73 | RSAerr(RSA_F_RSA_PADDING_ADD_SSLV23,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | 74 | RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); |
74 | return(0); | 75 | return 0; |
75 | } | 76 | } |
76 | 77 | ||
77 | p=(unsigned char *)to; | 78 | p = (unsigned char *)to; |
78 | 79 | ||
79 | *(p++)=0; | 80 | *(p++) = 0; |
80 | *(p++)=2; /* Public Key BT (Block Type) */ | 81 | *(p++) = 2; /* Public Key BT (Block Type) */ |
81 | 82 | ||
82 | /* pad out with non-zero random data */ | 83 | /* pad out with non-zero random data */ |
83 | j=tlen-3-8-flen; | 84 | j = tlen - 3 - 8 - flen; |
84 | 85 | ||
85 | if (RAND_bytes(p,j) <= 0) | 86 | if (RAND_bytes(p, j) <= 0) |
86 | return(0); | 87 | return 0; |
87 | for (i=0; i<j; i++) | 88 | for (i = 0; i < j; i++) { |
88 | { | ||
89 | if (*p == '\0') | 89 | if (*p == '\0') |
90 | do { | 90 | do { |
91 | if (RAND_bytes(p,1) <= 0) | 91 | if (RAND_bytes(p, 1) <= 0) |
92 | return(0); | 92 | return 0; |
93 | } while (*p == '\0'); | 93 | } while (*p == '\0'); |
94 | p++; | 94 | p++; |
95 | } | 95 | } |
96 | 96 | ||
97 | memset(p,3,8); | 97 | memset(p, 3, 8); |
98 | p+=8; | 98 | p += 8; |
99 | *(p++)='\0'; | 99 | *(p++) = '\0'; |
100 | 100 | ||
101 | memcpy(p,from,(unsigned int)flen); | 101 | memcpy(p, from, (unsigned int)flen); |
102 | return(1); | 102 | return 1; |
103 | } | 103 | } |
104 | 104 | ||
105 | int RSA_padding_check_SSLv23(unsigned char *to, int tlen, | 105 | int |
106 | const unsigned char *from, int flen, int num) | 106 | RSA_padding_check_SSLv23(unsigned char *to, int tlen, const unsigned char *from, |
107 | { | 107 | int flen, int num) |
108 | int i,j,k; | 108 | { |
109 | int i, j, k; | ||
109 | const unsigned char *p; | 110 | const unsigned char *p; |
110 | 111 | ||
111 | p=from; | 112 | p = from; |
112 | if (flen < 10) | 113 | if (flen < 10) { |
113 | { | 114 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSA_R_DATA_TOO_SMALL); |
114 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_DATA_TOO_SMALL); | 115 | return -1; |
115 | return(-1); | 116 | } |
116 | } | 117 | if (num != flen + 1 || *(p++) != 02) { |
117 | if ((num != (flen+1)) || (*(p++) != 02)) | 118 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, |
118 | { | 119 | RSA_R_BLOCK_TYPE_IS_NOT_02); |
119 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_BLOCK_TYPE_IS_NOT_02); | 120 | return -1; |
120 | return(-1); | 121 | } |
121 | } | ||
122 | 122 | ||
123 | /* scan over padding data */ | 123 | /* scan over padding data */ |
124 | j=flen-1; /* one for type */ | 124 | j = flen - 1; /* one for type */ |
125 | for (i=0; i<j; i++) | 125 | for (i = 0; i < j; i++) |
126 | if (*(p++) == 0) break; | 126 | if (*(p++) == 0) |
127 | break; | ||
127 | 128 | ||
128 | if ((i == j) || (i < 8)) | 129 | if (i == j || i < 8) { |
129 | { | 130 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, |
130 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_NULL_BEFORE_BLOCK_MISSING); | 131 | RSA_R_NULL_BEFORE_BLOCK_MISSING); |
131 | return(-1); | 132 | return -1; |
132 | } | 133 | } |
133 | for (k = -9; k<-1; k++) | 134 | for (k = -9; k < -1; k++) { |
134 | { | 135 | if (p[k] != 0x03) |
135 | if (p[k] != 0x03) break; | 136 | break; |
136 | } | 137 | } |
137 | if (k == -1) | 138 | if (k == -1) { |
138 | { | 139 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, |
139 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_SSLV3_ROLLBACK_ATTACK); | 140 | RSA_R_SSLV3_ROLLBACK_ATTACK); |
140 | return(-1); | 141 | return -1; |
141 | } | 142 | } |
142 | 143 | ||
143 | i++; /* Skip over the '\0' */ | 144 | i++; /* Skip over the '\0' */ |
144 | j-=i; | 145 | j -= i; |
145 | if (j > tlen) | 146 | if (j > tlen) { |
146 | { | 147 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSA_R_DATA_TOO_LARGE); |
147 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_DATA_TOO_LARGE); | 148 | return -1; |
148 | return(-1); | ||
149 | } | ||
150 | memcpy(to,p,(unsigned int)j); | ||
151 | |||
152 | return(j); | ||
153 | } | 149 | } |
150 | memcpy(to, p, (unsigned int)j); | ||
154 | 151 | ||
152 | return j; | ||
153 | } | ||