diff options
author | markus <> | 2002-09-12 20:53:05 +0000 |
---|---|---|
committer | markus <> | 2002-09-12 20:53:05 +0000 |
commit | 31392c89d1135cf2a416f97295f6d21681b3fbc4 (patch) | |
tree | 09ce0b27981cae5a4625fa506a24d5c79fc8a13a | |
parent | 715a204e4615e4a70a466fcb383a9a57cad5e6b8 (diff) | |
download | openbsd-31392c89d1135cf2a416f97295f6d21681b3fbc4.tar.gz openbsd-31392c89d1135cf2a416f97295f6d21681b3fbc4.tar.bz2 openbsd-31392c89d1135cf2a416f97295f6d21681b3fbc4.zip |
import openssl-0.9.7-stable-SNAP-20020911 (without idea)
41 files changed, 1189 insertions, 331 deletions
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c index ed0bdfbde1..e0265f69d2 100644 --- a/src/lib/libcrypto/asn1/a_bitstr.c +++ b/src/lib/libcrypto/asn1/a_bitstr.c | |||
@@ -120,6 +120,12 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, unsigned char **pp, | |||
120 | unsigned char *p,*s; | 120 | unsigned char *p,*s; |
121 | int i; | 121 | int i; |
122 | 122 | ||
123 | if (len < 1) | ||
124 | { | ||
125 | i=ASN1_R_STRING_TOO_SHORT; | ||
126 | goto err; | ||
127 | } | ||
128 | |||
123 | if ((a == NULL) || ((*a) == NULL)) | 129 | if ((a == NULL) || ((*a) == NULL)) |
124 | { | 130 | { |
125 | if ((ret=M_ASN1_BIT_STRING_new()) == NULL) return(NULL); | 131 | if ((ret=M_ASN1_BIT_STRING_new()) == NULL) return(NULL); |
diff --git a/src/lib/libcrypto/asn1/a_strex.c b/src/lib/libcrypto/asn1/a_strex.c index 8dab29dca1..7ddb7662f1 100644 --- a/src/lib/libcrypto/asn1/a_strex.c +++ b/src/lib/libcrypto/asn1/a_strex.c | |||
@@ -544,7 +544,7 @@ int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in) | |||
544 | { | 544 | { |
545 | ASN1_STRING stmp, *str = &stmp; | 545 | ASN1_STRING stmp, *str = &stmp; |
546 | int mbflag, type, ret; | 546 | int mbflag, type, ret; |
547 | if(!*out || !in) return -1; | 547 | if(!in) return -1; |
548 | type = in->type; | 548 | type = in->type; |
549 | if((type < 0) || (type > 30)) return -1; | 549 | if((type < 0) || (type > 30)) return -1; |
550 | mbflag = tag2nbyte[type]; | 550 | mbflag = tag2nbyte[type]; |
@@ -553,6 +553,6 @@ int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in) | |||
553 | stmp.data = NULL; | 553 | stmp.data = NULL; |
554 | ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING); | 554 | ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING); |
555 | if(ret < 0) return ret; | 555 | if(ret < 0) return ret; |
556 | if(out) *out = stmp.data; | 556 | *out = stmp.data; |
557 | return stmp.length; | 557 | return stmp.length; |
558 | } | 558 | } |
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c index 422685a3b4..0638870ab7 100644 --- a/src/lib/libcrypto/asn1/asn1_lib.c +++ b/src/lib/libcrypto/asn1/asn1_lib.c | |||
@@ -57,6 +57,7 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <limits.h> | ||
60 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
61 | #include <openssl/asn1.h> | 62 | #include <openssl/asn1.h> |
62 | #include <openssl/asn1_mac.h> | 63 | #include <openssl/asn1_mac.h> |
@@ -124,7 +125,7 @@ int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass, | |||
124 | (int)(omax+ *pp)); | 125 | (int)(omax+ *pp)); |
125 | 126 | ||
126 | #endif | 127 | #endif |
127 | if (*plength > (omax - (*pp - p))) | 128 | if (*plength > (omax - (p - *pp))) |
128 | { | 129 | { |
129 | ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); | 130 | ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); |
130 | /* Set this so that even if things are not long enough | 131 | /* Set this so that even if things are not long enough |
@@ -141,7 +142,7 @@ err: | |||
141 | static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max) | 142 | static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max) |
142 | { | 143 | { |
143 | unsigned char *p= *pp; | 144 | unsigned char *p= *pp; |
144 | long ret=0; | 145 | unsigned long ret=0; |
145 | int i; | 146 | int i; |
146 | 147 | ||
147 | if (max-- < 1) return(0); | 148 | if (max-- < 1) return(0); |
@@ -170,10 +171,10 @@ static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max) | |||
170 | else | 171 | else |
171 | ret=i; | 172 | ret=i; |
172 | } | 173 | } |
173 | if (ret < 0) | 174 | if (ret > LONG_MAX) |
174 | return 0; | 175 | return 0; |
175 | *pp=p; | 176 | *pp=p; |
176 | *rl=ret; | 177 | *rl=(long)ret; |
177 | return(1); | 178 | return(1); |
178 | } | 179 | } |
179 | 180 | ||
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c index 848c29a2dd..739f272ecf 100644 --- a/src/lib/libcrypto/asn1/t_req.c +++ b/src/lib/libcrypto/asn1/t_req.c | |||
@@ -82,7 +82,7 @@ int X509_REQ_print_fp(FILE *fp, X509_REQ *x) | |||
82 | } | 82 | } |
83 | #endif | 83 | #endif |
84 | 84 | ||
85 | int X509_REQ_print(BIO *bp, X509_REQ *x) | 85 | int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long cflag) |
86 | { | 86 | { |
87 | unsigned long l; | 87 | unsigned long l; |
88 | int i; | 88 | int i; |
@@ -92,143 +92,185 @@ int X509_REQ_print(BIO *bp, X509_REQ *x) | |||
92 | STACK_OF(X509_ATTRIBUTE) *sk; | 92 | STACK_OF(X509_ATTRIBUTE) *sk; |
93 | STACK_OF(X509_EXTENSION) *exts; | 93 | STACK_OF(X509_EXTENSION) *exts; |
94 | char str[128]; | 94 | char str[128]; |
95 | char mlch = ' '; | ||
96 | int nmindent = 0; | ||
97 | |||
98 | if((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) { | ||
99 | mlch = '\n'; | ||
100 | nmindent = 12; | ||
101 | } | ||
102 | |||
103 | if(nmflags == X509_FLAG_COMPAT) | ||
104 | nmindent = 16; | ||
105 | |||
95 | 106 | ||
96 | ri=x->req_info; | 107 | ri=x->req_info; |
97 | sprintf(str,"Certificate Request:\n"); | 108 | if(!(cflag & X509_FLAG_NO_HEADER)) |
98 | if (BIO_puts(bp,str) <= 0) goto err; | ||
99 | sprintf(str,"%4sData:\n",""); | ||
100 | if (BIO_puts(bp,str) <= 0) goto err; | ||
101 | |||
102 | neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":""; | ||
103 | l=0; | ||
104 | for (i=0; i<ri->version->length; i++) | ||
105 | { l<<=8; l+=ri->version->data[i]; } | ||
106 | sprintf(str,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg,l); | ||
107 | if (BIO_puts(bp,str) <= 0) goto err; | ||
108 | sprintf(str,"%8sSubject: ",""); | ||
109 | if (BIO_puts(bp,str) <= 0) goto err; | ||
110 | |||
111 | X509_NAME_print(bp,ri->subject,16); | ||
112 | sprintf(str,"\n%8sSubject Public Key Info:\n",""); | ||
113 | if (BIO_puts(bp,str) <= 0) goto err; | ||
114 | i=OBJ_obj2nid(ri->pubkey->algor->algorithm); | ||
115 | sprintf(str,"%12sPublic Key Algorithm: %s\n","", | ||
116 | (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)); | ||
117 | if (BIO_puts(bp,str) <= 0) goto err; | ||
118 | |||
119 | pkey=X509_REQ_get_pubkey(x); | ||
120 | #ifndef OPENSSL_NO_RSA | ||
121 | if (pkey != NULL && pkey->type == EVP_PKEY_RSA) | ||
122 | { | 109 | { |
123 | BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","", | 110 | if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err; |
124 | BN_num_bits(pkey->pkey.rsa->n)); | 111 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; |
125 | RSA_print(bp,pkey->pkey.rsa,16); | ||
126 | } | 112 | } |
127 | else | 113 | if(!(cflag & X509_FLAG_NO_VERSION)) |
128 | #endif | ||
129 | #ifndef OPENSSL_NO_DSA | ||
130 | if (pkey != NULL && pkey->type == EVP_PKEY_DSA) | ||
131 | { | 114 | { |
132 | BIO_printf(bp,"%12sDSA Public Key:\n",""); | 115 | neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":""; |
133 | DSA_print(bp,pkey->pkey.dsa,16); | 116 | l=0; |
117 | for (i=0; i<ri->version->length; i++) | ||
118 | { l<<=8; l+=ri->version->data[i]; } | ||
119 | sprintf(str,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg,l); | ||
120 | if (BIO_puts(bp,str) <= 0) goto err; | ||
134 | } | 121 | } |
135 | else | 122 | if(!(cflag & X509_FLAG_NO_SUBJECT)) |
136 | #endif | 123 | { |
137 | BIO_printf(bp,"%12sUnknown Public Key:\n",""); | 124 | if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; |
125 | if (X509_NAME_print_ex(bp,ri->subject,nmindent, nmflags) < 0) goto err; | ||
126 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
127 | } | ||
128 | if(!(cflag & X509_FLAG_NO_PUBKEY)) | ||
129 | { | ||
130 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) | ||
131 | goto err; | ||
132 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) | ||
133 | goto err; | ||
134 | if (i2a_ASN1_OBJECT(bp, ri->pubkey->algor->algorithm) <= 0) | ||
135 | goto err; | ||
136 | if (BIO_puts(bp, "\n") <= 0) | ||
137 | goto err; | ||
138 | 138 | ||
139 | if (pkey != NULL) | 139 | pkey=X509_REQ_get_pubkey(x); |
140 | EVP_PKEY_free(pkey); | 140 | if (pkey == NULL) |
141 | { | ||
142 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); | ||
143 | ERR_print_errors(bp); | ||
144 | } | ||
145 | else | ||
146 | #ifndef OPENSSL_NO_RSA | ||
147 | if (pkey->type == EVP_PKEY_RSA) | ||
148 | { | ||
149 | BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","", | ||
150 | BN_num_bits(pkey->pkey.rsa->n)); | ||
151 | RSA_print(bp,pkey->pkey.rsa,16); | ||
152 | } | ||
153 | else | ||
154 | #endif | ||
155 | #ifndef OPENSSL_NO_DSA | ||
156 | if (pkey->type == EVP_PKEY_DSA) | ||
157 | { | ||
158 | BIO_printf(bp,"%12sDSA Public Key:\n",""); | ||
159 | DSA_print(bp,pkey->pkey.dsa,16); | ||
160 | } | ||
161 | else | ||
162 | #endif | ||
163 | BIO_printf(bp,"%12sUnknown Public Key:\n",""); | ||
141 | 164 | ||
142 | /* may not be */ | 165 | EVP_PKEY_free(pkey); |
143 | sprintf(str,"%8sAttributes:\n",""); | 166 | } |
144 | if (BIO_puts(bp,str) <= 0) goto err; | ||
145 | 167 | ||
146 | sk=x->req_info->attributes; | 168 | if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) |
147 | if (sk_X509_ATTRIBUTE_num(sk) == 0) | ||
148 | { | 169 | { |
149 | sprintf(str,"%12sa0:00\n",""); | 170 | /* may not be */ |
171 | sprintf(str,"%8sAttributes:\n",""); | ||
150 | if (BIO_puts(bp,str) <= 0) goto err; | 172 | if (BIO_puts(bp,str) <= 0) goto err; |
151 | } | 173 | |
152 | else | 174 | sk=x->req_info->attributes; |
153 | { | 175 | if (sk_X509_ATTRIBUTE_num(sk) == 0) |
154 | for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) | ||
155 | { | 176 | { |
156 | ASN1_TYPE *at; | 177 | sprintf(str,"%12sa0:00\n",""); |
157 | X509_ATTRIBUTE *a; | ||
158 | ASN1_BIT_STRING *bs=NULL; | ||
159 | ASN1_TYPE *t; | ||
160 | int j,type=0,count=1,ii=0; | ||
161 | |||
162 | a=sk_X509_ATTRIBUTE_value(sk,i); | ||
163 | if(X509_REQ_extension_nid(OBJ_obj2nid(a->object))) | ||
164 | continue; | ||
165 | sprintf(str,"%12s",""); | ||
166 | if (BIO_puts(bp,str) <= 0) goto err; | 178 | if (BIO_puts(bp,str) <= 0) goto err; |
167 | if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) | 179 | } |
180 | else | ||
168 | { | 181 | { |
169 | if (a->single) | 182 | for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) |
170 | { | 183 | { |
171 | t=a->value.single; | 184 | ASN1_TYPE *at; |
172 | type=t->type; | 185 | X509_ATTRIBUTE *a; |
173 | bs=t->value.bit_string; | 186 | ASN1_BIT_STRING *bs=NULL; |
174 | } | 187 | ASN1_TYPE *t; |
175 | else | 188 | int j,type=0,count=1,ii=0; |
189 | |||
190 | a=sk_X509_ATTRIBUTE_value(sk,i); | ||
191 | if(X509_REQ_extension_nid(OBJ_obj2nid(a->object))) | ||
192 | continue; | ||
193 | sprintf(str,"%12s",""); | ||
194 | if (BIO_puts(bp,str) <= 0) goto err; | ||
195 | if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) | ||
176 | { | 196 | { |
177 | ii=0; | 197 | if (a->single) |
178 | count=sk_ASN1_TYPE_num(a->value.set); | 198 | { |
199 | t=a->value.single; | ||
200 | type=t->type; | ||
201 | bs=t->value.bit_string; | ||
202 | } | ||
203 | else | ||
204 | { | ||
205 | ii=0; | ||
206 | count=sk_ASN1_TYPE_num(a->value.set); | ||
179 | get_next: | 207 | get_next: |
180 | at=sk_ASN1_TYPE_value(a->value.set,ii); | 208 | at=sk_ASN1_TYPE_value(a->value.set,ii); |
181 | type=at->type; | 209 | type=at->type; |
182 | bs=at->value.asn1_string; | 210 | bs=at->value.asn1_string; |
211 | } | ||
212 | } | ||
213 | for (j=25-j; j>0; j--) | ||
214 | if (BIO_write(bp," ",1) != 1) goto err; | ||
215 | if (BIO_puts(bp,":") <= 0) goto err; | ||
216 | if ( (type == V_ASN1_PRINTABLESTRING) || | ||
217 | (type == V_ASN1_T61STRING) || | ||
218 | (type == V_ASN1_IA5STRING)) | ||
219 | { | ||
220 | if (BIO_write(bp,(char *)bs->data,bs->length) | ||
221 | != bs->length) | ||
222 | goto err; | ||
223 | BIO_puts(bp,"\n"); | ||
224 | } | ||
225 | else | ||
226 | { | ||
227 | BIO_puts(bp,"unable to print attribute\n"); | ||
228 | } | ||
229 | if (++ii < count) goto get_next; | ||
183 | } | 230 | } |
184 | } | 231 | } |
185 | for (j=25-j; j>0; j--) | 232 | } |
186 | if (BIO_write(bp," ",1) != 1) goto err; | 233 | if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) |
187 | if (BIO_puts(bp,":") <= 0) goto err; | 234 | { |
188 | if ( (type == V_ASN1_PRINTABLESTRING) || | 235 | exts = X509_REQ_get_extensions(x); |
189 | (type == V_ASN1_T61STRING) || | 236 | if(exts) |
190 | (type == V_ASN1_IA5STRING)) | 237 | { |
238 | BIO_printf(bp,"%8sRequested Extensions:\n",""); | ||
239 | for (i=0; i<sk_X509_EXTENSION_num(exts); i++) | ||
191 | { | 240 | { |
192 | if (BIO_write(bp,(char *)bs->data,bs->length) | 241 | ASN1_OBJECT *obj; |
193 | != bs->length) | 242 | X509_EXTENSION *ex; |
243 | int j; | ||
244 | ex=sk_X509_EXTENSION_value(exts, i); | ||
245 | if (BIO_printf(bp,"%12s","") <= 0) goto err; | ||
246 | obj=X509_EXTENSION_get_object(ex); | ||
247 | i2a_ASN1_OBJECT(bp,obj); | ||
248 | j=X509_EXTENSION_get_critical(ex); | ||
249 | if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0) | ||
194 | goto err; | 250 | goto err; |
195 | BIO_puts(bp,"\n"); | 251 | if(!X509V3_EXT_print(bp, ex, 0, 16)) |
196 | } | 252 | { |
197 | else | 253 | BIO_printf(bp, "%16s", ""); |
198 | { | 254 | M_ASN1_OCTET_STRING_print(bp,ex->value); |
199 | BIO_puts(bp,"unable to print attribute\n"); | 255 | } |
256 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
200 | } | 257 | } |
201 | if (++ii < count) goto get_next; | 258 | sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); |
202 | } | 259 | } |
203 | } | 260 | } |
204 | 261 | ||
205 | exts = X509_REQ_get_extensions(x); | 262 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) |
206 | if(exts) { | 263 | { |
207 | BIO_printf(bp,"%8sRequested Extensions:\n",""); | 264 | if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err; |
208 | for (i=0; i<sk_X509_EXTENSION_num(exts); i++) { | ||
209 | ASN1_OBJECT *obj; | ||
210 | X509_EXTENSION *ex; | ||
211 | int j; | ||
212 | ex=sk_X509_EXTENSION_value(exts, i); | ||
213 | if (BIO_printf(bp,"%12s","") <= 0) goto err; | ||
214 | obj=X509_EXTENSION_get_object(ex); | ||
215 | i2a_ASN1_OBJECT(bp,obj); | ||
216 | j=X509_EXTENSION_get_critical(ex); | ||
217 | if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0) | ||
218 | goto err; | ||
219 | if(!X509V3_EXT_print(bp, ex, 0, 16)) { | ||
220 | BIO_printf(bp, "%16s", ""); | ||
221 | M_ASN1_OCTET_STRING_print(bp,ex->value); | ||
222 | } | ||
223 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
224 | } | 265 | } |
225 | sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); | ||
226 | } | ||
227 | |||
228 | if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err; | ||
229 | 266 | ||
230 | return(1); | 267 | return(1); |
231 | err: | 268 | err: |
232 | X509err(X509_F_X509_REQ_PRINT,ERR_R_BUF_LIB); | 269 | X509err(X509_F_X509_REQ_PRINT,ERR_R_BUF_LIB); |
233 | return(0); | 270 | return(0); |
234 | } | 271 | } |
272 | |||
273 | int X509_REQ_print(BIO *bp, X509_REQ *x) | ||
274 | { | ||
275 | return X509_REQ_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); | ||
276 | } | ||
diff --git a/src/lib/libcrypto/asn1/tasn_dec.c b/src/lib/libcrypto/asn1/tasn_dec.c index 0fc1f421e2..f87c08793a 100644 --- a/src/lib/libcrypto/asn1/tasn_dec.c +++ b/src/lib/libcrypto/asn1/tasn_dec.c | |||
@@ -913,10 +913,10 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *i | |||
913 | ctx->ptag = ptag; | 913 | ctx->ptag = ptag; |
914 | ctx->hdrlen = p - q; | 914 | ctx->hdrlen = p - q; |
915 | ctx->valid = 1; | 915 | ctx->valid = 1; |
916 | /* If definite length, length + header can't exceed total | 916 | /* If definite length, and no error, length + |
917 | * amount of data available. | 917 | * header can't exceed total amount of data available. |
918 | */ | 918 | */ |
919 | if(!(i & 1) && ((plen + ctx->hdrlen) > len)) { | 919 | if(!(i & 0x81) && ((plen + ctx->hdrlen) > len)) { |
920 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_TOO_LONG); | 920 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_TOO_LONG); |
921 | asn1_tlc_clear(ctx); | 921 | asn1_tlc_clear(ctx); |
922 | return 0; | 922 | return 0; |
diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c index 3ce1290772..80c9cb69db 100644 --- a/src/lib/libcrypto/bio/b_print.c +++ b/src/lib/libcrypto/bio/b_print.c | |||
@@ -109,7 +109,7 @@ | |||
109 | * o ... (for OpenSSL) | 109 | * o ... (for OpenSSL) |
110 | */ | 110 | */ |
111 | 111 | ||
112 | #if HAVE_LONG_DOUBLE | 112 | #ifdef HAVE_LONG_DOUBLE |
113 | #define LDOUBLE long double | 113 | #define LDOUBLE long double |
114 | #else | 114 | #else |
115 | #define LDOUBLE double | 115 | #define LDOUBLE double |
diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h index 1eaf879553..b40682f831 100644 --- a/src/lib/libcrypto/bn/bn.h +++ b/src/lib/libcrypto/bn/bn.h | |||
@@ -430,7 +430,7 @@ int BN_mod_mul_montgomery(BIGNUM *r,const BIGNUM *a,const BIGNUM *b, | |||
430 | int BN_from_montgomery(BIGNUM *r,const BIGNUM *a, | 430 | int BN_from_montgomery(BIGNUM *r,const BIGNUM *a, |
431 | BN_MONT_CTX *mont, BN_CTX *ctx); | 431 | BN_MONT_CTX *mont, BN_CTX *ctx); |
432 | void BN_MONT_CTX_free(BN_MONT_CTX *mont); | 432 | void BN_MONT_CTX_free(BN_MONT_CTX *mont); |
433 | int BN_MONT_CTX_set(BN_MONT_CTX *mont,const BIGNUM *modulus,BN_CTX *ctx); | 433 | int BN_MONT_CTX_set(BN_MONT_CTX *mont,const BIGNUM *mod,BN_CTX *ctx); |
434 | BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to,BN_MONT_CTX *from); | 434 | BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to,BN_MONT_CTX *from); |
435 | 435 | ||
436 | BN_BLINDING *BN_BLINDING_new(BIGNUM *A,BIGNUM *Ai,BIGNUM *mod); | 436 | BN_BLINDING *BN_BLINDING_new(BIGNUM *A,BIGNUM *Ai,BIGNUM *mod); |
diff --git a/src/lib/libcrypto/cryptlib.c b/src/lib/libcrypto/cryptlib.c index d301b376f7..612b3b93b4 100644 --- a/src/lib/libcrypto/cryptlib.c +++ b/src/lib/libcrypto/cryptlib.c | |||
@@ -492,11 +492,3 @@ BOOL WINAPI DLLEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason, | |||
492 | #endif | 492 | #endif |
493 | 493 | ||
494 | #endif | 494 | #endif |
495 | |||
496 | void OpenSSLDie(const char *file,int line,const char *assertion) | ||
497 | { | ||
498 | fprintf(stderr,"%s(%d): OpenSSL internal error, assertion failed: %s\n", | ||
499 | file,line,assertion); | ||
500 | abort(); | ||
501 | } | ||
502 | |||
diff --git a/src/lib/libcrypto/cryptlib.h b/src/lib/libcrypto/cryptlib.h index 985a6d377c..88e4ae509f 100644 --- a/src/lib/libcrypto/cryptlib.h +++ b/src/lib/libcrypto/cryptlib.h | |||
@@ -93,10 +93,6 @@ extern "C" { | |||
93 | #define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1) | 93 | #define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1) |
94 | #define HEX_SIZE(type) ((sizeof(type)*2) | 94 | #define HEX_SIZE(type) ((sizeof(type)*2) |
95 | 95 | ||
96 | /* die if we have to */ | ||
97 | void OpenSSLDie(const char *file,int line,const char *assertion); | ||
98 | #define die(e) ((e) ? (void)0 : OpenSSLDie(__FILE__, __LINE__, #e)) | ||
99 | |||
100 | #ifdef __cplusplus | 96 | #ifdef __cplusplus |
101 | } | 97 | } |
102 | #endif | 98 | #endif |
diff --git a/src/lib/libcrypto/des/ecb_enc.c b/src/lib/libcrypto/des/ecb_enc.c index 4650f2fa0f..1b70f68806 100644 --- a/src/lib/libcrypto/des/ecb_enc.c +++ b/src/lib/libcrypto/des/ecb_enc.c | |||
@@ -57,6 +57,7 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include "des_locl.h" | 59 | #include "des_locl.h" |
60 | #include "des_ver.h" | ||
60 | #include "spr.h" | 61 | #include "spr.h" |
61 | #include <openssl/opensslv.h> | 62 | #include <openssl/opensslv.h> |
62 | 63 | ||
diff --git a/src/lib/libcrypto/des/set_key.c b/src/lib/libcrypto/des/set_key.c index 683916e71b..143008ed9c 100644 --- a/src/lib/libcrypto/des/set_key.c +++ b/src/lib/libcrypto/des/set_key.c | |||
@@ -342,7 +342,7 @@ void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule) | |||
342 | register DES_LONG *k; | 342 | register DES_LONG *k; |
343 | register int i; | 343 | register int i; |
344 | 344 | ||
345 | #if OPENBSD_DEV_CRYPTO | 345 | #ifdef OPENBSD_DEV_CRYPTO |
346 | memcpy(schedule->key,key,sizeof schedule->key); | 346 | memcpy(schedule->key,key,sizeof schedule->key); |
347 | schedule->session=NULL; | 347 | schedule->session=NULL; |
348 | #endif | 348 | #endif |
diff --git a/src/lib/libcrypto/doc/DH_set_method.pod b/src/lib/libcrypto/doc/DH_set_method.pod index d990bf8786..73261fc467 100644 --- a/src/lib/libcrypto/doc/DH_set_method.pod +++ b/src/lib/libcrypto/doc/DH_set_method.pod | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | =head1 NAME | 3 | =head1 NAME |
4 | 4 | ||
5 | DH_set_default_openssl_method, DH_get_default_openssl_method, | 5 | DH_set_default_method, DH_get_default_method, |
6 | DH_set_method, DH_new_method, DH_OpenSSL - select DH method | 6 | DH_set_method, DH_new_method, DH_OpenSSL - select DH method |
7 | 7 | ||
8 | =head1 SYNOPSIS | 8 | =head1 SYNOPSIS |
@@ -10,45 +10,47 @@ DH_set_method, DH_new_method, DH_OpenSSL - select DH method | |||
10 | #include <openssl/dh.h> | 10 | #include <openssl/dh.h> |
11 | #include <openssl/engine.h> | 11 | #include <openssl/engine.h> |
12 | 12 | ||
13 | void DH_set_default_openssl_method(DH_METHOD *meth); | 13 | void DH_set_default_method(const DH_METHOD *meth); |
14 | 14 | ||
15 | DH_METHOD *DH_get_default_openssl_method(void); | 15 | const DH_METHOD *DH_get_default_method(void); |
16 | 16 | ||
17 | int DH_set_method(DH *dh, ENGINE *engine); | 17 | int DH_set_method(DH *dh, const DH_METHOD *meth); |
18 | 18 | ||
19 | DH *DH_new_method(ENGINE *engine); | 19 | DH *DH_new_method(ENGINE *engine); |
20 | 20 | ||
21 | DH_METHOD *DH_OpenSSL(void); | 21 | const DH_METHOD *DH_OpenSSL(void); |
22 | 22 | ||
23 | =head1 DESCRIPTION | 23 | =head1 DESCRIPTION |
24 | 24 | ||
25 | A B<DH_METHOD> specifies the functions that OpenSSL uses for Diffie-Hellman | 25 | A B<DH_METHOD> specifies the functions that OpenSSL uses for Diffie-Hellman |
26 | operations. By modifying the method, alternative implementations | 26 | operations. By modifying the method, alternative implementations |
27 | such as hardware accelerators may be used. | 27 | such as hardware accelerators may be used. IMPORTANT: See the NOTES section for |
28 | 28 | important information about how these DH API functions are affected by the use | |
29 | Initially, the default is to use the OpenSSL internal implementation. | 29 | of B<ENGINE> API calls. |
30 | DH_OpenSSL() returns a pointer to that method. | 30 | |
31 | 31 | Initially, the default DH_METHOD is the OpenSSL internal implementation, as | |
32 | DH_set_default_openssl_method() makes B<meth> the default method for all DH | 32 | returned by DH_OpenSSL(). |
33 | structures created later. B<NB:> This is true only whilst the default engine | 33 | |
34 | for Diffie-Hellman operations remains as "openssl". ENGINEs provide an | 34 | DH_set_default_method() makes B<meth> the default method for all DH |
35 | encapsulation for implementations of one or more algorithms, and all the DH | 35 | structures created later. B<NB>: This is true only whilst no ENGINE has been set |
36 | functions mentioned here operate within the scope of the default | 36 | as a default for DH, so this function is no longer recommended. |
37 | "openssl" engine. | 37 | |
38 | 38 | DH_get_default_method() returns a pointer to the current default DH_METHOD. | |
39 | DH_get_default_openssl_method() returns a pointer to the current default | 39 | However, the meaningfulness of this result is dependant on whether the ENGINE |
40 | method for the "openssl" engine. | 40 | API is being used, so this function is no longer recommended. |
41 | 41 | ||
42 | DH_set_method() selects B<engine> as the engine that will be responsible for | 42 | DH_set_method() selects B<meth> to perform all operations using the key B<dh>. |
43 | all operations using the structure B<dh>. If this function completes successfully, | 43 | This will replace the DH_METHOD used by the DH key and if the previous method |
44 | then the B<dh> structure will have its own functional reference of B<engine>, so | 44 | was supplied by an ENGINE, the handle to that ENGINE will be released during the |
45 | the caller should remember to free their own reference to B<engine> when they are | 45 | change. It is possible to have DH keys that only work with certain DH_METHOD |
46 | finished with it. NB: An ENGINE's DH_METHOD can be retrieved (or set) by | 46 | implementations (eg. from an ENGINE module that supports embedded |
47 | ENGINE_get_DH() or ENGINE_set_DH(). | 47 | hardware-protected keys), and in such cases attempting to change the DH_METHOD |
48 | 48 | for the key can have unexpected results. | |
49 | DH_new_method() allocates and initializes a DH structure so that | 49 | |
50 | B<engine> will be used for the DH operations. If B<engine> is NULL, | 50 | DH_new_method() allocates and initializes a DH structure so that B<engine> will |
51 | the default engine for Diffie-Hellman opertaions is used. | 51 | be used for the DH operations. If B<engine> is NULL, the default ENGINE for DH |
52 | operations is used, and if no default ENGINE is set, the DH_METHOD controlled by | ||
53 | DH_set_default_method() is used. | ||
52 | 54 | ||
53 | =head1 THE DH_METHOD STRUCTURE | 55 | =head1 THE DH_METHOD STRUCTURE |
54 | 56 | ||
@@ -82,17 +84,28 @@ the default engine for Diffie-Hellman opertaions is used. | |||
82 | 84 | ||
83 | =head1 RETURN VALUES | 85 | =head1 RETURN VALUES |
84 | 86 | ||
85 | DH_OpenSSL() and DH_get_default_openssl_method() return pointers to the | 87 | DH_OpenSSL() and DH_get_default_method() return pointers to the respective |
86 | respective B<DH_METHOD>s. | 88 | B<DH_METHOD>s. |
89 | |||
90 | DH_set_default_method() returns no value. | ||
91 | |||
92 | DH_set_method() returns non-zero if the provided B<meth> was successfully set as | ||
93 | the method for B<dh> (including unloading the ENGINE handle if the previous | ||
94 | method was supplied by an ENGINE). | ||
87 | 95 | ||
88 | DH_set_default_openssl_method() returns no value. | 96 | DH_new_method() returns NULL and sets an error code that can be obtained by |
97 | L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise it | ||
98 | returns a pointer to the newly allocated structure. | ||
89 | 99 | ||
90 | DH_set_method() returns non-zero if the ENGINE associated with B<dh> | 100 | =head1 NOTES |
91 | was successfully changed to B<engine>. | ||
92 | 101 | ||
93 | DH_new_method() returns NULL and sets an error code that can be | 102 | As of version 0.9.7, DH_METHOD implementations are grouped together with other |
94 | obtained by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. | 103 | algorithmic APIs (eg. RSA_METHOD, EVP_CIPHER, etc) in B<ENGINE> modules. If a |
95 | Otherwise it returns a pointer to the newly allocated structure. | 104 | default ENGINE is specified for DH functionality using an ENGINE API function, |
105 | that will override any DH defaults set using the DH API (ie. | ||
106 | DH_set_default_method()). For this reason, the ENGINE API is the recommended way | ||
107 | to control default implementations for use in DH and other cryptographic | ||
108 | algorithms. | ||
96 | 109 | ||
97 | =head1 SEE ALSO | 110 | =head1 SEE ALSO |
98 | 111 | ||
@@ -103,9 +116,14 @@ L<dh(3)|dh(3)>, L<DH_new(3)|DH_new(3)> | |||
103 | DH_set_default_method(), DH_get_default_method(), DH_set_method(), | 116 | DH_set_default_method(), DH_get_default_method(), DH_set_method(), |
104 | DH_new_method() and DH_OpenSSL() were added in OpenSSL 0.9.4. | 117 | DH_new_method() and DH_OpenSSL() were added in OpenSSL 0.9.4. |
105 | 118 | ||
106 | DH_set_default_openssl_method() and DH_get_default_openssl_method() | 119 | DH_set_default_openssl_method() and DH_get_default_openssl_method() replaced |
107 | replaced DH_set_default_method() and DH_get_default_method() respectively, | 120 | DH_set_default_method() and DH_get_default_method() respectively, and |
108 | and DH_set_method() and DH_new_method() were altered to use B<ENGINE>s | 121 | DH_set_method() and DH_new_method() were altered to use B<ENGINE>s rather than |
109 | rather than B<DH_METHOD>s during development of OpenSSL 0.9.6. | 122 | B<DH_METHOD>s during development of the engine version of OpenSSL 0.9.6. For |
123 | 0.9.7, the handling of defaults in the ENGINE API was restructured so that this | ||
124 | change was reversed, and behaviour of the other functions resembled more closely | ||
125 | the previous behaviour. The behaviour of defaults in the ENGINE API now | ||
126 | transparently overrides the behaviour of defaults in the DH API without | ||
127 | requiring changing these function prototypes. | ||
110 | 128 | ||
111 | =cut | 129 | =cut |
diff --git a/src/lib/libcrypto/doc/DSA_dup_DH.pod b/src/lib/libcrypto/doc/DSA_dup_DH.pod index 29cb1075d1..fdfe125ab0 100644 --- a/src/lib/libcrypto/doc/DSA_dup_DH.pod +++ b/src/lib/libcrypto/doc/DSA_dup_DH.pod | |||
@@ -8,7 +8,7 @@ DSA_dup_DH - create a DH structure out of DSA structure | |||
8 | 8 | ||
9 | #include <openssl/dsa.h> | 9 | #include <openssl/dsa.h> |
10 | 10 | ||
11 | DH * DSA_dup_DH(DSA *r); | 11 | DH * DSA_dup_DH(const DSA *r); |
12 | 12 | ||
13 | =head1 DESCRIPTION | 13 | =head1 DESCRIPTION |
14 | 14 | ||
diff --git a/src/lib/libcrypto/doc/DSA_new.pod b/src/lib/libcrypto/doc/DSA_new.pod index 7dde54445b..546146d9de 100644 --- a/src/lib/libcrypto/doc/DSA_new.pod +++ b/src/lib/libcrypto/doc/DSA_new.pod | |||
@@ -14,7 +14,8 @@ DSA_new, DSA_free - allocate and free DSA objects | |||
14 | 14 | ||
15 | =head1 DESCRIPTION | 15 | =head1 DESCRIPTION |
16 | 16 | ||
17 | DSA_new() allocates and initializes a B<DSA> structure. | 17 | DSA_new() allocates and initializes a B<DSA> structure. It is equivalent to |
18 | calling DSA_new_method(NULL). | ||
18 | 19 | ||
19 | DSA_free() frees the B<DSA> structure and its components. The values are | 20 | DSA_free() frees the B<DSA> structure and its components. The values are |
20 | erased before the memory is returned to the system. | 21 | erased before the memory is returned to the system. |
diff --git a/src/lib/libcrypto/doc/DSA_set_method.pod b/src/lib/libcrypto/doc/DSA_set_method.pod index 36a1052d27..bc3cfb1f0a 100644 --- a/src/lib/libcrypto/doc/DSA_set_method.pod +++ b/src/lib/libcrypto/doc/DSA_set_method.pod | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | =head1 NAME | 3 | =head1 NAME |
4 | 4 | ||
5 | DSA_set_default_openssl_method, DSA_get_default_openssl_method, | 5 | DSA_set_default_method, DSA_get_default_method, |
6 | DSA_set_method, DSA_new_method, DSA_OpenSSL - select DSA method | 6 | DSA_set_method, DSA_new_method, DSA_OpenSSL - select DSA method |
7 | 7 | ||
8 | =head1 SYNOPSIS | 8 | =head1 SYNOPSIS |
@@ -10,11 +10,11 @@ DSA_set_method, DSA_new_method, DSA_OpenSSL - select DSA method | |||
10 | #include <openssl/dsa.h> | 10 | #include <openssl/dsa.h> |
11 | #include <openssl/engine.h> | 11 | #include <openssl/engine.h> |
12 | 12 | ||
13 | void DSA_set_default_openssl_method(DSA_METHOD *meth); | 13 | void DSA_set_default_method(const DSA_METHOD *meth); |
14 | 14 | ||
15 | DSA_METHOD *DSA_get_default_openssl_method(void); | 15 | const DSA_METHOD *DSA_get_default_method(void); |
16 | 16 | ||
17 | int DSA_set_method(DSA *dsa, ENGINE *engine); | 17 | int DSA_set_method(DSA *dsa, const DSA_METHOD *meth); |
18 | 18 | ||
19 | DSA *DSA_new_method(ENGINE *engine); | 19 | DSA *DSA_new_method(ENGINE *engine); |
20 | 20 | ||
@@ -24,26 +24,35 @@ DSA_set_method, DSA_new_method, DSA_OpenSSL - select DSA method | |||
24 | 24 | ||
25 | A B<DSA_METHOD> specifies the functions that OpenSSL uses for DSA | 25 | A B<DSA_METHOD> specifies the functions that OpenSSL uses for DSA |
26 | operations. By modifying the method, alternative implementations | 26 | operations. By modifying the method, alternative implementations |
27 | such as hardware accelerators may be used. | 27 | such as hardware accelerators may be used. IMPORTANT: See the NOTES section for |
28 | 28 | important information about how these DSA API functions are affected by the use | |
29 | Initially, the default is to use the OpenSSL internal implementation. | 29 | of B<ENGINE> API calls. |
30 | DSA_OpenSSL() returns a pointer to that method. | 30 | |
31 | 31 | Initially, the default DSA_METHOD is the OpenSSL internal implementation, | |
32 | DSA_set_default_openssl_method() makes B<meth> the default method for | 32 | as returned by DSA_OpenSSL(). |
33 | all DSA structures created later. B<NB:> This is true only whilst the | 33 | |
34 | default engine for DSA operations remains as "openssl". ENGINEs | 34 | DSA_set_default_method() makes B<meth> the default method for all DSA |
35 | provide an encapsulation for implementations of one or more algorithms at a | 35 | structures created later. B<NB>: This is true only whilst no ENGINE has |
36 | time, and all the DSA functions mentioned here operate within the scope | 36 | been set as a default for DSA, so this function is no longer recommended. |
37 | of the default "openssl" engine. | 37 | |
38 | 38 | DSA_get_default_method() returns a pointer to the current default | |
39 | DSA_get_default_openssl_method() returns a pointer to the current default | 39 | DSA_METHOD. However, the meaningfulness of this result is dependant on |
40 | method for the "openssl" engine. | 40 | whether the ENGINE API is being used, so this function is no longer |
41 | 41 | recommended. | |
42 | DSA_set_method() selects B<engine> for all operations using the structure B<dsa>. | 42 | |
43 | 43 | DSA_set_method() selects B<meth> to perform all operations using the key | |
44 | DSA_new_method() allocates and initializes a DSA structure so that | 44 | B<rsa>. This will replace the DSA_METHOD used by the DSA key and if the |
45 | B<engine> will be used for the DSA operations. If B<engine> is NULL, | 45 | previous method was supplied by an ENGINE, the handle to that ENGINE will |
46 | the default engine for DSA operations is used. | 46 | be released during the change. It is possible to have DSA keys that only |
47 | work with certain DSA_METHOD implementations (eg. from an ENGINE module | ||
48 | that supports embedded hardware-protected keys), and in such cases | ||
49 | attempting to change the DSA_METHOD for the key can have unexpected | ||
50 | results. | ||
51 | |||
52 | DSA_new_method() allocates and initializes a DSA structure so that B<engine> | ||
53 | will be used for the DSA operations. If B<engine> is NULL, the default engine | ||
54 | for DSA operations is used, and if no default ENGINE is set, the DSA_METHOD | ||
55 | controlled by DSA_set_default_method() is used. | ||
47 | 56 | ||
48 | =head1 THE DSA_METHOD STRUCTURE | 57 | =head1 THE DSA_METHOD STRUCTURE |
49 | 58 | ||
@@ -89,18 +98,29 @@ struct | |||
89 | 98 | ||
90 | =head1 RETURN VALUES | 99 | =head1 RETURN VALUES |
91 | 100 | ||
92 | DSA_OpenSSL() and DSA_get_default_openssl_method() return pointers to the | 101 | DSA_OpenSSL() and DSA_get_default_method() return pointers to the respective |
93 | respective B<DSA_METHOD>s. | 102 | B<DSA_METHOD>s. |
94 | 103 | ||
95 | DSA_set_default_openssl_method() returns no value. | 104 | DSA_set_default_method() returns no value. |
96 | 105 | ||
97 | DSA_set_method() returns non-zero if the ENGINE associated with B<dsa> | 106 | DSA_set_method() returns non-zero if the provided B<meth> was successfully set as |
98 | was successfully changed to B<engine>. | 107 | the method for B<dsa> (including unloading the ENGINE handle if the previous |
108 | method was supplied by an ENGINE). | ||
99 | 109 | ||
100 | DSA_new_method() returns NULL and sets an error code that can be | 110 | DSA_new_method() returns NULL and sets an error code that can be |
101 | obtained by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation | 111 | obtained by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation |
102 | fails. Otherwise it returns a pointer to the newly allocated structure. | 112 | fails. Otherwise it returns a pointer to the newly allocated structure. |
103 | 113 | ||
114 | =head1 NOTES | ||
115 | |||
116 | As of version 0.9.7, DSA_METHOD implementations are grouped together with other | ||
117 | algorithmic APIs (eg. RSA_METHOD, EVP_CIPHER, etc) in B<ENGINE> modules. If a | ||
118 | default ENGINE is specified for DSA functionality using an ENGINE API function, | ||
119 | that will override any DSA defaults set using the DSA API (ie. | ||
120 | DSA_set_default_method()). For this reason, the ENGINE API is the recommended way | ||
121 | to control default implementations for use in DSA and other cryptographic | ||
122 | algorithms. | ||
123 | |||
104 | =head1 SEE ALSO | 124 | =head1 SEE ALSO |
105 | 125 | ||
106 | L<dsa(3)|dsa(3)>, L<DSA_new(3)|DSA_new(3)> | 126 | L<dsa(3)|dsa(3)>, L<DSA_new(3)|DSA_new(3)> |
@@ -110,9 +130,14 @@ L<dsa(3)|dsa(3)>, L<DSA_new(3)|DSA_new(3)> | |||
110 | DSA_set_default_method(), DSA_get_default_method(), DSA_set_method(), | 130 | DSA_set_default_method(), DSA_get_default_method(), DSA_set_method(), |
111 | DSA_new_method() and DSA_OpenSSL() were added in OpenSSL 0.9.4. | 131 | DSA_new_method() and DSA_OpenSSL() were added in OpenSSL 0.9.4. |
112 | 132 | ||
113 | DSA_set_default_openssl_method() and DSA_get_default_openssl_method() | 133 | DSA_set_default_openssl_method() and DSA_get_default_openssl_method() replaced |
114 | replaced DSA_set_default_method() and DSA_get_default_method() respectively, | 134 | DSA_set_default_method() and DSA_get_default_method() respectively, and |
115 | and DSA_set_method() and DSA_new_method() were altered to use B<ENGINE>s | 135 | DSA_set_method() and DSA_new_method() were altered to use B<ENGINE>s rather than |
116 | rather than B<DSA_METHOD>s during development of OpenSSL 0.9.6. | 136 | B<DSA_METHOD>s during development of the engine version of OpenSSL 0.9.6. For |
137 | 0.9.7, the handling of defaults in the ENGINE API was restructured so that this | ||
138 | change was reversed, and behaviour of the other functions resembled more closely | ||
139 | the previous behaviour. The behaviour of defaults in the ENGINE API now | ||
140 | transparently overrides the behaviour of defaults in the DSA API without | ||
141 | requiring changing these function prototypes. | ||
117 | 142 | ||
118 | =cut | 143 | =cut |
diff --git a/src/lib/libcrypto/doc/DSA_size.pod b/src/lib/libcrypto/doc/DSA_size.pod index 23b6320a4d..ba4f650361 100644 --- a/src/lib/libcrypto/doc/DSA_size.pod +++ b/src/lib/libcrypto/doc/DSA_size.pod | |||
@@ -8,7 +8,7 @@ DSA_size - get DSA signature size | |||
8 | 8 | ||
9 | #include <openssl/dsa.h> | 9 | #include <openssl/dsa.h> |
10 | 10 | ||
11 | int DSA_size(DSA *dsa); | 11 | int DSA_size(const DSA *dsa); |
12 | 12 | ||
13 | =head1 DESCRIPTION | 13 | =head1 DESCRIPTION |
14 | 14 | ||
diff --git a/src/lib/libcrypto/doc/EVP_SealInit.pod b/src/lib/libcrypto/doc/EVP_SealInit.pod index 0451eb648a..25ef07f7c7 100644 --- a/src/lib/libcrypto/doc/EVP_SealInit.pod +++ b/src/lib/libcrypto/doc/EVP_SealInit.pod | |||
@@ -73,4 +73,6 @@ L<EVP_OpenInit(3)|EVP_OpenInit(3)> | |||
73 | 73 | ||
74 | =head1 HISTORY | 74 | =head1 HISTORY |
75 | 75 | ||
76 | EVP_SealFinal() did not return a value before OpenSSL 0.9.7. | ||
77 | |||
76 | =cut | 78 | =cut |
diff --git a/src/lib/libcrypto/doc/RAND_set_rand_method.pod b/src/lib/libcrypto/doc/RAND_set_rand_method.pod index 464eba416d..c9bb6d9f27 100644 --- a/src/lib/libcrypto/doc/RAND_set_rand_method.pod +++ b/src/lib/libcrypto/doc/RAND_set_rand_method.pod | |||
@@ -8,22 +8,30 @@ RAND_set_rand_method, RAND_get_rand_method, RAND_SSLeay - select RAND method | |||
8 | 8 | ||
9 | #include <openssl/rand.h> | 9 | #include <openssl/rand.h> |
10 | 10 | ||
11 | void RAND_set_rand_method(RAND_METHOD *meth); | 11 | void RAND_set_rand_method(const RAND_METHOD *meth); |
12 | 12 | ||
13 | RAND_METHOD *RAND_get_rand_method(void); | 13 | const RAND_METHOD *RAND_get_rand_method(void); |
14 | 14 | ||
15 | RAND_METHOD *RAND_SSLeay(void); | 15 | RAND_METHOD *RAND_SSLeay(void); |
16 | 16 | ||
17 | =head1 DESCRIPTION | 17 | =head1 DESCRIPTION |
18 | 18 | ||
19 | A B<RAND_METHOD> specifies the functions that OpenSSL uses for random | 19 | A B<RAND_METHOD> specifies the functions that OpenSSL uses for random number |
20 | number generation. By modifying the method, alternative | 20 | generation. By modifying the method, alternative implementations such as |
21 | implementations such as hardware RNGs may be used. Initially, the | 21 | hardware RNGs may be used. IMPORTANT: See the NOTES section for important |
22 | default is to use the OpenSSL internal implementation. RAND_SSLeay() | 22 | information about how these RAND API functions are affected by the use of |
23 | returns a pointer to that method. | 23 | B<ENGINE> API calls. |
24 | 24 | ||
25 | RAND_set_rand_method() sets the RAND method to B<meth>. | 25 | Initially, the default RAND_METHOD is the OpenSSL internal implementation, as |
26 | RAND_get_rand_method() returns a pointer to the current method. | 26 | returned by RAND_SSLeay(). |
27 | |||
28 | RAND_set_default_method() makes B<meth> the method for PRNG use. B<NB>: This is | ||
29 | true only whilst no ENGINE has been set as a default for RAND, so this function | ||
30 | is no longer recommended. | ||
31 | |||
32 | RAND_get_default_method() returns a pointer to the current RAND_METHOD. | ||
33 | However, the meaningfulness of this result is dependant on whether the ENGINE | ||
34 | API is being used, so this function is no longer recommended. | ||
27 | 35 | ||
28 | =head1 THE RAND_METHOD STRUCTURE | 36 | =head1 THE RAND_METHOD STRUCTURE |
29 | 37 | ||
@@ -47,13 +55,29 @@ Each component may be NULL if the function is not implemented. | |||
47 | RAND_set_rand_method() returns no value. RAND_get_rand_method() and | 55 | RAND_set_rand_method() returns no value. RAND_get_rand_method() and |
48 | RAND_SSLeay() return pointers to the respective methods. | 56 | RAND_SSLeay() return pointers to the respective methods. |
49 | 57 | ||
58 | =head1 NOTES | ||
59 | |||
60 | As of version 0.9.7, RAND_METHOD implementations are grouped together with other | ||
61 | algorithmic APIs (eg. RSA_METHOD, EVP_CIPHER, etc) in B<ENGINE> modules. If a | ||
62 | default ENGINE is specified for RAND functionality using an ENGINE API function, | ||
63 | that will override any RAND defaults set using the RAND API (ie. | ||
64 | RAND_set_rand_method()). For this reason, the ENGINE API is the recommended way | ||
65 | to control default implementations for use in RAND and other cryptographic | ||
66 | algorithms. | ||
67 | |||
50 | =head1 SEE ALSO | 68 | =head1 SEE ALSO |
51 | 69 | ||
52 | L<rand(3)|rand(3)> | 70 | L<rand(3)|rand(3)>, L<engine(3)|engine(3)> |
53 | 71 | ||
54 | =head1 HISTORY | 72 | =head1 HISTORY |
55 | 73 | ||
56 | RAND_set_rand_method(), RAND_get_rand_method() and RAND_SSLeay() are | 74 | RAND_set_rand_method(), RAND_get_rand_method() and RAND_SSLeay() are |
57 | available in all versions of OpenSSL. | 75 | available in all versions of OpenSSL. |
58 | 76 | ||
77 | In the engine version of version 0.9.6, RAND_set_rand_method() was altered to | ||
78 | take an ENGINE pointer as its argument. As of version 0.9.7, that has been | ||
79 | reverted as the ENGINE API transparently overrides RAND defaults if used, | ||
80 | otherwise RAND API functions work as before. RAND_set_rand_engine() was also | ||
81 | introduced in version 0.9.7. | ||
82 | |||
59 | =cut | 83 | =cut |
diff --git a/src/lib/libcrypto/doc/RSA_new.pod b/src/lib/libcrypto/doc/RSA_new.pod index f16490ea6a..f0d996c40f 100644 --- a/src/lib/libcrypto/doc/RSA_new.pod +++ b/src/lib/libcrypto/doc/RSA_new.pod | |||
@@ -14,7 +14,8 @@ RSA_new, RSA_free - allocate and free RSA objects | |||
14 | 14 | ||
15 | =head1 DESCRIPTION | 15 | =head1 DESCRIPTION |
16 | 16 | ||
17 | RSA_new() allocates and initializes an B<RSA> structure. | 17 | RSA_new() allocates and initializes an B<RSA> structure. It is equivalent to |
18 | calling RSA_new_method(NULL). | ||
18 | 19 | ||
19 | RSA_free() frees the B<RSA> structure and its components. The key is | 20 | RSA_free() frees the B<RSA> structure and its components. The key is |
20 | erased before the memory is returned to the system. | 21 | erased before the memory is returned to the system. |
@@ -29,7 +30,8 @@ RSA_free() returns no value. | |||
29 | 30 | ||
30 | =head1 SEE ALSO | 31 | =head1 SEE ALSO |
31 | 32 | ||
32 | L<err(3)|err(3)>, L<rsa(3)|rsa(3)>, L<RSA_generate_key(3)|RSA_generate_key(3)> | 33 | L<err(3)|err(3)>, L<rsa(3)|rsa(3)>, L<RSA_generate_key(3)|RSA_generate_key(3)>, |
34 | L<RSA_new_method(3)|RSA_new_method(3)> | ||
33 | 35 | ||
34 | =head1 HISTORY | 36 | =head1 HISTORY |
35 | 37 | ||
diff --git a/src/lib/libcrypto/doc/RSA_set_method.pod b/src/lib/libcrypto/doc/RSA_set_method.pod index 14917dd35f..0687c2242a 100644 --- a/src/lib/libcrypto/doc/RSA_set_method.pod +++ b/src/lib/libcrypto/doc/RSA_set_method.pod | |||
@@ -11,52 +11,64 @@ RSA_null_method, RSA_flags, RSA_new_method - select RSA method | |||
11 | #include <openssl/rsa.h> | 11 | #include <openssl/rsa.h> |
12 | #include <openssl/engine.h> | 12 | #include <openssl/engine.h> |
13 | 13 | ||
14 | void RSA_set_default_openssl_method(RSA_METHOD *meth); | 14 | void RSA_set_default_method(const RSA_METHOD *meth); |
15 | 15 | ||
16 | RSA_METHOD *RSA_get_default_openssl_method(void); | 16 | RSA_METHOD *RSA_get_default_method(void); |
17 | 17 | ||
18 | int RSA_set_method(RSA *rsa, ENGINE *engine); | 18 | int RSA_set_method(RSA *rsa, const RSA_METHOD *meth); |
19 | 19 | ||
20 | RSA_METHOD *RSA_get_method(RSA *rsa); | 20 | RSA_METHOD *RSA_get_method(const RSA *rsa); |
21 | 21 | ||
22 | RSA_METHOD *RSA_PKCS1_SSLeay(void); | 22 | RSA_METHOD *RSA_PKCS1_SSLeay(void); |
23 | 23 | ||
24 | RSA_METHOD *RSA_null_method(void); | 24 | RSA_METHOD *RSA_null_method(void); |
25 | 25 | ||
26 | int RSA_flags(RSA *rsa); | 26 | int RSA_flags(const RSA *rsa); |
27 | 27 | ||
28 | RSA *RSA_new_method(ENGINE *engine); | 28 | RSA *RSA_new_method(ENGINE *engine); |
29 | 29 | ||
30 | =head1 DESCRIPTION | 30 | =head1 DESCRIPTION |
31 | 31 | ||
32 | An B<RSA_METHOD> specifies the functions that OpenSSL uses for RSA | 32 | An B<RSA_METHOD> specifies the functions that OpenSSL uses for RSA |
33 | operations. By modifying the method, alternative implementations | 33 | operations. By modifying the method, alternative implementations such as |
34 | such as hardware accelerators may be used. | 34 | hardware accelerators may be used. IMPORTANT: See the NOTES section for |
35 | 35 | important information about how these RSA API functions are affected by the | |
36 | Initially, the default is to use the OpenSSL internal implementation. | 36 | use of B<ENGINE> API calls. |
37 | RSA_PKCS1_SSLeay() returns a pointer to that method. | 37 | |
38 | 38 | Initially, the default RSA_METHOD is the OpenSSL internal implementation, | |
39 | RSA_set_default_openssl_method() makes B<meth> the default method for all B<RSA> | 39 | as returned by RSA_PKCS1_SSLeay(). |
40 | structures created later. B<NB:> This is true only whilst the default engine | 40 | |
41 | for RSA operations remains as "openssl". ENGINEs provide an | 41 | RSA_set_default_method() makes B<meth> the default method for all RSA |
42 | encapsulation for implementations of one or more algorithms at a time, and all | 42 | structures created later. B<NB>: This is true only whilst no ENGINE has |
43 | the RSA functions mentioned here operate within the scope of the default | 43 | been set as a default for RSA, so this function is no longer recommended. |
44 | "openssl" engine. | 44 | |
45 | 45 | RSA_get_default_method() returns a pointer to the current default | |
46 | RSA_get_default_openssl_method() returns a pointer to the current default | 46 | RSA_METHOD. However, the meaningfulness of this result is dependant on |
47 | method for the "openssl" engine. | 47 | whether the ENGINE API is being used, so this function is no longer |
48 | 48 | recommended. | |
49 | RSA_set_method() selects B<engine> for all operations using the key | 49 | |
50 | B<rsa>. | 50 | RSA_set_method() selects B<meth> to perform all operations using the key |
51 | 51 | B<rsa>. This will replace the RSA_METHOD used by the RSA key and if the | |
52 | RSA_get_method() returns a pointer to the RSA_METHOD from the currently | 52 | previous method was supplied by an ENGINE, the handle to that ENGINE will |
53 | selected ENGINE for B<rsa>. | 53 | be released during the change. It is possible to have RSA keys that only |
54 | 54 | work with certain RSA_METHOD implementations (eg. from an ENGINE module | |
55 | RSA_flags() returns the B<flags> that are set for B<rsa>'s current method. | 55 | that supports embedded hardware-protected keys), and in such cases |
56 | attempting to change the RSA_METHOD for the key can have unexpected | ||
57 | results. | ||
58 | |||
59 | RSA_get_method() returns a pointer to the RSA_METHOD being used by B<rsa>. | ||
60 | This method may or may not be supplied by an ENGINE implementation, but if | ||
61 | it is, the return value can only be guaranteed to be valid as long as the | ||
62 | RSA key itself is valid and does not have its implementation changed by | ||
63 | RSA_set_method(). | ||
64 | |||
65 | RSA_flags() returns the B<flags> that are set for B<rsa>'s current | ||
66 | RSA_METHOD. See the BUGS section. | ||
56 | 67 | ||
57 | RSA_new_method() allocates and initializes an RSA structure so that | 68 | RSA_new_method() allocates and initializes an RSA structure so that |
58 | B<engine> will be used for the RSA operations. If B<engine> is NULL, | 69 | B<engine> will be used for the RSA operations. If B<engine> is NULL, the |
59 | the default engine for RSA operations is used. | 70 | default ENGINE for RSA operations is used, and if no default ENGINE is set, |
71 | the RSA_METHOD controlled by RSA_set_default_method() is used. | ||
60 | 72 | ||
61 | =head1 THE RSA_METHOD STRUCTURE | 73 | =head1 THE RSA_METHOD STRUCTURE |
62 | 74 | ||
@@ -121,22 +133,45 @@ the default engine for RSA operations is used. | |||
121 | 133 | ||
122 | =head1 RETURN VALUES | 134 | =head1 RETURN VALUES |
123 | 135 | ||
124 | RSA_PKCS1_SSLeay(), RSA_PKCS1_null_method(), RSA_get_default_openssl_method() | 136 | RSA_PKCS1_SSLeay(), RSA_PKCS1_null_method(), RSA_get_default_method() |
125 | and RSA_get_method() return pointers to the respective RSA_METHODs. | 137 | and RSA_get_method() return pointers to the respective RSA_METHODs. |
126 | 138 | ||
127 | RSA_set_default_openssl_method() returns no value. | 139 | RSA_set_default_method() returns no value. |
128 | 140 | ||
129 | RSA_set_method() selects B<engine> as the engine that will be responsible for | 141 | RSA_set_method() returns a pointer to the old RSA_METHOD implementation |
130 | all operations using the structure B<rsa>. If this function completes successfully, | 142 | that was replaced. However, this return value should probably be ignored |
131 | then the B<rsa> structure will have its own functional reference of B<engine>, so | 143 | because if it was supplied by an ENGINE, the pointer could be invalidated |
132 | the caller should remember to free their own reference to B<engine> when they are | 144 | at any time if the ENGINE is unloaded (in fact it could be unloaded as a |
133 | finished with it. NB: An ENGINE's RSA_METHOD can be retrieved (or set) by | 145 | result of the RSA_set_method() function releasing its handle to the |
134 | ENGINE_get_RSA() or ENGINE_set_RSA(). | 146 | ENGINE). For this reason, the return type may be replaced with a B<void> |
147 | declaration in a future release. | ||
135 | 148 | ||
136 | RSA_new_method() returns NULL and sets an error code that can be | 149 | RSA_new_method() returns NULL and sets an error code that can be obtained |
137 | obtained by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise | 150 | by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise |
138 | it returns a pointer to the newly allocated structure. | 151 | it returns a pointer to the newly allocated structure. |
139 | 152 | ||
153 | =head1 NOTES | ||
154 | |||
155 | As of version 0.9.7, RSA_METHOD implementations are grouped together with | ||
156 | other algorithmic APIs (eg. DSA_METHOD, EVP_CIPHER, etc) into B<ENGINE> | ||
157 | modules. If a default ENGINE is specified for RSA functionality using an | ||
158 | ENGINE API function, that will override any RSA defaults set using the RSA | ||
159 | API (ie. RSA_set_default_method()). For this reason, the ENGINE API is the | ||
160 | recommended way to control default implementations for use in RSA and other | ||
161 | cryptographic algorithms. | ||
162 | |||
163 | =head1 BUGS | ||
164 | |||
165 | The behaviour of RSA_flags() is a mis-feature that is left as-is for now | ||
166 | to avoid creating compatibility problems. RSA functionality, such as the | ||
167 | encryption functions, are controlled by the B<flags> value in the RSA key | ||
168 | itself, not by the B<flags> value in the RSA_METHOD attached to the RSA key | ||
169 | (which is what this function returns). If the flags element of an RSA key | ||
170 | is changed, the changes will be honoured by RSA functionality but will not | ||
171 | be reflected in the return value of the RSA_flags() function - in effect | ||
172 | RSA_flags() behaves more like an RSA_default_flags() function (which does | ||
173 | not currently exist). | ||
174 | |||
140 | =head1 SEE ALSO | 175 | =head1 SEE ALSO |
141 | 176 | ||
142 | L<rsa(3)|rsa(3)>, L<RSA_new(3)|RSA_new(3)> | 177 | L<rsa(3)|rsa(3)>, L<RSA_new(3)|RSA_new(3)> |
@@ -149,8 +184,14 @@ well as the rsa_sign and rsa_verify components of RSA_METHOD were | |||
149 | added in OpenSSL 0.9.4. | 184 | added in OpenSSL 0.9.4. |
150 | 185 | ||
151 | RSA_set_default_openssl_method() and RSA_get_default_openssl_method() | 186 | RSA_set_default_openssl_method() and RSA_get_default_openssl_method() |
152 | replaced RSA_set_default_method() and RSA_get_default_method() respectively, | 187 | replaced RSA_set_default_method() and RSA_get_default_method() |
153 | and RSA_set_method() and RSA_new_method() were altered to use B<ENGINE>s | 188 | respectively, and RSA_set_method() and RSA_new_method() were altered to use |
154 | rather than B<RSA_METHOD>s during development of OpenSSL 0.9.6. | 189 | B<ENGINE>s rather than B<RSA_METHOD>s during development of the engine |
190 | version of OpenSSL 0.9.6. For 0.9.7, the handling of defaults in the ENGINE | ||
191 | API was restructured so that this change was reversed, and behaviour of the | ||
192 | other functions resembled more closely the previous behaviour. The | ||
193 | behaviour of defaults in the ENGINE API now transparently overrides the | ||
194 | behaviour of defaults in the RSA API without requiring changing these | ||
195 | function prototypes. | ||
155 | 196 | ||
156 | =cut | 197 | =cut |
diff --git a/src/lib/libcrypto/doc/RSA_size.pod b/src/lib/libcrypto/doc/RSA_size.pod index b36b4d58d5..5b7f835f95 100644 --- a/src/lib/libcrypto/doc/RSA_size.pod +++ b/src/lib/libcrypto/doc/RSA_size.pod | |||
@@ -8,7 +8,7 @@ RSA_size - get RSA modulus size | |||
8 | 8 | ||
9 | #include <openssl/rsa.h> | 9 | #include <openssl/rsa.h> |
10 | 10 | ||
11 | int RSA_size(RSA *rsa); | 11 | int RSA_size(const RSA *rsa); |
12 | 12 | ||
13 | =head1 DESCRIPTION | 13 | =head1 DESCRIPTION |
14 | 14 | ||
diff --git a/src/lib/libcrypto/doc/dh.pod b/src/lib/libcrypto/doc/dh.pod index b4be4be405..c3ccd06207 100644 --- a/src/lib/libcrypto/doc/dh.pod +++ b/src/lib/libcrypto/doc/dh.pod | |||
@@ -12,20 +12,20 @@ dh - Diffie-Hellman key agreement | |||
12 | DH * DH_new(void); | 12 | DH * DH_new(void); |
13 | void DH_free(DH *dh); | 13 | void DH_free(DH *dh); |
14 | 14 | ||
15 | int DH_size(DH *dh); | 15 | int DH_size(const DH *dh); |
16 | 16 | ||
17 | DH * DH_generate_parameters(int prime_len, int generator, | 17 | DH * DH_generate_parameters(int prime_len, int generator, |
18 | void (*callback)(int, int, void *), void *cb_arg); | 18 | void (*callback)(int, int, void *), void *cb_arg); |
19 | int DH_check(DH *dh, int *codes); | 19 | int DH_check(const DH *dh, int *codes); |
20 | 20 | ||
21 | int DH_generate_key(DH *dh); | 21 | int DH_generate_key(DH *dh); |
22 | int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh); | 22 | int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh); |
23 | 23 | ||
24 | void DH_set_default_openssl_method(DH_METHOD *meth); | 24 | void DH_set_default_method(const DH_METHOD *meth); |
25 | DH_METHOD *DH_get_default_openssl_method(void); | 25 | const DH_METHOD *DH_get_default_method(void); |
26 | int DH_set_method(DH *dh, ENGINE *engine); | 26 | int DH_set_method(DH *dh, const DH_METHOD *meth); |
27 | DH *DH_new_method(ENGINE *engine); | 27 | DH *DH_new_method(ENGINE *engine); |
28 | DH_METHOD *DH_OpenSSL(void); | 28 | const DH_METHOD *DH_OpenSSL(void); |
29 | 29 | ||
30 | int DH_get_ex_new_index(long argl, char *argp, int (*new_func)(), | 30 | int DH_get_ex_new_index(long argl, char *argp, int (*new_func)(), |
31 | int (*dup_func)(), void (*free_func)()); | 31 | int (*dup_func)(), void (*free_func)()); |
@@ -33,10 +33,10 @@ dh - Diffie-Hellman key agreement | |||
33 | char *DH_get_ex_data(DH *d, int idx); | 33 | char *DH_get_ex_data(DH *d, int idx); |
34 | 34 | ||
35 | DH * d2i_DHparams(DH **a, unsigned char **pp, long length); | 35 | DH * d2i_DHparams(DH **a, unsigned char **pp, long length); |
36 | int i2d_DHparams(DH *a, unsigned char **pp); | 36 | int i2d_DHparams(const DH *a, unsigned char **pp); |
37 | 37 | ||
38 | int DHparams_print_fp(FILE *fp, DH *x); | 38 | int DHparams_print_fp(FILE *fp, const DH *x); |
39 | int DHparams_print(BIO *bp, DH *x); | 39 | int DHparams_print(BIO *bp, const DH *x); |
40 | 40 | ||
41 | =head1 DESCRIPTION | 41 | =head1 DESCRIPTION |
42 | 42 | ||
@@ -57,11 +57,20 @@ The B<DH> structure consists of several BIGNUM components. | |||
57 | }; | 57 | }; |
58 | DH | 58 | DH |
59 | 59 | ||
60 | Note that DH keys may use non-standard B<DH_METHOD> implementations, | ||
61 | either directly or by the use of B<ENGINE> modules. In some cases (eg. an | ||
62 | ENGINE providing support for hardware-embedded keys), these BIGNUM values | ||
63 | will not be used by the implementation or may be used for alternative data | ||
64 | storage. For this reason, applications should generally avoid using DH | ||
65 | structure elements directly and instead use API functions to query or | ||
66 | modify keys. | ||
67 | |||
60 | =head1 SEE ALSO | 68 | =head1 SEE ALSO |
61 | 69 | ||
62 | L<dhparam(1)|dhparam(1)>, L<bn(3)|bn(3)>, L<dsa(3)|dsa(3)>, L<err(3)|err(3)>, | 70 | L<dhparam(1)|dhparam(1)>, L<bn(3)|bn(3)>, L<dsa(3)|dsa(3)>, L<err(3)|err(3)>, |
63 | L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<DH_set_method(3)|DH_set_method(3)>, | 71 | L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<engine(3)|engine(3)>, |
64 | L<DH_new(3)|DH_new(3)>, L<DH_get_ex_new_index(3)|DH_get_ex_new_index(3)>, | 72 | L<DH_set_method(3)|DH_set_method(3)>, L<DH_new(3)|DH_new(3)>, |
73 | L<DH_get_ex_new_index(3)|DH_get_ex_new_index(3)>, | ||
65 | L<DH_generate_parameters(3)|DH_generate_parameters(3)>, | 74 | L<DH_generate_parameters(3)|DH_generate_parameters(3)>, |
66 | L<DH_compute_key(3)|DH_compute_key(3)>, L<d2i_DHparams(3)|d2i_DHparams(3)>, | 75 | L<DH_compute_key(3)|DH_compute_key(3)>, L<d2i_DHparams(3)|d2i_DHparams(3)>, |
67 | L<RSA_print(3)|RSA_print(3)> | 76 | L<RSA_print(3)|RSA_print(3)> |
diff --git a/src/lib/libcrypto/doc/dsa.pod b/src/lib/libcrypto/doc/dsa.pod index 82d7fb77cd..da07d2b930 100644 --- a/src/lib/libcrypto/doc/dsa.pod +++ b/src/lib/libcrypto/doc/dsa.pod | |||
@@ -12,13 +12,13 @@ dsa - Digital Signature Algorithm | |||
12 | DSA * DSA_new(void); | 12 | DSA * DSA_new(void); |
13 | void DSA_free(DSA *dsa); | 13 | void DSA_free(DSA *dsa); |
14 | 14 | ||
15 | int DSA_size(DSA *dsa); | 15 | int DSA_size(const DSA *dsa); |
16 | 16 | ||
17 | DSA * DSA_generate_parameters(int bits, unsigned char *seed, | 17 | DSA * DSA_generate_parameters(int bits, unsigned char *seed, |
18 | int seed_len, int *counter_ret, unsigned long *h_ret, | 18 | int seed_len, int *counter_ret, unsigned long *h_ret, |
19 | void (*callback)(int, int, void *), void *cb_arg); | 19 | void (*callback)(int, int, void *), void *cb_arg); |
20 | 20 | ||
21 | DH * DSA_dup_DH(DSA *r); | 21 | DH * DSA_dup_DH(const DSA *r); |
22 | 22 | ||
23 | int DSA_generate_key(DSA *dsa); | 23 | int DSA_generate_key(DSA *dsa); |
24 | 24 | ||
@@ -27,13 +27,13 @@ dsa - Digital Signature Algorithm | |||
27 | int DSA_sign_setup(DSA *dsa, BN_CTX *ctx, BIGNUM **kinvp, | 27 | int DSA_sign_setup(DSA *dsa, BN_CTX *ctx, BIGNUM **kinvp, |
28 | BIGNUM **rp); | 28 | BIGNUM **rp); |
29 | int DSA_verify(int dummy, const unsigned char *dgst, int len, | 29 | int DSA_verify(int dummy, const unsigned char *dgst, int len, |
30 | unsigned char *sigbuf, int siglen, DSA *dsa); | 30 | const unsigned char *sigbuf, int siglen, DSA *dsa); |
31 | 31 | ||
32 | void DSA_set_default_openssl_method(DSA_METHOD *meth); | 32 | void DSA_set_default_method(const DSA_METHOD *meth); |
33 | DSA_METHOD *DSA_get_default_openssl_method(void); | 33 | const DSA_METHOD *DSA_get_default_method(void); |
34 | int DSA_set_method(DSA *dsa, ENGINE *engine); | 34 | int DSA_set_method(DSA *dsa, const DSA_METHOD *meth); |
35 | DSA *DSA_new_method(ENGINE *engine); | 35 | DSA *DSA_new_method(ENGINE *engine); |
36 | DSA_METHOD *DSA_OpenSSL(void); | 36 | const DSA_METHOD *DSA_OpenSSL(void); |
37 | 37 | ||
38 | int DSA_get_ex_new_index(long argl, char *argp, int (*new_func)(), | 38 | int DSA_get_ex_new_index(long argl, char *argp, int (*new_func)(), |
39 | int (*dup_func)(), void (*free_func)()); | 39 | int (*dup_func)(), void (*free_func)()); |
@@ -42,7 +42,7 @@ dsa - Digital Signature Algorithm | |||
42 | 42 | ||
43 | DSA_SIG *DSA_SIG_new(void); | 43 | DSA_SIG *DSA_SIG_new(void); |
44 | void DSA_SIG_free(DSA_SIG *a); | 44 | void DSA_SIG_free(DSA_SIG *a); |
45 | int i2d_DSA_SIG(DSA_SIG *a, unsigned char **pp); | 45 | int i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp); |
46 | DSA_SIG *d2i_DSA_SIG(DSA_SIG **v, unsigned char **pp, long length); | 46 | DSA_SIG *d2i_DSA_SIG(DSA_SIG **v, unsigned char **pp, long length); |
47 | 47 | ||
48 | DSA_SIG *DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); | 48 | DSA_SIG *DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); |
@@ -52,14 +52,14 @@ dsa - Digital Signature Algorithm | |||
52 | DSA * d2i_DSAPublicKey(DSA **a, unsigned char **pp, long length); | 52 | DSA * d2i_DSAPublicKey(DSA **a, unsigned char **pp, long length); |
53 | DSA * d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length); | 53 | DSA * d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length); |
54 | DSA * d2i_DSAparams(DSA **a, unsigned char **pp, long length); | 54 | DSA * d2i_DSAparams(DSA **a, unsigned char **pp, long length); |
55 | int i2d_DSAPublicKey(DSA *a, unsigned char **pp); | 55 | int i2d_DSAPublicKey(const DSA *a, unsigned char **pp); |
56 | int i2d_DSAPrivateKey(DSA *a, unsigned char **pp); | 56 | int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp); |
57 | int i2d_DSAparams(DSA *a,unsigned char **pp); | 57 | int i2d_DSAparams(const DSA *a,unsigned char **pp); |
58 | 58 | ||
59 | int DSAparams_print(BIO *bp, DSA *x); | 59 | int DSAparams_print(BIO *bp, const DSA *x); |
60 | int DSAparams_print_fp(FILE *fp, DSA *x); | 60 | int DSAparams_print_fp(FILE *fp, const DSA *x); |
61 | int DSA_print(BIO *bp, DSA *x, int off); | 61 | int DSA_print(BIO *bp, const DSA *x, int off); |
62 | int DSA_print_fp(FILE *bp, DSA *x, int off); | 62 | int DSA_print_fp(FILE *bp, const DSA *x, int off); |
63 | 63 | ||
64 | =head1 DESCRIPTION | 64 | =head1 DESCRIPTION |
65 | 65 | ||
@@ -85,6 +85,14 @@ The B<DSA> structure consists of several BIGNUM components. | |||
85 | 85 | ||
86 | In public keys, B<priv_key> is NULL. | 86 | In public keys, B<priv_key> is NULL. |
87 | 87 | ||
88 | Note that DSA keys may use non-standard B<DSA_METHOD> implementations, | ||
89 | either directly or by the use of B<ENGINE> modules. In some cases (eg. an | ||
90 | ENGINE providing support for hardware-embedded keys), these BIGNUM values | ||
91 | will not be used by the implementation or may be used for alternative data | ||
92 | storage. For this reason, applications should generally avoid using DSA | ||
93 | structure elements directly and instead use API functions to query or | ||
94 | modify keys. | ||
95 | |||
88 | =head1 CONFORMING TO | 96 | =head1 CONFORMING TO |
89 | 97 | ||
90 | US Federal Information Processing Standard FIPS 186 (Digital Signature | 98 | US Federal Information Processing Standard FIPS 186 (Digital Signature |
@@ -93,7 +101,8 @@ Standard, DSS), ANSI X9.30 | |||
93 | =head1 SEE ALSO | 101 | =head1 SEE ALSO |
94 | 102 | ||
95 | L<bn(3)|bn(3)>, L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, | 103 | L<bn(3)|bn(3)>, L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, |
96 | L<rsa(3)|rsa(3)>, L<sha(3)|sha(3)>, L<DSA_new(3)|DSA_new(3)>, | 104 | L<rsa(3)|rsa(3)>, L<sha(3)|sha(3)>, L<engine(3)|engine(3)>, |
105 | L<DSA_new(3)|DSA_new(3)>, | ||
97 | L<DSA_size(3)|DSA_size(3)>, | 106 | L<DSA_size(3)|DSA_size(3)>, |
98 | L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>, | 107 | L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>, |
99 | L<DSA_dup_DH(3)|DSA_dup_DH(3)>, | 108 | L<DSA_dup_DH(3)|DSA_dup_DH(3)>, |
diff --git a/src/lib/libcrypto/doc/engine.pod b/src/lib/libcrypto/doc/engine.pod new file mode 100644 index 0000000000..61e0264bb7 --- /dev/null +++ b/src/lib/libcrypto/doc/engine.pod | |||
@@ -0,0 +1,621 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | engine - ENGINE cryptographic module support | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | #include <openssl/engine.h> | ||
10 | |||
11 | ENGINE *ENGINE_get_first(void); | ||
12 | ENGINE *ENGINE_get_last(void); | ||
13 | ENGINE *ENGINE_get_next(ENGINE *e); | ||
14 | ENGINE *ENGINE_get_prev(ENGINE *e); | ||
15 | |||
16 | int ENGINE_add(ENGINE *e); | ||
17 | int ENGINE_remove(ENGINE *e); | ||
18 | |||
19 | ENGINE *ENGINE_by_id(const char *id); | ||
20 | |||
21 | int ENGINE_init(ENGINE *e); | ||
22 | int ENGINE_finish(ENGINE *e); | ||
23 | |||
24 | void ENGINE_load_openssl(void); | ||
25 | void ENGINE_load_dynamic(void); | ||
26 | void ENGINE_load_cswift(void); | ||
27 | void ENGINE_load_chil(void); | ||
28 | void ENGINE_load_atalla(void); | ||
29 | void ENGINE_load_nuron(void); | ||
30 | void ENGINE_load_ubsec(void); | ||
31 | void ENGINE_load_aep(void); | ||
32 | void ENGINE_load_sureware(void); | ||
33 | void ENGINE_load_4758cca(void); | ||
34 | void ENGINE_load_openbsd_dev_crypto(void); | ||
35 | void ENGINE_load_builtin_engines(void); | ||
36 | |||
37 | void ENGINE_cleanup(void); | ||
38 | |||
39 | ENGINE *ENGINE_get_default_RSA(void); | ||
40 | ENGINE *ENGINE_get_default_DSA(void); | ||
41 | ENGINE *ENGINE_get_default_DH(void); | ||
42 | ENGINE *ENGINE_get_default_RAND(void); | ||
43 | ENGINE *ENGINE_get_cipher_engine(int nid); | ||
44 | ENGINE *ENGINE_get_digest_engine(int nid); | ||
45 | |||
46 | int ENGINE_set_default_RSA(ENGINE *e); | ||
47 | int ENGINE_set_default_DSA(ENGINE *e); | ||
48 | int ENGINE_set_default_DH(ENGINE *e); | ||
49 | int ENGINE_set_default_RAND(ENGINE *e); | ||
50 | int ENGINE_set_default_ciphers(ENGINE *e); | ||
51 | int ENGINE_set_default_digests(ENGINE *e); | ||
52 | int ENGINE_set_default_string(ENGINE *e, const char *list); | ||
53 | |||
54 | int ENGINE_set_default(ENGINE *e, unsigned int flags); | ||
55 | |||
56 | unsigned int ENGINE_get_table_flags(void); | ||
57 | void ENGINE_set_table_flags(unsigned int flags); | ||
58 | |||
59 | int ENGINE_register_RSA(ENGINE *e); | ||
60 | void ENGINE_unregister_RSA(ENGINE *e); | ||
61 | void ENGINE_register_all_RSA(void); | ||
62 | int ENGINE_register_DSA(ENGINE *e); | ||
63 | void ENGINE_unregister_DSA(ENGINE *e); | ||
64 | void ENGINE_register_all_DSA(void); | ||
65 | int ENGINE_register_DH(ENGINE *e); | ||
66 | void ENGINE_unregister_DH(ENGINE *e); | ||
67 | void ENGINE_register_all_DH(void); | ||
68 | int ENGINE_register_RAND(ENGINE *e); | ||
69 | void ENGINE_unregister_RAND(ENGINE *e); | ||
70 | void ENGINE_register_all_RAND(void); | ||
71 | int ENGINE_register_ciphers(ENGINE *e); | ||
72 | void ENGINE_unregister_ciphers(ENGINE *e); | ||
73 | void ENGINE_register_all_ciphers(void); | ||
74 | int ENGINE_register_digests(ENGINE *e); | ||
75 | void ENGINE_unregister_digests(ENGINE *e); | ||
76 | void ENGINE_register_all_digests(void); | ||
77 | int ENGINE_register_complete(ENGINE *e); | ||
78 | int ENGINE_register_all_complete(void); | ||
79 | |||
80 | int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); | ||
81 | int ENGINE_cmd_is_executable(ENGINE *e, int cmd); | ||
82 | int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, | ||
83 | long i, void *p, void (*f)(), int cmd_optional); | ||
84 | int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg, | ||
85 | int cmd_optional); | ||
86 | |||
87 | int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg); | ||
88 | void *ENGINE_get_ex_data(const ENGINE *e, int idx); | ||
89 | |||
90 | int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
91 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
92 | |||
93 | ENGINE *ENGINE_new(void); | ||
94 | int ENGINE_free(ENGINE *e); | ||
95 | |||
96 | int ENGINE_set_id(ENGINE *e, const char *id); | ||
97 | int ENGINE_set_name(ENGINE *e, const char *name); | ||
98 | int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth); | ||
99 | int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth); | ||
100 | int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth); | ||
101 | int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth); | ||
102 | int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f); | ||
103 | int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f); | ||
104 | int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f); | ||
105 | int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f); | ||
106 | int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f); | ||
107 | int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f); | ||
108 | int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f); | ||
109 | int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f); | ||
110 | int ENGINE_set_flags(ENGINE *e, int flags); | ||
111 | int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns); | ||
112 | |||
113 | const char *ENGINE_get_id(const ENGINE *e); | ||
114 | const char *ENGINE_get_name(const ENGINE *e); | ||
115 | const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e); | ||
116 | const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e); | ||
117 | const DH_METHOD *ENGINE_get_DH(const ENGINE *e); | ||
118 | const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e); | ||
119 | ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e); | ||
120 | ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e); | ||
121 | ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e); | ||
122 | ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e); | ||
123 | ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e); | ||
124 | ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e); | ||
125 | ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e); | ||
126 | ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e); | ||
127 | const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid); | ||
128 | const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid); | ||
129 | int ENGINE_get_flags(const ENGINE *e); | ||
130 | const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e); | ||
131 | |||
132 | EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id, | ||
133 | UI_METHOD *ui_method, void *callback_data); | ||
134 | EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id, | ||
135 | UI_METHOD *ui_method, void *callback_data); | ||
136 | |||
137 | void ENGINE_add_conf_module(void); | ||
138 | |||
139 | =head1 DESCRIPTION | ||
140 | |||
141 | These functions create, manipulate, and use cryptographic modules in the | ||
142 | form of B<ENGINE> objects. These objects act as containers for | ||
143 | implementations of cryptographic algorithms, and support a | ||
144 | reference-counted mechanism to allow them to be dynamically loaded in and | ||
145 | out of the running application. | ||
146 | |||
147 | The cryptographic functionality that can be provided by an B<ENGINE> | ||
148 | implementation includes the following abstractions; | ||
149 | |||
150 | RSA_METHOD - for providing alternative RSA implementations | ||
151 | DSA_METHOD, DH_METHOD, RAND_METHOD - alternative DSA, DH, and RAND | ||
152 | EVP_CIPHER - potentially multiple cipher algorithms (indexed by 'nid') | ||
153 | EVP_DIGEST - potentially multiple hash algorithms (indexed by 'nid') | ||
154 | key-loading - loading public and/or private EVP_PKEY keys | ||
155 | |||
156 | =head2 Reference counting and handles | ||
157 | |||
158 | Due to the modular nature of the ENGINE API, pointers to ENGINEs need to be | ||
159 | treated as handles - ie. not only as pointers, but also as references to | ||
160 | the underlying ENGINE object. Ie. you should obtain a new reference when | ||
161 | making copies of an ENGINE pointer if the copies will be used (and | ||
162 | released) independantly. | ||
163 | |||
164 | ENGINE objects have two levels of reference-counting to match the way in | ||
165 | which the objects are used. At the most basic level, each ENGINE pointer is | ||
166 | inherently a B<structural> reference - you need a structural reference | ||
167 | simply to refer to the pointer value at all, as this kind of reference is | ||
168 | your guarantee that the structure can not be deallocated until you release | ||
169 | your reference. | ||
170 | |||
171 | However, a structural reference provides no guarantee that the ENGINE has | ||
172 | been initiliased to be usable to perform any of its cryptographic | ||
173 | implementations - and indeed it's quite possible that most ENGINEs will not | ||
174 | initialised at all on standard setups, as ENGINEs are typically used to | ||
175 | support specialised hardware. To use an ENGINE's functionality, you need a | ||
176 | B<functional> reference. This kind of reference can be considered a | ||
177 | specialised form of structural reference, because each functional reference | ||
178 | implicitly contains a structural reference as well - however to avoid | ||
179 | difficult-to-find programming bugs, it is recommended to treat the two | ||
180 | kinds of reference independantly. If you have a functional reference to an | ||
181 | ENGINE, you have a guarantee that the ENGINE has been initialised ready to | ||
182 | perform cryptographic operations and will not be uninitialised or cleaned | ||
183 | up until after you have released your reference. | ||
184 | |||
185 | We will discuss the two kinds of reference separately, including how to | ||
186 | tell which one you are dealing with at any given point in time (after all | ||
187 | they are both simply (ENGINE *) pointers, the difference is in the way they | ||
188 | are used). | ||
189 | |||
190 | =head3 Structural references | ||
191 | |||
192 | This basic type of reference is typically used for creating new ENGINEs | ||
193 | dynamically, iterating across OpenSSL's internal linked-list of loaded | ||
194 | ENGINEs, reading information about an ENGINE, etc. Essentially a structural | ||
195 | reference is sufficient if you only need to query or manipulate the data of | ||
196 | an ENGINE implementation rather than use its functionality. | ||
197 | |||
198 | The ENGINE_new() function returns a structural reference to a new (empty) | ||
199 | ENGINE object. Other than that, structural references come from return | ||
200 | values to various ENGINE API functions such as; ENGINE_by_id(), | ||
201 | ENGINE_get_first(), ENGINE_get_last(), ENGINE_get_next(), | ||
202 | ENGINE_get_prev(). All structural references should be released by a | ||
203 | corresponding to call to the ENGINE_free() function - the ENGINE object | ||
204 | itself will only actually be cleaned up and deallocated when the last | ||
205 | structural reference is released. | ||
206 | |||
207 | It should also be noted that many ENGINE API function calls that accept a | ||
208 | structural reference will internally obtain another reference - typically | ||
209 | this happens whenever the supplied ENGINE will be needed by OpenSSL after | ||
210 | the function has returned. Eg. the function to add a new ENGINE to | ||
211 | OpenSSL's internal list is ENGINE_add() - if this function returns success, | ||
212 | then OpenSSL will have stored a new structural reference internally so the | ||
213 | caller is still responsible for freeing their own reference with | ||
214 | ENGINE_free() when they are finished with it. In a similar way, some | ||
215 | functions will automatically release the structural reference passed to it | ||
216 | if part of the function's job is to do so. Eg. the ENGINE_get_next() and | ||
217 | ENGINE_get_prev() functions are used for iterating across the internal | ||
218 | ENGINE list - they will return a new structural reference to the next (or | ||
219 | previous) ENGINE in the list or NULL if at the end (or beginning) of the | ||
220 | list, but in either case the structural reference passed to the function is | ||
221 | released on behalf of the caller. | ||
222 | |||
223 | To clarify a particular function's handling of references, one should | ||
224 | always consult that function's documentation "man" page, or failing that | ||
225 | the openssl/engine.h header file includes some hints. | ||
226 | |||
227 | =head3 Functional references | ||
228 | |||
229 | As mentioned, functional references exist when the cryptographic | ||
230 | functionality of an ENGINE is required to be available. A functional | ||
231 | reference can be obtained in one of two ways; from an existing structural | ||
232 | reference to the required ENGINE, or by asking OpenSSL for the default | ||
233 | operational ENGINE for a given cryptographic purpose. | ||
234 | |||
235 | To obtain a functional reference from an existing structural reference, | ||
236 | call the ENGINE_init() function. This returns zero if the ENGINE was not | ||
237 | already operational and couldn't be successfully initialised (eg. lack of | ||
238 | system drivers, no special hardware attached, etc), otherwise it will | ||
239 | return non-zero to indicate that the ENGINE is now operational and will | ||
240 | have allocated a new B<functional> reference to the ENGINE. In this case, | ||
241 | the supplied ENGINE pointer is, from the point of the view of the caller, | ||
242 | both a structural reference and a functional reference - so if the caller | ||
243 | intends to use it as a functional reference it should free the structural | ||
244 | reference with ENGINE_free() first. If the caller wishes to use it only as | ||
245 | a structural reference (eg. if the ENGINE_init() call was simply to test if | ||
246 | the ENGINE seems available/online), then it should free the functional | ||
247 | reference; all functional references are released by the ENGINE_finish() | ||
248 | function. | ||
249 | |||
250 | The second way to get a functional reference is by asking OpenSSL for a | ||
251 | default implementation for a given task, eg. by ENGINE_get_default_RSA(), | ||
252 | ENGINE_get_default_cipher_engine(), etc. These are discussed in the next | ||
253 | section, though they are not usually required by application programmers as | ||
254 | they are used automatically when creating and using the relevant | ||
255 | algorithm-specific types in OpenSSL, such as RSA, DSA, EVP_CIPHER_CTX, etc. | ||
256 | |||
257 | =head2 Default implementations | ||
258 | |||
259 | For each supported abstraction, the ENGINE code maintains an internal table | ||
260 | of state to control which implementations are available for a given | ||
261 | abstraction and which should be used by default. These implementations are | ||
262 | registered in the tables separated-out by an 'nid' index, because | ||
263 | abstractions like EVP_CIPHER and EVP_DIGEST support many distinct | ||
264 | algorithms and modes - ENGINEs will support different numbers and | ||
265 | combinations of these. In the case of other abstractions like RSA, DSA, | ||
266 | etc, there is only one "algorithm" so all implementations implicitly | ||
267 | register using the same 'nid' index. ENGINEs can be B<registered> into | ||
268 | these tables to make themselves available for use automatically by the | ||
269 | various abstractions, eg. RSA. For illustrative purposes, we continue with | ||
270 | the RSA example, though all comments apply similarly to the other | ||
271 | abstractions (they each get their own table and linkage to the | ||
272 | corresponding section of openssl code). | ||
273 | |||
274 | When a new RSA key is being created, ie. in RSA_new_method(), a | ||
275 | "get_default" call will be made to the ENGINE subsystem to process the RSA | ||
276 | state table and return a functional reference to an initialised ENGINE | ||
277 | whose RSA_METHOD should be used. If no ENGINE should (or can) be used, it | ||
278 | will return NULL and the RSA key will operate with a NULL ENGINE handle by | ||
279 | using the conventional RSA implementation in OpenSSL (and will from then on | ||
280 | behave the way it used to before the ENGINE API existed - for details see | ||
281 | L<RSA_new_method(3)|RSA_new_method(3)>). | ||
282 | |||
283 | Each state table has a flag to note whether it has processed this | ||
284 | "get_default" query since the table was last modified, because to process | ||
285 | this question it must iterate across all the registered ENGINEs in the | ||
286 | table trying to initialise each of them in turn, in case one of them is | ||
287 | operational. If it returns a functional reference to an ENGINE, it will | ||
288 | also cache another reference to speed up processing future queries (without | ||
289 | needing to iterate across the table). Likewise, it will cache a NULL | ||
290 | response if no ENGINE was available so that future queries won't repeat the | ||
291 | same iteration unless the state table changes. This behaviour can also be | ||
292 | changed; if the ENGINE_TABLE_FLAG_NOINIT flag is set (using | ||
293 | ENGINE_set_table_flags()), no attempted initialisations will take place, | ||
294 | instead the only way for the state table to return a non-NULL ENGINE to the | ||
295 | "get_default" query will be if one is expressly set in the table. Eg. | ||
296 | ENGINE_set_default_RSA() does the same job as ENGINE_register_RSA() except | ||
297 | that it also sets the state table's cached response for the "get_default" | ||
298 | query. | ||
299 | |||
300 | In the case of abstractions like EVP_CIPHER, where implementations are | ||
301 | indexed by 'nid', these flags and cached-responses are distinct for each | ||
302 | 'nid' value. | ||
303 | |||
304 | It is worth illustrating the difference between "registration" of ENGINEs | ||
305 | into these per-algorithm state tables and using the alternative | ||
306 | "set_default" functions. The latter handles both "registration" and also | ||
307 | setting the cached "default" ENGINE in each relevant state table - so | ||
308 | registered ENGINEs will only have a chance to be initialised for use as a | ||
309 | default if a default ENGINE wasn't already set for the same state table. | ||
310 | Eg. if ENGINE X supports cipher nids {A,B} and RSA, ENGINE Y supports | ||
311 | ciphers {A} and DSA, and the following code is executed; | ||
312 | |||
313 | ENGINE_register_complete(X); | ||
314 | ENGINE_set_default(Y, ENGINE_METHOD_ALL); | ||
315 | e1 = ENGINE_get_default_RSA(); | ||
316 | e2 = ENGINE_get_cipher_engine(A); | ||
317 | e3 = ENGINE_get_cipher_engine(B); | ||
318 | e4 = ENGINE_get_default_DSA(); | ||
319 | e5 = ENGINE_get_cipher_engine(C); | ||
320 | |||
321 | The results would be as follows; | ||
322 | |||
323 | assert(e1 == X); | ||
324 | assert(e2 == Y); | ||
325 | assert(e3 == X); | ||
326 | assert(e4 == Y); | ||
327 | assert(e5 == NULL); | ||
328 | |||
329 | =head2 Application requirements | ||
330 | |||
331 | This section will explain the basic things an application programmer should | ||
332 | support to make the most useful elements of the ENGINE functionality | ||
333 | available to the user. The first thing to consider is whether the | ||
334 | programmer wishes to make alternative ENGINE modules available to the | ||
335 | application and user. OpenSSL maintains an internal linked list of | ||
336 | "visible" ENGINEs from which it has to operate - at start-up, this list is | ||
337 | empty and in fact if an application does not call any ENGINE API calls and | ||
338 | it uses static linking against openssl, then the resulting application | ||
339 | binary will not contain any alternative ENGINE code at all. So the first | ||
340 | consideration is whether any/all available ENGINE implementations should be | ||
341 | made visible to OpenSSL - this is controlled by calling the various "load" | ||
342 | functions, eg. | ||
343 | |||
344 | /* Make the "dynamic" ENGINE available */ | ||
345 | void ENGINE_load_dynamic(void); | ||
346 | /* Make the CryptoSwift hardware acceleration support available */ | ||
347 | void ENGINE_load_cswift(void); | ||
348 | /* Make support for nCipher's "CHIL" hardware available */ | ||
349 | void ENGINE_load_chil(void); | ||
350 | ... | ||
351 | /* Make ALL ENGINE implementations bundled with OpenSSL available */ | ||
352 | void ENGINE_load_builtin_engines(void); | ||
353 | |||
354 | Having called any of these functions, ENGINE objects would have been | ||
355 | dynamically allocated and populated with these implementations and linked | ||
356 | into OpenSSL's internal linked list. At this point it is important to | ||
357 | mention an important API function; | ||
358 | |||
359 | void ENGINE_cleanup(void); | ||
360 | |||
361 | If no ENGINE API functions are called at all in an application, then there | ||
362 | are no inherent memory leaks to worry about from the ENGINE functionality, | ||
363 | however if any ENGINEs are "load"ed, even if they are never registered or | ||
364 | used, it is necessary to use the ENGINE_cleanup() function to | ||
365 | correspondingly cleanup before program exit, if the caller wishes to avoid | ||
366 | memory leaks. This mechanism uses an internal callback registration table | ||
367 | so that any ENGINE API functionality that knows it requires cleanup can | ||
368 | register its cleanup details to be called during ENGINE_cleanup(). This | ||
369 | approach allows ENGINE_cleanup() to clean up after any ENGINE functionality | ||
370 | at all that your program uses, yet doesn't automatically create linker | ||
371 | dependencies to all possible ENGINE functionality - only the cleanup | ||
372 | callbacks required by the functionality you do use will be required by the | ||
373 | linker. | ||
374 | |||
375 | The fact that ENGINEs are made visible to OpenSSL (and thus are linked into | ||
376 | the program and loaded into memory at run-time) does not mean they are | ||
377 | "registered" or called into use by OpenSSL automatically - that behaviour | ||
378 | is something for the application to have control over. Some applications | ||
379 | will want to allow the user to specify exactly which ENGINE they want used | ||
380 | if any is to be used at all. Others may prefer to load all support and have | ||
381 | OpenSSL automatically use at run-time any ENGINE that is able to | ||
382 | successfully initialise - ie. to assume that this corresponds to | ||
383 | acceleration hardware attached to the machine or some such thing. There are | ||
384 | probably numerous other ways in which applications may prefer to handle | ||
385 | things, so we will simply illustrate the consequences as they apply to a | ||
386 | couple of simple cases and leave developers to consider these and the | ||
387 | source code to openssl's builtin utilities as guides. | ||
388 | |||
389 | =head3 Using a specific ENGINE implementation | ||
390 | |||
391 | Here we'll assume an application has been configured by its user or admin | ||
392 | to want to use the "ACME" ENGINE if it is available in the version of | ||
393 | OpenSSL the application was compiled with. If it is available, it should be | ||
394 | used by default for all RSA, DSA, and symmetric cipher operation, otherwise | ||
395 | OpenSSL should use its builtin software as per usual. The following code | ||
396 | illustrates how to approach this; | ||
397 | |||
398 | ENGINE *e; | ||
399 | const char *engine_id = "ACME"; | ||
400 | ENGINE_load_builtin_engines(); | ||
401 | e = ENGINE_by_id(engine_id); | ||
402 | if(!e) | ||
403 | /* the engine isn't available */ | ||
404 | return; | ||
405 | if(!ENGINE_init(e)) { | ||
406 | /* the engine couldn't initialise, release 'e' */ | ||
407 | ENGINE_free(e); | ||
408 | return; | ||
409 | } | ||
410 | if(!ENGINE_set_default_RSA(e)) | ||
411 | /* This should only happen when 'e' can't initialise, but the previous | ||
412 | * statement suggests it did. */ | ||
413 | abort(); | ||
414 | ENGINE_set_default_DSA(e); | ||
415 | ENGINE_set_default_ciphers(e); | ||
416 | /* Release the functional reference from ENGINE_init() */ | ||
417 | ENGINE_finish(e); | ||
418 | /* Release the structural reference from ENGINE_by_id() */ | ||
419 | ENGINE_free(e); | ||
420 | |||
421 | =head3 Automatically using builtin ENGINE implementations | ||
422 | |||
423 | Here we'll assume we want to load and register all ENGINE implementations | ||
424 | bundled with OpenSSL, such that for any cryptographic algorithm required by | ||
425 | OpenSSL - if there is an ENGINE that implements it and can be initialise, | ||
426 | it should be used. The following code illustrates how this can work; | ||
427 | |||
428 | /* Load all bundled ENGINEs into memory and make them visible */ | ||
429 | ENGINE_load_builtin_engines(); | ||
430 | /* Register all of them for every algorithm they collectively implement */ | ||
431 | ENGINE_register_all_complete(); | ||
432 | |||
433 | That's all that's required. Eg. the next time OpenSSL tries to set up an | ||
434 | RSA key, any bundled ENGINEs that implement RSA_METHOD will be passed to | ||
435 | ENGINE_init() and if any of those succeed, that ENGINE will be set as the | ||
436 | default for use with RSA from then on. | ||
437 | |||
438 | =head2 Advanced configuration support | ||
439 | |||
440 | There is a mechanism supported by the ENGINE framework that allows each | ||
441 | ENGINE implementation to define an arbitrary set of configuration | ||
442 | "commands" and expose them to OpenSSL and any applications based on | ||
443 | OpenSSL. This mechanism is entirely based on the use of name-value pairs | ||
444 | and and assumes ASCII input (no unicode or UTF for now!), so it is ideal if | ||
445 | applications want to provide a transparent way for users to provide | ||
446 | arbitrary configuration "directives" directly to such ENGINEs. It is also | ||
447 | possible for the application to dynamically interrogate the loaded ENGINE | ||
448 | implementations for the names, descriptions, and input flags of their | ||
449 | available "control commands", providing a more flexible configuration | ||
450 | scheme. However, if the user is expected to know which ENGINE device he/she | ||
451 | is using (in the case of specialised hardware, this goes without saying) | ||
452 | then applications may not need to concern themselves with discovering the | ||
453 | supported control commands and simply prefer to allow settings to passed | ||
454 | into ENGINEs exactly as they are provided by the user. | ||
455 | |||
456 | Before illustrating how control commands work, it is worth mentioning what | ||
457 | they are typically used for. Broadly speaking there are two uses for | ||
458 | control commands; the first is to provide the necessary details to the | ||
459 | implementation (which may know nothing at all specific to the host system) | ||
460 | so that it can be initialised for use. This could include the path to any | ||
461 | driver or config files it needs to load, required network addresses, | ||
462 | smart-card identifiers, passwords to initialise password-protected devices, | ||
463 | logging information, etc etc. This class of commands typically needs to be | ||
464 | passed to an ENGINE B<before> attempting to initialise it, ie. before | ||
465 | calling ENGINE_init(). The other class of commands consist of settings or | ||
466 | operations that tweak certain behaviour or cause certain operations to take | ||
467 | place, and these commands may work either before or after ENGINE_init(), or | ||
468 | in same cases both. ENGINE implementations should provide indications of | ||
469 | this in the descriptions attached to builtin control commands and/or in | ||
470 | external product documentation. | ||
471 | |||
472 | =head3 Issuing control commands to an ENGINE | ||
473 | |||
474 | Let's illustrate by example; a function for which the caller supplies the | ||
475 | name of the ENGINE it wishes to use, a table of string-pairs for use before | ||
476 | initialisation, and another table for use after initialisation. Note that | ||
477 | the string-pairs used for control commands consist of a command "name" | ||
478 | followed by the command "parameter" - the parameter could be NULL in some | ||
479 | cases but the name can not. This function should initialise the ENGINE | ||
480 | (issuing the "pre" commands beforehand and the "post" commands afterwards) | ||
481 | and set it as the default for everything except RAND and then return a | ||
482 | boolean success or failure. | ||
483 | |||
484 | int generic_load_engine_fn(const char *engine_id, | ||
485 | const char **pre_cmds, int pre_num, | ||
486 | const char **post_cmds, int post_num) | ||
487 | { | ||
488 | ENGINE *e = ENGINE_by_id(engine_id); | ||
489 | if(!e) return 0; | ||
490 | while(pre_num--) { | ||
491 | if(!ENGINE_ctrl_cmd_string(e, pre_cmds[0], pre_cmds[1], 0)) { | ||
492 | fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id, | ||
493 | pre_cmds[0], pre_cmds[1] ? pre_cmds[1] : "(NULL)"); | ||
494 | ENGINE_free(e); | ||
495 | return 0; | ||
496 | } | ||
497 | pre_cmds += 2; | ||
498 | } | ||
499 | if(!ENGINE_init(e)) { | ||
500 | fprintf(stderr, "Failed initialisation\n"); | ||
501 | ENGINE_free(e); | ||
502 | return 0; | ||
503 | } | ||
504 | /* ENGINE_init() returned a functional reference, so free the structural | ||
505 | * reference from ENGINE_by_id(). */ | ||
506 | ENGINE_free(e); | ||
507 | while(post_num--) { | ||
508 | if(!ENGINE_ctrl_cmd_string(e, post_cmds[0], post_cmds[1], 0)) { | ||
509 | fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id, | ||
510 | post_cmds[0], post_cmds[1] ? post_cmds[1] : "(NULL)"); | ||
511 | ENGINE_finish(e); | ||
512 | return 0; | ||
513 | } | ||
514 | post_cmds += 2; | ||
515 | } | ||
516 | ENGINE_set_default(e, ENGINE_METHOD_ALL & ~ENGINE_METHOD_RAND); | ||
517 | /* Success */ | ||
518 | return 1; | ||
519 | } | ||
520 | |||
521 | Note that ENGINE_ctrl_cmd_string() accepts a boolean argument that can | ||
522 | relax the semantics of the function - if set non-zero it will only return | ||
523 | failure if the ENGINE supported the given command name but failed while | ||
524 | executing it, if the ENGINE doesn't support the command name it will simply | ||
525 | return success without doing anything. In this case we assume the user is | ||
526 | only supplying commands specific to the given ENGINE so we set this to | ||
527 | FALSE. | ||
528 | |||
529 | =head3 Discovering supported control commands | ||
530 | |||
531 | It is possible to discover at run-time the names, numerical-ids, descriptions | ||
532 | and input parameters of the control commands supported from a structural | ||
533 | reference to any ENGINE. It is first important to note that some control | ||
534 | commands are defined by OpenSSL itself and it will intercept and handle these | ||
535 | control commands on behalf of the ENGINE, ie. the ENGINE's ctrl() handler is not | ||
536 | used for the control command. openssl/engine.h defines a symbol, | ||
537 | ENGINE_CMD_BASE, that all control commands implemented by ENGINEs from. Any | ||
538 | command value lower than this symbol is considered a "generic" command is | ||
539 | handled directly by the OpenSSL core routines. | ||
540 | |||
541 | It is using these "core" control commands that one can discover the the control | ||
542 | commands implemented by a given ENGINE, specifically the commands; | ||
543 | |||
544 | #define ENGINE_HAS_CTRL_FUNCTION 10 | ||
545 | #define ENGINE_CTRL_GET_FIRST_CMD_TYPE 11 | ||
546 | #define ENGINE_CTRL_GET_NEXT_CMD_TYPE 12 | ||
547 | #define ENGINE_CTRL_GET_CMD_FROM_NAME 13 | ||
548 | #define ENGINE_CTRL_GET_NAME_LEN_FROM_CMD 14 | ||
549 | #define ENGINE_CTRL_GET_NAME_FROM_CMD 15 | ||
550 | #define ENGINE_CTRL_GET_DESC_LEN_FROM_CMD 16 | ||
551 | #define ENGINE_CTRL_GET_DESC_FROM_CMD 17 | ||
552 | #define ENGINE_CTRL_GET_CMD_FLAGS 18 | ||
553 | |||
554 | Whilst these commands are automatically processed by the OpenSSL framework code, | ||
555 | they use various properties exposed by each ENGINE by which to process these | ||
556 | queries. An ENGINE has 3 properties it exposes that can affect this behaviour; | ||
557 | it can supply a ctrl() handler, it can specify ENGINE_FLAGS_MANUAL_CMD_CTRL in | ||
558 | the ENGINE's flags, and it can expose an array of control command descriptions. | ||
559 | If an ENGINE specifies the ENGINE_FLAGS_MANUAL_CMD_CTRL flag, then it will | ||
560 | simply pass all these "core" control commands directly to the ENGINE's ctrl() | ||
561 | handler (and thus, it must have supplied one), so it is up to the ENGINE to | ||
562 | reply to these "discovery" commands itself. If that flag is not set, then the | ||
563 | OpenSSL framework code will work with the following rules; | ||
564 | |||
565 | if no ctrl() handler supplied; | ||
566 | ENGINE_HAS_CTRL_FUNCTION returns FALSE (zero), | ||
567 | all other commands fail. | ||
568 | if a ctrl() handler was supplied but no array of control commands; | ||
569 | ENGINE_HAS_CTRL_FUNCTION returns TRUE, | ||
570 | all other commands fail. | ||
571 | if a ctrl() handler and array of control commands was supplied; | ||
572 | ENGINE_HAS_CTRL_FUNCTION returns TRUE, | ||
573 | all other commands proceed processing ... | ||
574 | |||
575 | If the ENGINE's array of control commands is empty then all other commands will | ||
576 | fail, otherwise; ENGINE_CTRL_GET_FIRST_CMD_TYPE returns the identifier of | ||
577 | the first command supported by the ENGINE, ENGINE_GET_NEXT_CMD_TYPE takes the | ||
578 | identifier of a command supported by the ENGINE and returns the next command | ||
579 | identifier or fails if there are no more, ENGINE_CMD_FROM_NAME takes a string | ||
580 | name for a command and returns the corresponding identifier or fails if no such | ||
581 | command name exists, and the remaining commands take a command identifier and | ||
582 | return properties of the corresponding commands. All except | ||
583 | ENGINE_CTRL_GET_FLAGS return the string length of a command name or description, | ||
584 | or populate a supplied character buffer with a copy of the command name or | ||
585 | description. ENGINE_CTRL_GET_FLAGS returns a bitwise-OR'd mask of the following | ||
586 | possible values; | ||
587 | |||
588 | #define ENGINE_CMD_FLAG_NUMERIC (unsigned int)0x0001 | ||
589 | #define ENGINE_CMD_FLAG_STRING (unsigned int)0x0002 | ||
590 | #define ENGINE_CMD_FLAG_NO_INPUT (unsigned int)0x0004 | ||
591 | #define ENGINE_CMD_FLAG_INTERNAL (unsigned int)0x0008 | ||
592 | |||
593 | If the ENGINE_CMD_FLAG_INTERNAL flag is set, then any other flags are purely | ||
594 | informational to the caller - this flag will prevent the command being usable | ||
595 | for any higher-level ENGINE functions such as ENGINE_ctrl_cmd_string(). | ||
596 | "INTERNAL" commands are not intended to be exposed to text-based configuration | ||
597 | by applications, administrations, users, etc. These can support arbitrary | ||
598 | operations via ENGINE_ctrl(), including passing to and/or from the control | ||
599 | commands data of any arbitrary type. These commands are supported in the | ||
600 | discovery mechanisms simply to allow applications determinie if an ENGINE | ||
601 | supports certain specific commands it might want to use (eg. application "foo" | ||
602 | might query various ENGINEs to see if they implement "FOO_GET_VENDOR_LOGO_GIF" - | ||
603 | and ENGINE could therefore decide whether or not to support this "foo"-specific | ||
604 | extension). | ||
605 | |||
606 | =head2 Future developments | ||
607 | |||
608 | The ENGINE API and internal architecture is currently being reviewed. Slated for | ||
609 | possible release in 0.9.8 is support for transparent loading of "dynamic" | ||
610 | ENGINEs (built as self-contained shared-libraries). This would allow ENGINE | ||
611 | implementations to be provided independantly of OpenSSL libraries and/or | ||
612 | OpenSSL-based applications, and would also remove any requirement for | ||
613 | applications to explicitly use the "dynamic" ENGINE to bind to shared-library | ||
614 | implementations. | ||
615 | |||
616 | =head1 SEE ALSO | ||
617 | |||
618 | L<rsa(3)|rsa(3)>, L<dsa(3)|dsa(3)>, L<dh(3)|dh(3)>, L<rand(3)|rand(3)>, | ||
619 | L<RSA_new_method(3)|RSA_new_method(3)> | ||
620 | |||
621 | =cut | ||
diff --git a/src/lib/libcrypto/doc/evp.pod b/src/lib/libcrypto/doc/evp.pod index edf47dbde6..b3ca14314f 100644 --- a/src/lib/libcrypto/doc/evp.pod +++ b/src/lib/libcrypto/doc/evp.pod | |||
@@ -24,6 +24,13 @@ functions. The B<EVP_Digest>I<...> functions provide message digests. | |||
24 | 24 | ||
25 | Algorithms are loaded with OpenSSL_add_all_algorithms(3). | 25 | Algorithms are loaded with OpenSSL_add_all_algorithms(3). |
26 | 26 | ||
27 | All the symmetric algorithms (ciphers) and digests can be replaced by ENGINE | ||
28 | modules providing alternative implementations. If ENGINE implementations of | ||
29 | ciphers or digests are registered as defaults, then the various EVP functions | ||
30 | will automatically use those implementations automatically in preference to | ||
31 | built in software implementations. For more information, consult the engine(3) | ||
32 | man page. | ||
33 | |||
27 | =head1 SEE ALSO | 34 | =head1 SEE ALSO |
28 | 35 | ||
29 | L<EVP_DigestInit(3)|EVP_DigestInit(3)>, | 36 | L<EVP_DigestInit(3)|EVP_DigestInit(3)>, |
@@ -32,6 +39,7 @@ L<EVP_OpenInit(3)|EVP_OpenInit(3)>, | |||
32 | L<EVP_SealInit(3)|EVP_SealInit(3)>, | 39 | L<EVP_SealInit(3)|EVP_SealInit(3)>, |
33 | L<EVP_SignInit(3)|EVP_SignInit(3)>, | 40 | L<EVP_SignInit(3)|EVP_SignInit(3)>, |
34 | L<EVP_VerifyInit(3)|EVP_VerifyInit(3)>, | 41 | L<EVP_VerifyInit(3)|EVP_VerifyInit(3)>, |
35 | L<OpenSSL_add_all_algorithms(3)|OpenSSL_add_all_algorithms(3)> | 42 | L<OpenSSL_add_all_algorithms(3)|OpenSSL_add_all_algorithms(3)>, |
43 | L<engine(3)|engine(3)> | ||
36 | 44 | ||
37 | =cut | 45 | =cut |
diff --git a/src/lib/libcrypto/doc/rsa.pod b/src/lib/libcrypto/doc/rsa.pod index 2b93a12b65..45ac53ffc1 100644 --- a/src/lib/libcrypto/doc/rsa.pod +++ b/src/lib/libcrypto/doc/rsa.pod | |||
@@ -16,13 +16,17 @@ rsa - RSA public key cryptosystem | |||
16 | unsigned char *to, RSA *rsa, int padding); | 16 | unsigned char *to, RSA *rsa, int padding); |
17 | int RSA_private_decrypt(int flen, unsigned char *from, | 17 | int RSA_private_decrypt(int flen, unsigned char *from, |
18 | unsigned char *to, RSA *rsa, int padding); | 18 | unsigned char *to, RSA *rsa, int padding); |
19 | int RSA_private_encrypt(int flen, unsigned char *from, | ||
20 | unsigned char *to, RSA *rsa,int padding); | ||
21 | int RSA_public_decrypt(int flen, unsigned char *from, | ||
22 | unsigned char *to, RSA *rsa,int padding); | ||
19 | 23 | ||
20 | int RSA_sign(int type, unsigned char *m, unsigned int m_len, | 24 | int RSA_sign(int type, unsigned char *m, unsigned int m_len, |
21 | unsigned char *sigret, unsigned int *siglen, RSA *rsa); | 25 | unsigned char *sigret, unsigned int *siglen, RSA *rsa); |
22 | int RSA_verify(int type, unsigned char *m, unsigned int m_len, | 26 | int RSA_verify(int type, unsigned char *m, unsigned int m_len, |
23 | unsigned char *sigbuf, unsigned int siglen, RSA *rsa); | 27 | unsigned char *sigbuf, unsigned int siglen, RSA *rsa); |
24 | 28 | ||
25 | int RSA_size(RSA *rsa); | 29 | int RSA_size(const RSA *rsa); |
26 | 30 | ||
27 | RSA *RSA_generate_key(int num, unsigned long e, | 31 | RSA *RSA_generate_key(int num, unsigned long e, |
28 | void (*callback)(int,int,void *), void *cb_arg); | 32 | void (*callback)(int,int,void *), void *cb_arg); |
@@ -32,13 +36,13 @@ rsa - RSA public key cryptosystem | |||
32 | int RSA_blinding_on(RSA *rsa, BN_CTX *ctx); | 36 | int RSA_blinding_on(RSA *rsa, BN_CTX *ctx); |
33 | void RSA_blinding_off(RSA *rsa); | 37 | void RSA_blinding_off(RSA *rsa); |
34 | 38 | ||
35 | void RSA_set_default_openssl_method(RSA_METHOD *meth); | 39 | void RSA_set_default_method(const RSA_METHOD *meth); |
36 | RSA_METHOD *RSA_get_default_openssl_method(void); | 40 | const RSA_METHOD *RSA_get_default_method(void); |
37 | int RSA_set_method(RSA *rsa, ENGINE *engine); | 41 | int RSA_set_method(RSA *rsa, const RSA_METHOD *meth); |
38 | RSA_METHOD *RSA_get_method(RSA *rsa); | 42 | const RSA_METHOD *RSA_get_method(const RSA *rsa); |
39 | RSA_METHOD *RSA_PKCS1_SSLeay(void); | 43 | RSA_METHOD *RSA_PKCS1_SSLeay(void); |
40 | RSA_METHOD *RSA_null_method(void); | 44 | RSA_METHOD *RSA_null_method(void); |
41 | int RSA_flags(RSA *rsa); | 45 | int RSA_flags(const RSA *rsa); |
42 | RSA *RSA_new_method(ENGINE *engine); | 46 | RSA *RSA_new_method(ENGINE *engine); |
43 | 47 | ||
44 | int RSA_print(BIO *bp, RSA *x, int offset); | 48 | int RSA_print(BIO *bp, RSA *x, int offset); |
@@ -49,11 +53,6 @@ rsa - RSA public key cryptosystem | |||
49 | int RSA_set_ex_data(RSA *r,int idx,char *arg); | 53 | int RSA_set_ex_data(RSA *r,int idx,char *arg); |
50 | char *RSA_get_ex_data(RSA *r, int idx); | 54 | char *RSA_get_ex_data(RSA *r, int idx); |
51 | 55 | ||
52 | int RSA_private_encrypt(int flen, unsigned char *from, | ||
53 | unsigned char *to, RSA *rsa,int padding); | ||
54 | int RSA_public_decrypt(int flen, unsigned char *from, | ||
55 | unsigned char *to, RSA *rsa,int padding); | ||
56 | |||
57 | int RSA_sign_ASN1_OCTET_STRING(int dummy, unsigned char *m, | 56 | int RSA_sign_ASN1_OCTET_STRING(int dummy, unsigned char *m, |
58 | unsigned int m_len, unsigned char *sigret, unsigned int *siglen, | 57 | unsigned int m_len, unsigned char *sigret, unsigned int *siglen, |
59 | RSA *rsa); | 58 | RSA *rsa); |
@@ -90,6 +89,14 @@ B<p>, B<q>, B<dmp1>, B<dmq1> and B<iqmp> may be B<NULL> in private | |||
90 | keys, but the RSA operations are much faster when these values are | 89 | keys, but the RSA operations are much faster when these values are |
91 | available. | 90 | available. |
92 | 91 | ||
92 | Note that RSA keys may use non-standard B<RSA_METHOD> implementations, | ||
93 | either directly or by the use of B<ENGINE> modules. In some cases (eg. an | ||
94 | ENGINE providing support for hardware-embedded keys), these BIGNUM values | ||
95 | will not be used by the implementation or may be used for alternative data | ||
96 | storage. For this reason, applications should generally avoid using RSA | ||
97 | structure elements directly and instead use API functions to query or | ||
98 | modify keys. | ||
99 | |||
93 | =head1 CONFORMING TO | 100 | =head1 CONFORMING TO |
94 | 101 | ||
95 | SSL, PKCS #1 v2.0 | 102 | SSL, PKCS #1 v2.0 |
@@ -101,7 +108,7 @@ RSA was covered by a US patent which expired in September 2000. | |||
101 | =head1 SEE ALSO | 108 | =head1 SEE ALSO |
102 | 109 | ||
103 | L<rsa(1)|rsa(1)>, L<bn(3)|bn(3)>, L<dsa(3)|dsa(3)>, L<dh(3)|dh(3)>, | 110 | L<rsa(1)|rsa(1)>, L<bn(3)|bn(3)>, L<dsa(3)|dsa(3)>, L<dh(3)|dh(3)>, |
104 | L<rand(3)|rand(3)>, L<RSA_new(3)|RSA_new(3)>, | 111 | L<rand(3)|rand(3)>, L<engine(3)|engine(3)>, L<RSA_new(3)|RSA_new(3)>, |
105 | L<RSA_public_encrypt(3)|RSA_public_encrypt(3)>, | 112 | L<RSA_public_encrypt(3)|RSA_public_encrypt(3)>, |
106 | L<RSA_sign(3)|RSA_sign(3)>, L<RSA_size(3)|RSA_size(3)>, | 113 | L<RSA_sign(3)|RSA_sign(3)>, L<RSA_size(3)|RSA_size(3)>, |
107 | L<RSA_generate_key(3)|RSA_generate_key(3)>, | 114 | L<RSA_generate_key(3)|RSA_generate_key(3)>, |
diff --git a/src/lib/libcrypto/evp/evp_locl.h b/src/lib/libcrypto/evp/evp_locl.h index 7b088b4848..4d81a3bf4c 100644 --- a/src/lib/libcrypto/evp/evp_locl.h +++ b/src/lib/libcrypto/evp/evp_locl.h | |||
@@ -124,17 +124,17 @@ const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; } | |||
124 | BLOCK_CIPHER_def1(cname, cbc, cbc, CBC, kstruct, nid, block_size, key_len, \ | 124 | BLOCK_CIPHER_def1(cname, cbc, cbc, CBC, kstruct, nid, block_size, key_len, \ |
125 | iv_len, flags, init_key, cleanup, set_asn1, get_asn1, ctrl) | 125 | iv_len, flags, init_key, cleanup, set_asn1, get_asn1, ctrl) |
126 | 126 | ||
127 | #define BLOCK_CIPHER_def_cfb(cname, kstruct, nid, block_size, key_len, \ | 127 | #define BLOCK_CIPHER_def_cfb(cname, kstruct, nid, key_len, \ |
128 | iv_len, cbits, flags, init_key, cleanup, \ | 128 | iv_len, cbits, flags, init_key, cleanup, \ |
129 | set_asn1, get_asn1, ctrl) \ | 129 | set_asn1, get_asn1, ctrl) \ |
130 | BLOCK_CIPHER_def1(cname, cfb##cbits, cfb, CFB, kstruct, nid, block_size, \ | 130 | BLOCK_CIPHER_def1(cname, cfb##cbits, cfb, CFB, kstruct, nid, 1, \ |
131 | key_len, iv_len, flags, init_key, cleanup, set_asn1, \ | 131 | key_len, iv_len, flags, init_key, cleanup, set_asn1, \ |
132 | get_asn1, ctrl) | 132 | get_asn1, ctrl) |
133 | 133 | ||
134 | #define BLOCK_CIPHER_def_ofb(cname, kstruct, nid, block_size, key_len, \ | 134 | #define BLOCK_CIPHER_def_ofb(cname, kstruct, nid, key_len, \ |
135 | iv_len, cbits, flags, init_key, cleanup, \ | 135 | iv_len, cbits, flags, init_key, cleanup, \ |
136 | set_asn1, get_asn1, ctrl) \ | 136 | set_asn1, get_asn1, ctrl) \ |
137 | BLOCK_CIPHER_def1(cname, ofb##cbits, ofb, OFB, kstruct, nid, block_size, \ | 137 | BLOCK_CIPHER_def1(cname, ofb##cbits, ofb, OFB, kstruct, nid, 1, \ |
138 | key_len, iv_len, flags, init_key, cleanup, set_asn1, \ | 138 | key_len, iv_len, flags, init_key, cleanup, set_asn1, \ |
139 | get_asn1, ctrl) | 139 | get_asn1, ctrl) |
140 | 140 | ||
@@ -149,9 +149,9 @@ BLOCK_CIPHER_def1(cname, ecb, ecb, ECB, kstruct, nid, block_size, key_len, \ | |||
149 | init_key, cleanup, set_asn1, get_asn1, ctrl) \ | 149 | init_key, cleanup, set_asn1, get_asn1, ctrl) \ |
150 | BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, iv_len, flags, \ | 150 | BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, iv_len, flags, \ |
151 | init_key, cleanup, set_asn1, get_asn1, ctrl) \ | 151 | init_key, cleanup, set_asn1, get_asn1, ctrl) \ |
152 | BLOCK_CIPHER_def_cfb(cname, kstruct, nid, block_size, key_len, iv_len, cbits, \ | 152 | BLOCK_CIPHER_def_cfb(cname, kstruct, nid, key_len, iv_len, cbits, \ |
153 | flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \ | 153 | flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \ |
154 | BLOCK_CIPHER_def_ofb(cname, kstruct, nid, block_size, key_len, iv_len, cbits, \ | 154 | BLOCK_CIPHER_def_ofb(cname, kstruct, nid, key_len, iv_len, cbits, \ |
155 | flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \ | 155 | flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \ |
156 | BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, iv_len, flags, \ | 156 | BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, iv_len, flags, \ |
157 | init_key, cleanup, set_asn1, get_asn1, ctrl) | 157 | init_key, cleanup, set_asn1, get_asn1, ctrl) |
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c index 02c3719f04..ce779dc1b5 100644 --- a/src/lib/libcrypto/objects/obj_dat.c +++ b/src/lib/libcrypto/objects/obj_dat.c | |||
@@ -425,7 +425,7 @@ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name) | |||
425 | a2d_ASN1_OBJECT(p,i,s,-1); | 425 | a2d_ASN1_OBJECT(p,i,s,-1); |
426 | 426 | ||
427 | p=buf; | 427 | p=buf; |
428 | op=d2i_ASN1_OBJECT(NULL,&p,i); | 428 | op=d2i_ASN1_OBJECT(NULL,&p,j); |
429 | OPENSSL_free(buf); | 429 | OPENSSL_free(buf); |
430 | return op; | 430 | return op; |
431 | } | 431 | } |
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c index 18b751a91a..a8db6ffbf5 100644 --- a/src/lib/libcrypto/pem/pem_lib.c +++ b/src/lib/libcrypto/pem/pem_lib.c | |||
@@ -366,8 +366,11 @@ err: | |||
366 | memset(iv,0,sizeof(iv)); | 366 | memset(iv,0,sizeof(iv)); |
367 | memset((char *)&ctx,0,sizeof(ctx)); | 367 | memset((char *)&ctx,0,sizeof(ctx)); |
368 | memset(buf,0,PEM_BUFSIZE); | 368 | memset(buf,0,PEM_BUFSIZE); |
369 | memset(data,0,(unsigned int)dsize); | 369 | if (data != NULL) |
370 | OPENSSL_free(data); | 370 | { |
371 | memset(data,0,(unsigned int)dsize); | ||
372 | OPENSSL_free(data); | ||
373 | } | ||
371 | return(ret); | 374 | return(ret); |
372 | } | 375 | } |
373 | 376 | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_asn.c b/src/lib/libcrypto/pkcs12/p12_asn.c index c327bdba03..a3739fee1a 100644 --- a/src/lib/libcrypto/pkcs12/p12_asn.c +++ b/src/lib/libcrypto/pkcs12/p12_asn.c | |||
@@ -83,8 +83,8 @@ ASN1_ADB_TEMPLATE(bag_default) = ASN1_EXP(PKCS12_BAGS, value.other, ASN1_ANY, 0) | |||
83 | 83 | ||
84 | ASN1_ADB(PKCS12_BAGS) = { | 84 | ASN1_ADB(PKCS12_BAGS) = { |
85 | ADB_ENTRY(NID_x509Certificate, ASN1_EXP(PKCS12_BAGS, value.x509cert, ASN1_OCTET_STRING, 0)), | 85 | ADB_ENTRY(NID_x509Certificate, ASN1_EXP(PKCS12_BAGS, value.x509cert, ASN1_OCTET_STRING, 0)), |
86 | ADB_ENTRY(NID_x509Certificate, ASN1_EXP(PKCS12_BAGS, value.x509crl, ASN1_OCTET_STRING, 0)), | 86 | ADB_ENTRY(NID_x509Crl, ASN1_EXP(PKCS12_BAGS, value.x509crl, ASN1_OCTET_STRING, 0)), |
87 | ADB_ENTRY(NID_x509Certificate, ASN1_EXP(PKCS12_BAGS, value.sdsicert, ASN1_IA5STRING, 0)), | 87 | ADB_ENTRY(NID_sdsiCertificate, ASN1_EXP(PKCS12_BAGS, value.sdsicert, ASN1_IA5STRING, 0)), |
88 | } ASN1_ADB_END(PKCS12_BAGS, 0, type, 0, &bag_default_tt, NULL); | 88 | } ASN1_ADB_END(PKCS12_BAGS, 0, type, 0, &bag_default_tt, NULL); |
89 | 89 | ||
90 | ASN1_SEQUENCE(PKCS12_BAGS) = { | 90 | ASN1_SEQUENCE(PKCS12_BAGS) = { |
@@ -98,7 +98,7 @@ ASN1_ADB_TEMPLATE(safebag_default) = ASN1_EXP(PKCS12_SAFEBAG, value.other, ASN1_ | |||
98 | 98 | ||
99 | ASN1_ADB(PKCS12_SAFEBAG) = { | 99 | ASN1_ADB(PKCS12_SAFEBAG) = { |
100 | ADB_ENTRY(NID_keyBag, ASN1_EXP(PKCS12_SAFEBAG, value.keybag, PKCS8_PRIV_KEY_INFO, 0)), | 100 | ADB_ENTRY(NID_keyBag, ASN1_EXP(PKCS12_SAFEBAG, value.keybag, PKCS8_PRIV_KEY_INFO, 0)), |
101 | ADB_ENTRY(NID_pkcs8ShroudedKeyBag, ASN1_EXP(PKCS12_SAFEBAG, value.keybag, X509_SIG, 0)), | 101 | ADB_ENTRY(NID_pkcs8ShroudedKeyBag, ASN1_EXP(PKCS12_SAFEBAG, value.shkeybag, X509_SIG, 0)), |
102 | ADB_ENTRY(NID_safeContentsBag, ASN1_EXP_SET_OF(PKCS12_SAFEBAG, value.safes, PKCS12_SAFEBAG, 0)), | 102 | ADB_ENTRY(NID_safeContentsBag, ASN1_EXP_SET_OF(PKCS12_SAFEBAG, value.safes, PKCS12_SAFEBAG, 0)), |
103 | ADB_ENTRY(NID_certBag, ASN1_EXP(PKCS12_SAFEBAG, value.bag, PKCS12_BAGS, 0)), | 103 | ADB_ENTRY(NID_certBag, ASN1_EXP(PKCS12_SAFEBAG, value.bag, PKCS12_BAGS, 0)), |
104 | ADB_ENTRY(NID_crlBag, ASN1_EXP(PKCS12_SAFEBAG, value.bag, PKCS12_BAGS, 0)), | 104 | ADB_ENTRY(NID_crlBag, ASN1_EXP(PKCS12_SAFEBAG, value.bag, PKCS12_BAGS, 0)), |
diff --git a/src/lib/libcrypto/pkcs7/pk7_lib.c b/src/lib/libcrypto/pkcs7/pk7_lib.c index c00ed6833a..985b07245c 100644 --- a/src/lib/libcrypto/pkcs7/pk7_lib.c +++ b/src/lib/libcrypto/pkcs7/pk7_lib.c | |||
@@ -74,6 +74,13 @@ long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg) | |||
74 | if (nid == NID_pkcs7_signed) | 74 | if (nid == NID_pkcs7_signed) |
75 | { | 75 | { |
76 | ret=p7->detached=(int)larg; | 76 | ret=p7->detached=(int)larg; |
77 | if (ret && PKCS7_type_is_data(p7->d.sign->contents)) | ||
78 | { | ||
79 | ASN1_OCTET_STRING *os; | ||
80 | os=p7->d.sign->contents->d.data; | ||
81 | ASN1_OCTET_STRING_free(os); | ||
82 | p7->d.sign->contents->d.data = NULL; | ||
83 | } | ||
77 | } | 84 | } |
78 | else | 85 | else |
79 | { | 86 | { |
diff --git a/src/lib/libcrypto/x509/x509.h b/src/lib/libcrypto/x509/x509.h index c75aa0c717..7095440d36 100644 --- a/src/lib/libcrypto/x509/x509.h +++ b/src/lib/libcrypto/x509/x509.h | |||
@@ -331,6 +331,7 @@ DECLARE_STACK_OF(X509_TRUST) | |||
331 | #define X509_FLAG_NO_EXTENSIONS (1L << 8) | 331 | #define X509_FLAG_NO_EXTENSIONS (1L << 8) |
332 | #define X509_FLAG_NO_SIGDUMP (1L << 9) | 332 | #define X509_FLAG_NO_SIGDUMP (1L << 9) |
333 | #define X509_FLAG_NO_AUX (1L << 10) | 333 | #define X509_FLAG_NO_AUX (1L << 10) |
334 | #define X509_FLAG_NO_ATTRIBUTES (1L << 11) | ||
334 | 335 | ||
335 | /* Flags specific to X509_NAME_print_ex() */ | 336 | /* Flags specific to X509_NAME_print_ex() */ |
336 | 337 | ||
@@ -1015,6 +1016,7 @@ int X509_print(BIO *bp,X509 *x); | |||
1015 | int X509_ocspid_print(BIO *bp,X509 *x); | 1016 | int X509_ocspid_print(BIO *bp,X509 *x); |
1016 | int X509_CERT_AUX_print(BIO *bp,X509_CERT_AUX *x, int indent); | 1017 | int X509_CERT_AUX_print(BIO *bp,X509_CERT_AUX *x, int indent); |
1017 | int X509_CRL_print(BIO *bp,X509_CRL *x); | 1018 | int X509_CRL_print(BIO *bp,X509_CRL *x); |
1019 | int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflag, unsigned long cflag); | ||
1018 | int X509_REQ_print(BIO *bp,X509_REQ *req); | 1020 | int X509_REQ_print(BIO *bp,X509_REQ *req); |
1019 | #endif | 1021 | #endif |
1020 | 1022 | ||
diff --git a/src/lib/libssl/doc/openssl.txt b/src/lib/libssl/doc/openssl.txt index 5da519e7e4..432a17b66c 100644 --- a/src/lib/libssl/doc/openssl.txt +++ b/src/lib/libssl/doc/openssl.txt | |||
@@ -344,7 +344,7 @@ the extension. | |||
344 | 344 | ||
345 | Examples: | 345 | Examples: |
346 | 346 | ||
347 | subjectAltName=email:copy,email:my@other.address,URL:http://my.url.here/ | 347 | subjectAltName=email:copy,email:my@other.address,URI:http://my.url.here/ |
348 | subjectAltName=email:my@other.address,RID:1.2.3.4 | 348 | subjectAltName=email:my@other.address,RID:1.2.3.4 |
349 | 349 | ||
350 | Issuer Alternative Name. | 350 | Issuer Alternative Name. |
diff --git a/src/lib/libssl/s3_clnt.c b/src/lib/libssl/s3_clnt.c index 2699b5863b..2b58482484 100644 --- a/src/lib/libssl/s3_clnt.c +++ b/src/lib/libssl/s3_clnt.c | |||
@@ -546,7 +546,11 @@ static int ssl3_client_hello(SSL *s) | |||
546 | *(p++)=i; | 546 | *(p++)=i; |
547 | if (i != 0) | 547 | if (i != 0) |
548 | { | 548 | { |
549 | die(i <= sizeof s->session->session_id); | 549 | if (i > sizeof s->session->session_id) |
550 | { | ||
551 | SSLerr(SSL_F_SSL3_CLIENT_HELLO, ERR_R_INTERNAL_ERROR); | ||
552 | goto err; | ||
553 | } | ||
550 | memcpy(p,s->session->session_id,i); | 554 | memcpy(p,s->session->session_id,i); |
551 | p+=i; | 555 | p+=i; |
552 | } | 556 | } |
@@ -1598,7 +1602,11 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
1598 | SSL_MAX_MASTER_KEY_LENGTH); | 1602 | SSL_MAX_MASTER_KEY_LENGTH); |
1599 | EVP_EncryptFinal_ex(&ciph_ctx,&(epms[outl]),&padl); | 1603 | EVP_EncryptFinal_ex(&ciph_ctx,&(epms[outl]),&padl); |
1600 | outl += padl; | 1604 | outl += padl; |
1601 | die(outl <= sizeof epms); | 1605 | if (outl > sizeof epms) |
1606 | { | ||
1607 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); | ||
1608 | goto err; | ||
1609 | } | ||
1602 | EVP_CIPHER_CTX_cleanup(&ciph_ctx); | 1610 | EVP_CIPHER_CTX_cleanup(&ciph_ctx); |
1603 | 1611 | ||
1604 | /* KerberosWrapper.EncryptedPreMasterSecret */ | 1612 | /* KerberosWrapper.EncryptedPreMasterSecret */ |
diff --git a/src/lib/libssl/s3_srvr.c b/src/lib/libssl/s3_srvr.c index 782b57f57a..20d716fb1b 100644 --- a/src/lib/libssl/s3_srvr.c +++ b/src/lib/libssl/s3_srvr.c | |||
@@ -965,7 +965,11 @@ static int ssl3_send_server_hello(SSL *s) | |||
965 | s->session->session_id_length=0; | 965 | s->session->session_id_length=0; |
966 | 966 | ||
967 | sl=s->session->session_id_length; | 967 | sl=s->session->session_id_length; |
968 | die(sl <= sizeof s->session->session_id); | 968 | if (sl > sizeof s->session->session_id) |
969 | { | ||
970 | SSLerr(SSL_F_SSL3_SEND_SERVER_HELLO, ERR_R_INTERNAL_ERROR); | ||
971 | return -1; | ||
972 | } | ||
969 | *(p++)=sl; | 973 | *(p++)=sl; |
970 | memcpy(p,s->session->session_id,sl); | 974 | memcpy(p,s->session->session_id,sl); |
971 | p+=sl; | 975 | p+=sl; |
@@ -1588,7 +1592,7 @@ static int ssl3_get_client_key_exchange(SSL *s) | |||
1588 | /* Note that the length is checked again below, | 1592 | /* Note that the length is checked again below, |
1589 | ** after decryption | 1593 | ** after decryption |
1590 | */ | 1594 | */ |
1591 | if(enc.pms_length > sizeof pms) | 1595 | if(enc_pms.length > sizeof pms) |
1592 | { | 1596 | { |
1593 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | 1597 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, |
1594 | SSL_R_DATA_LENGTH_TOO_LONG); | 1598 | SSL_R_DATA_LENGTH_TOO_LONG); |
diff --git a/src/lib/libssl/ssl.h b/src/lib/libssl/ssl.h index d9949e8eb2..e9d1e896d7 100644 --- a/src/lib/libssl/ssl.h +++ b/src/lib/libssl/ssl.h | |||
@@ -1462,6 +1462,7 @@ void ERR_load_SSL_strings(void); | |||
1462 | 1462 | ||
1463 | /* Function codes. */ | 1463 | /* Function codes. */ |
1464 | #define SSL_F_CLIENT_CERTIFICATE 100 | 1464 | #define SSL_F_CLIENT_CERTIFICATE 100 |
1465 | #define SSL_F_CLIENT_FINISHED 238 | ||
1465 | #define SSL_F_CLIENT_HELLO 101 | 1466 | #define SSL_F_CLIENT_HELLO 101 |
1466 | #define SSL_F_CLIENT_MASTER_KEY 102 | 1467 | #define SSL_F_CLIENT_MASTER_KEY 102 |
1467 | #define SSL_F_D2I_SSL_SESSION 103 | 1468 | #define SSL_F_D2I_SSL_SESSION 103 |
@@ -1475,7 +1476,9 @@ void ERR_load_SSL_strings(void); | |||
1475 | #define SSL_F_I2D_SSL_SESSION 111 | 1476 | #define SSL_F_I2D_SSL_SESSION 111 |
1476 | #define SSL_F_READ_N 112 | 1477 | #define SSL_F_READ_N 112 |
1477 | #define SSL_F_REQUEST_CERTIFICATE 113 | 1478 | #define SSL_F_REQUEST_CERTIFICATE 113 |
1479 | #define SSL_F_SERVER_FINISH 239 | ||
1478 | #define SSL_F_SERVER_HELLO 114 | 1480 | #define SSL_F_SERVER_HELLO 114 |
1481 | #define SSL_F_SERVER_VERIFY 240 | ||
1479 | #define SSL_F_SSL23_ACCEPT 115 | 1482 | #define SSL_F_SSL23_ACCEPT 115 |
1480 | #define SSL_F_SSL23_CLIENT_HELLO 116 | 1483 | #define SSL_F_SSL23_CLIENT_HELLO 116 |
1481 | #define SSL_F_SSL23_CONNECT 117 | 1484 | #define SSL_F_SSL23_CONNECT 117 |
@@ -1487,6 +1490,7 @@ void ERR_load_SSL_strings(void); | |||
1487 | #define SSL_F_SSL2_ACCEPT 122 | 1490 | #define SSL_F_SSL2_ACCEPT 122 |
1488 | #define SSL_F_SSL2_CONNECT 123 | 1491 | #define SSL_F_SSL2_CONNECT 123 |
1489 | #define SSL_F_SSL2_ENC_INIT 124 | 1492 | #define SSL_F_SSL2_ENC_INIT 124 |
1493 | #define SSL_F_SSL2_GENERATE_KEY_MATERIAL 241 | ||
1490 | #define SSL_F_SSL2_PEEK 234 | 1494 | #define SSL_F_SSL2_PEEK 234 |
1491 | #define SSL_F_SSL2_READ 125 | 1495 | #define SSL_F_SSL2_READ 125 |
1492 | #define SSL_F_SSL2_READ_INTERNAL 236 | 1496 | #define SSL_F_SSL2_READ_INTERNAL 236 |
@@ -1523,6 +1527,7 @@ void ERR_load_SSL_strings(void); | |||
1523 | #define SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE 152 | 1527 | #define SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE 152 |
1524 | #define SSL_F_SSL3_SEND_CLIENT_VERIFY 153 | 1528 | #define SSL_F_SSL3_SEND_CLIENT_VERIFY 153 |
1525 | #define SSL_F_SSL3_SEND_SERVER_CERTIFICATE 154 | 1529 | #define SSL_F_SSL3_SEND_SERVER_CERTIFICATE 154 |
1530 | #define SSL_F_SSL3_SEND_SERVER_HELLO 242 | ||
1526 | #define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE 155 | 1531 | #define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE 155 |
1527 | #define SSL_F_SSL3_SETUP_BUFFERS 156 | 1532 | #define SSL_F_SSL3_SETUP_BUFFERS 156 |
1528 | #define SSL_F_SSL3_SETUP_KEY_BLOCK 157 | 1533 | #define SSL_F_SSL3_SETUP_KEY_BLOCK 157 |
@@ -1747,6 +1752,7 @@ void ERR_load_SSL_strings(void); | |||
1747 | #define SSL_R_SHORT_READ 219 | 1752 | #define SSL_R_SHORT_READ 219 |
1748 | #define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 220 | 1753 | #define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 220 |
1749 | #define SSL_R_SSL23_DOING_SESSION_ID_REUSE 221 | 1754 | #define SSL_R_SSL23_DOING_SESSION_ID_REUSE 221 |
1755 | #define SSL_R_SSL2_CONNECTION_ID_TOO_LONG 1114 | ||
1750 | #define SSL_R_SSL3_SESSION_ID_TOO_LONG 1113 | 1756 | #define SSL_R_SSL3_SESSION_ID_TOO_LONG 1113 |
1751 | #define SSL_R_SSL3_SESSION_ID_TOO_SHORT 222 | 1757 | #define SSL_R_SSL3_SESSION_ID_TOO_SHORT 222 |
1752 | #define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042 | 1758 | #define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042 |
diff --git a/src/lib/libssl/ssl_asn1.c b/src/lib/libssl/ssl_asn1.c index 1638c6b525..3723fc2e37 100644 --- a/src/lib/libssl/ssl_asn1.c +++ b/src/lib/libssl/ssl_asn1.c | |||
@@ -294,10 +294,11 @@ SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, unsigned char **pp, | |||
294 | i=SSL2_MAX_SSL_SESSION_ID_LENGTH; | 294 | i=SSL2_MAX_SSL_SESSION_ID_LENGTH; |
295 | 295 | ||
296 | if (os.length > i) | 296 | if (os.length > i) |
297 | os.length=i; | 297 | os.length = i; |
298 | if (os.length > sizeof ret->session_id) /* can't happen */ | ||
299 | os.length = sizeof ret->session_id; | ||
298 | 300 | ||
299 | ret->session_id_length=os.length; | 301 | ret->session_id_length=os.length; |
300 | die(os.length <= sizeof ret->session_id); | ||
301 | memcpy(ret->session_id,os.data,os.length); | 302 | memcpy(ret->session_id,os.data,os.length); |
302 | 303 | ||
303 | M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING); | 304 | M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING); |
diff --git a/src/lib/libssl/ssl_err.c b/src/lib/libssl/ssl_err.c index 0cad32c855..7067a745f3 100644 --- a/src/lib/libssl/ssl_err.c +++ b/src/lib/libssl/ssl_err.c | |||
@@ -67,6 +67,7 @@ | |||
67 | static ERR_STRING_DATA SSL_str_functs[]= | 67 | static ERR_STRING_DATA SSL_str_functs[]= |
68 | { | 68 | { |
69 | {ERR_PACK(0,SSL_F_CLIENT_CERTIFICATE,0), "CLIENT_CERTIFICATE"}, | 69 | {ERR_PACK(0,SSL_F_CLIENT_CERTIFICATE,0), "CLIENT_CERTIFICATE"}, |
70 | {ERR_PACK(0,SSL_F_CLIENT_FINISHED,0), "CLIENT_FINISHED"}, | ||
70 | {ERR_PACK(0,SSL_F_CLIENT_HELLO,0), "CLIENT_HELLO"}, | 71 | {ERR_PACK(0,SSL_F_CLIENT_HELLO,0), "CLIENT_HELLO"}, |
71 | {ERR_PACK(0,SSL_F_CLIENT_MASTER_KEY,0), "CLIENT_MASTER_KEY"}, | 72 | {ERR_PACK(0,SSL_F_CLIENT_MASTER_KEY,0), "CLIENT_MASTER_KEY"}, |
72 | {ERR_PACK(0,SSL_F_D2I_SSL_SESSION,0), "d2i_SSL_SESSION"}, | 73 | {ERR_PACK(0,SSL_F_D2I_SSL_SESSION,0), "d2i_SSL_SESSION"}, |
@@ -80,7 +81,9 @@ static ERR_STRING_DATA SSL_str_functs[]= | |||
80 | {ERR_PACK(0,SSL_F_I2D_SSL_SESSION,0), "i2d_SSL_SESSION"}, | 81 | {ERR_PACK(0,SSL_F_I2D_SSL_SESSION,0), "i2d_SSL_SESSION"}, |
81 | {ERR_PACK(0,SSL_F_READ_N,0), "READ_N"}, | 82 | {ERR_PACK(0,SSL_F_READ_N,0), "READ_N"}, |
82 | {ERR_PACK(0,SSL_F_REQUEST_CERTIFICATE,0), "REQUEST_CERTIFICATE"}, | 83 | {ERR_PACK(0,SSL_F_REQUEST_CERTIFICATE,0), "REQUEST_CERTIFICATE"}, |
84 | {ERR_PACK(0,SSL_F_SERVER_FINISH,0), "SERVER_FINISH"}, | ||
83 | {ERR_PACK(0,SSL_F_SERVER_HELLO,0), "SERVER_HELLO"}, | 85 | {ERR_PACK(0,SSL_F_SERVER_HELLO,0), "SERVER_HELLO"}, |
86 | {ERR_PACK(0,SSL_F_SERVER_VERIFY,0), "SERVER_VERIFY"}, | ||
84 | {ERR_PACK(0,SSL_F_SSL23_ACCEPT,0), "SSL23_ACCEPT"}, | 87 | {ERR_PACK(0,SSL_F_SSL23_ACCEPT,0), "SSL23_ACCEPT"}, |
85 | {ERR_PACK(0,SSL_F_SSL23_CLIENT_HELLO,0), "SSL23_CLIENT_HELLO"}, | 88 | {ERR_PACK(0,SSL_F_SSL23_CLIENT_HELLO,0), "SSL23_CLIENT_HELLO"}, |
86 | {ERR_PACK(0,SSL_F_SSL23_CONNECT,0), "SSL23_CONNECT"}, | 89 | {ERR_PACK(0,SSL_F_SSL23_CONNECT,0), "SSL23_CONNECT"}, |
@@ -92,6 +95,7 @@ static ERR_STRING_DATA SSL_str_functs[]= | |||
92 | {ERR_PACK(0,SSL_F_SSL2_ACCEPT,0), "SSL2_ACCEPT"}, | 95 | {ERR_PACK(0,SSL_F_SSL2_ACCEPT,0), "SSL2_ACCEPT"}, |
93 | {ERR_PACK(0,SSL_F_SSL2_CONNECT,0), "SSL2_CONNECT"}, | 96 | {ERR_PACK(0,SSL_F_SSL2_CONNECT,0), "SSL2_CONNECT"}, |
94 | {ERR_PACK(0,SSL_F_SSL2_ENC_INIT,0), "SSL2_ENC_INIT"}, | 97 | {ERR_PACK(0,SSL_F_SSL2_ENC_INIT,0), "SSL2_ENC_INIT"}, |
98 | {ERR_PACK(0,SSL_F_SSL2_GENERATE_KEY_MATERIAL,0), "SSL2_GENERATE_KEY_MATERIAL"}, | ||
95 | {ERR_PACK(0,SSL_F_SSL2_PEEK,0), "SSL2_PEEK"}, | 99 | {ERR_PACK(0,SSL_F_SSL2_PEEK,0), "SSL2_PEEK"}, |
96 | {ERR_PACK(0,SSL_F_SSL2_READ,0), "SSL2_READ"}, | 100 | {ERR_PACK(0,SSL_F_SSL2_READ,0), "SSL2_READ"}, |
97 | {ERR_PACK(0,SSL_F_SSL2_READ_INTERNAL,0), "SSL2_READ_INTERNAL"}, | 101 | {ERR_PACK(0,SSL_F_SSL2_READ_INTERNAL,0), "SSL2_READ_INTERNAL"}, |
@@ -128,6 +132,7 @@ static ERR_STRING_DATA SSL_str_functs[]= | |||
128 | {ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,0), "SSL3_SEND_CLIENT_KEY_EXCHANGE"}, | 132 | {ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,0), "SSL3_SEND_CLIENT_KEY_EXCHANGE"}, |
129 | {ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_VERIFY,0), "SSL3_SEND_CLIENT_VERIFY"}, | 133 | {ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_VERIFY,0), "SSL3_SEND_CLIENT_VERIFY"}, |
130 | {ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_CERTIFICATE,0), "SSL3_SEND_SERVER_CERTIFICATE"}, | 134 | {ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_CERTIFICATE,0), "SSL3_SEND_SERVER_CERTIFICATE"}, |
135 | {ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_HELLO,0), "SSL3_SEND_SERVER_HELLO"}, | ||
131 | {ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,0), "SSL3_SEND_SERVER_KEY_EXCHANGE"}, | 136 | {ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,0), "SSL3_SEND_SERVER_KEY_EXCHANGE"}, |
132 | {ERR_PACK(0,SSL_F_SSL3_SETUP_BUFFERS,0), "SSL3_SETUP_BUFFERS"}, | 137 | {ERR_PACK(0,SSL_F_SSL3_SETUP_BUFFERS,0), "SSL3_SETUP_BUFFERS"}, |
133 | {ERR_PACK(0,SSL_F_SSL3_SETUP_KEY_BLOCK,0), "SSL3_SETUP_KEY_BLOCK"}, | 138 | {ERR_PACK(0,SSL_F_SSL3_SETUP_KEY_BLOCK,0), "SSL3_SETUP_KEY_BLOCK"}, |
@@ -355,6 +360,7 @@ static ERR_STRING_DATA SSL_str_reasons[]= | |||
355 | {SSL_R_SHORT_READ ,"short read"}, | 360 | {SSL_R_SHORT_READ ,"short read"}, |
356 | {SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE,"signature for non signing certificate"}, | 361 | {SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE,"signature for non signing certificate"}, |
357 | {SSL_R_SSL23_DOING_SESSION_ID_REUSE ,"ssl23 doing session id reuse"}, | 362 | {SSL_R_SSL23_DOING_SESSION_ID_REUSE ,"ssl23 doing session id reuse"}, |
363 | {SSL_R_SSL2_CONNECTION_ID_TOO_LONG ,"ssl2 connection id too long"}, | ||
358 | {SSL_R_SSL3_SESSION_ID_TOO_LONG ,"ssl3 session id too long"}, | 364 | {SSL_R_SSL3_SESSION_ID_TOO_LONG ,"ssl3 session id too long"}, |
359 | {SSL_R_SSL3_SESSION_ID_TOO_SHORT ,"ssl3 session id too short"}, | 365 | {SSL_R_SSL3_SESSION_ID_TOO_SHORT ,"ssl3 session id too short"}, |
360 | {SSL_R_SSLV3_ALERT_BAD_CERTIFICATE ,"sslv3 alert bad certificate"}, | 366 | {SSL_R_SSLV3_ALERT_BAD_CERTIFICATE ,"sslv3 alert bad certificate"}, |
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c index ab172aeaec..4bc4ce5b3a 100644 --- a/src/lib/libssl/ssl_lib.c +++ b/src/lib/libssl/ssl_lib.c | |||
@@ -1405,13 +1405,24 @@ void SSL_CTX_free(SSL_CTX *a) | |||
1405 | abort(); /* ok */ | 1405 | abort(); /* ok */ |
1406 | } | 1406 | } |
1407 | #endif | 1407 | #endif |
1408 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data); | ||
1409 | 1408 | ||
1409 | /* | ||
1410 | * Free internal session cache. However: the remove_cb() may reference | ||
1411 | * the ex_data of SSL_CTX, thus the ex_data store can only be removed | ||
1412 | * after the sessions were flushed. | ||
1413 | * As the ex_data handling routines might also touch the session cache, | ||
1414 | * the most secure solution seems to be: empty (flush) the cache, then | ||
1415 | * free ex_data, then finally free the cache. | ||
1416 | * (See ticket [openssl.org #212].) | ||
1417 | */ | ||
1410 | if (a->sessions != NULL) | 1418 | if (a->sessions != NULL) |
1411 | { | ||
1412 | SSL_CTX_flush_sessions(a,0); | 1419 | SSL_CTX_flush_sessions(a,0); |
1420 | |||
1421 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data); | ||
1422 | |||
1423 | if (a->sessions != NULL) | ||
1413 | lh_free(a->sessions); | 1424 | lh_free(a->sessions); |
1414 | } | 1425 | |
1415 | if (a->cert_store != NULL) | 1426 | if (a->cert_store != NULL) |
1416 | X509_STORE_free(a->cert_store); | 1427 | X509_STORE_free(a->cert_store); |
1417 | if (a->cipher_list != NULL) | 1428 | if (a->cipher_list != NULL) |
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h index fe4ac839cf..dd6c7a7323 100644 --- a/src/lib/libssl/ssl_locl.h +++ b/src/lib/libssl/ssl_locl.h | |||
@@ -510,7 +510,7 @@ STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s); | |||
510 | int ssl_verify_alarm_type(long type); | 510 | int ssl_verify_alarm_type(long type); |
511 | 511 | ||
512 | int ssl2_enc_init(SSL *s, int client); | 512 | int ssl2_enc_init(SSL *s, int client); |
513 | void ssl2_generate_key_material(SSL *s); | 513 | int ssl2_generate_key_material(SSL *s); |
514 | void ssl2_enc(SSL *s,int send_data); | 514 | void ssl2_enc(SSL *s,int send_data); |
515 | void ssl2_mac(SSL *s,unsigned char *mac,int send_data); | 515 | void ssl2_mac(SSL *s,unsigned char *mac,int send_data); |
516 | SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p); | 516 | SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p); |
diff --git a/src/lib/libssl/ssl_sess.c b/src/lib/libssl/ssl_sess.c index 8bfc382bb6..ca1a7427be 100644 --- a/src/lib/libssl/ssl_sess.c +++ b/src/lib/libssl/ssl_sess.c | |||
@@ -251,7 +251,12 @@ int ssl_get_new_session(SSL *s, int session) | |||
251 | ss->session_id_length=0; | 251 | ss->session_id_length=0; |
252 | } | 252 | } |
253 | 253 | ||
254 | die(s->sid_ctx_length <= sizeof ss->sid_ctx); | 254 | if (s->sid_ctx_length > sizeof ss->sid_ctx) |
255 | { | ||
256 | SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_INTERNAL_ERROR); | ||
257 | SSL_SESSION_free(ss); | ||
258 | return 0; | ||
259 | } | ||
255 | memcpy(ss->sid_ctx,s->sid_ctx,s->sid_ctx_length); | 260 | memcpy(ss->sid_ctx,s->sid_ctx,s->sid_ctx_length); |
256 | ss->sid_ctx_length=s->sid_ctx_length; | 261 | ss->sid_ctx_length=s->sid_ctx_length; |
257 | s->session=ss; | 262 | s->session=ss; |