summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/dsa
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/dsa')
-rw-r--r--src/lib/libcrypto/dsa/Makefile76
-rw-r--r--src/lib/libcrypto/dsa/dsa.h39
-rw-r--r--src/lib/libcrypto/dsa/dsa_asn1.c82
-rw-r--r--src/lib/libcrypto/dsa/dsa_err.c10
-rw-r--r--src/lib/libcrypto/dsa/dsa_gen.c3
-rw-r--r--src/lib/libcrypto/dsa/dsa_key.c4
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c49
-rw-r--r--src/lib/libcrypto/dsa/dsa_ossl.c3
-rw-r--r--src/lib/libcrypto/dsa/dsa_sign.c31
-rw-r--r--src/lib/libcrypto/dsa/dsa_vrf.c32
10 files changed, 240 insertions, 89 deletions
diff --git a/src/lib/libcrypto/dsa/Makefile b/src/lib/libcrypto/dsa/Makefile
index 5493f19e85..2cc45cdc62 100644
--- a/src/lib/libcrypto/dsa/Makefile
+++ b/src/lib/libcrypto/dsa/Makefile
@@ -18,9 +18,9 @@ APPS=
18 18
19LIB=$(TOP)/libcrypto.a 19LIB=$(TOP)/libcrypto.a
20LIBSRC= dsa_gen.c dsa_key.c dsa_lib.c dsa_asn1.c dsa_vrf.c dsa_sign.c \ 20LIBSRC= dsa_gen.c dsa_key.c dsa_lib.c dsa_asn1.c dsa_vrf.c dsa_sign.c \
21 dsa_err.c dsa_ossl.c dsa_depr.c 21 dsa_err.c dsa_ossl.c dsa_depr.c dsa_utl.c
22LIBOBJ= dsa_gen.o dsa_key.o dsa_lib.o dsa_asn1.o dsa_vrf.o dsa_sign.o \ 22LIBOBJ= dsa_gen.o dsa_key.o dsa_lib.o dsa_asn1.o dsa_vrf.o dsa_sign.o \
23 dsa_err.o dsa_ossl.o dsa_depr.o 23 dsa_err.o dsa_ossl.o dsa_depr.o dsa_utl.o
24 24
25SRC= $(LIBSRC) 25SRC= $(LIBSRC)
26 26
@@ -35,7 +35,7 @@ top:
35all: lib 35all: lib
36 36
37lib: $(LIBOBJ) 37lib: $(LIBOBJ)
38 $(AR) $(LIB) $(LIBOBJ) 38 $(ARX) $(LIB) $(LIBOBJ)
39 $(RANLIB) $(LIB) || echo Never mind. 39 $(RANLIB) $(LIB) || echo Never mind.
40 @touch lib 40 @touch lib
41 41
@@ -78,9 +78,10 @@ clean:
78 78
79dsa_asn1.o: ../../e_os.h ../../include/openssl/asn1.h 79dsa_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
80dsa_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h 80dsa_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
81dsa_asn1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 81dsa_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
82dsa_asn1.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h 82dsa_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
83dsa_asn1.o: ../../include/openssl/err.h ../../include/openssl/lhash.h 83dsa_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
84dsa_asn1.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
84dsa_asn1.o: ../../include/openssl/opensslconf.h 85dsa_asn1.o: ../../include/openssl/opensslconf.h
85dsa_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h 86dsa_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
86dsa_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 87dsa_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
@@ -90,8 +91,9 @@ dsa_depr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
90dsa_depr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 91dsa_depr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
91dsa_depr.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h 92dsa_depr.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
92dsa_depr.o: ../../include/openssl/err.h ../../include/openssl/evp.h 93dsa_depr.o: ../../include/openssl/err.h ../../include/openssl/evp.h
93dsa_depr.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h 94dsa_depr.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
94dsa_depr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h 95dsa_depr.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
96dsa_depr.o: ../../include/openssl/opensslconf.h
95dsa_depr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h 97dsa_depr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
96dsa_depr.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h 98dsa_depr.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
97dsa_depr.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 99dsa_depr.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
@@ -108,12 +110,13 @@ dsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
108dsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 110dsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
109dsa_gen.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h 111dsa_gen.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
110dsa_gen.o: ../../include/openssl/err.h ../../include/openssl/evp.h 112dsa_gen.o: ../../include/openssl/err.h ../../include/openssl/evp.h
111dsa_gen.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h 113dsa_gen.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
112dsa_gen.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h 114dsa_gen.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
113dsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h 115dsa_gen.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
114dsa_gen.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h 116dsa_gen.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
115dsa_gen.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 117dsa_gen.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
116dsa_gen.o: ../../include/openssl/symhacks.h ../cryptlib.h dsa_gen.c 118dsa_gen.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
119dsa_gen.o: ../cryptlib.h dsa_gen.c
117dsa_key.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h 120dsa_key.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
118dsa_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 121dsa_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
119dsa_key.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h 122dsa_key.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
@@ -129,14 +132,14 @@ dsa_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
129dsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h 132dsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
130dsa_lib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h 133dsa_lib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
131dsa_lib.o: ../../include/openssl/engine.h ../../include/openssl/err.h 134dsa_lib.o: ../../include/openssl/engine.h ../../include/openssl/err.h
132dsa_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h 135dsa_lib.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
133dsa_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h 136dsa_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
134dsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 137dsa_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
135dsa_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h 138dsa_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
136dsa_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h 139dsa_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
137dsa_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h 140dsa_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
138dsa_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h 141dsa_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
139dsa_lib.o: ../cryptlib.h dsa_lib.c 142dsa_lib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h dsa_lib.c
140dsa_ossl.o: ../../e_os.h ../../include/openssl/asn1.h 143dsa_ossl.o: ../../e_os.h ../../include/openssl/asn1.h
141dsa_ossl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 144dsa_ossl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
142dsa_ossl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 145dsa_ossl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
@@ -151,19 +154,34 @@ dsa_sign.o: ../../e_os.h ../../include/openssl/asn1.h
151dsa_sign.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 154dsa_sign.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
152dsa_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 155dsa_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
153dsa_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h 156dsa_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
154dsa_sign.o: ../../include/openssl/err.h ../../include/openssl/lhash.h 157dsa_sign.o: ../../include/openssl/err.h ../../include/openssl/fips.h
155dsa_sign.o: ../../include/openssl/opensslconf.h 158dsa_sign.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
156dsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h 159dsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
157dsa_sign.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h 160dsa_sign.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
158dsa_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h 161dsa_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
159dsa_sign.o: ../cryptlib.h dsa_sign.c 162dsa_sign.o: ../cryptlib.h dsa_sign.c
163dsa_utl.o: ../../e_os.h ../../include/openssl/asn1.h
164dsa_utl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
165dsa_utl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
166dsa_utl.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
167dsa_utl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
168dsa_utl.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
169dsa_utl.o: ../../include/openssl/engine.h ../../include/openssl/err.h
170dsa_utl.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
171dsa_utl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
172dsa_utl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
173dsa_utl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
174dsa_utl.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
175dsa_utl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
176dsa_utl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
177dsa_utl.o: ../../include/openssl/x509_vfy.h ../cryptlib.h dsa_utl.c
160dsa_vrf.o: ../../e_os.h ../../include/openssl/asn1.h 178dsa_vrf.o: ../../e_os.h ../../include/openssl/asn1.h
161dsa_vrf.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h 179dsa_vrf.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
162dsa_vrf.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h 180dsa_vrf.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
163dsa_vrf.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h 181dsa_vrf.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
164dsa_vrf.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 182dsa_vrf.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
165dsa_vrf.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h 183dsa_vrf.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
166dsa_vrf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h 184dsa_vrf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
167dsa_vrf.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h 185dsa_vrf.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
168dsa_vrf.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h 186dsa_vrf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
169dsa_vrf.o: ../cryptlib.h dsa_vrf.c 187dsa_vrf.o: ../../include/openssl/symhacks.h ../cryptlib.h dsa_vrf.c
diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h
index 3a8fe5b56b..702c50d6dc 100644
--- a/src/lib/libcrypto/dsa/dsa.h
+++ b/src/lib/libcrypto/dsa/dsa.h
@@ -88,6 +88,8 @@
88# define OPENSSL_DSA_MAX_MODULUS_BITS 10000 88# define OPENSSL_DSA_MAX_MODULUS_BITS 10000
89#endif 89#endif
90 90
91#define OPENSSL_DSA_FIPS_MIN_MODULUS_BITS 1024
92
91#define DSA_FLAG_CACHE_MONT_P 0x01 93#define DSA_FLAG_CACHE_MONT_P 0x01
92#define DSA_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DSA 94#define DSA_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DSA
93 * implementation now uses constant time 95 * implementation now uses constant time
@@ -97,6 +99,25 @@
97 * be used for all exponents. 99 * be used for all exponents.
98 */ 100 */
99 101
102/* If this flag is set the DSA method is FIPS compliant and can be used
103 * in FIPS mode. This is set in the validated module method. If an
104 * application sets this flag in its own methods it is its reposibility
105 * to ensure the result is compliant.
106 */
107
108#define DSA_FLAG_FIPS_METHOD 0x0400
109
110/* If this flag is set the operations normally disabled in FIPS mode are
111 * permitted it is then the applications responsibility to ensure that the
112 * usage is compliant.
113 */
114
115#define DSA_FLAG_NON_FIPS_ALLOW 0x0400
116
117#ifdef OPENSSL_FIPS
118#define FIPS_DSA_SIZE_T int
119#endif
120
100#ifdef __cplusplus 121#ifdef __cplusplus
101extern "C" { 122extern "C" {
102#endif 123#endif
@@ -189,6 +210,11 @@ void DSA_set_default_method(const DSA_METHOD *);
189const DSA_METHOD *DSA_get_default_method(void); 210const DSA_METHOD *DSA_get_default_method(void);
190int DSA_set_method(DSA *dsa, const DSA_METHOD *); 211int DSA_set_method(DSA *dsa, const DSA_METHOD *);
191 212
213#ifdef OPENSSL_FIPS
214DSA * FIPS_dsa_new(void);
215void FIPS_dsa_free (DSA *r);
216#endif
217
192DSA * DSA_new(void); 218DSA * DSA_new(void);
193DSA * DSA_new_method(ENGINE *engine); 219DSA * DSA_new_method(ENGINE *engine);
194void DSA_free (DSA *r); 220void DSA_free (DSA *r);
@@ -249,6 +275,11 @@ int DSA_print_fp(FILE *bp, const DSA *x, int off);
249DH *DSA_dup_DH(const DSA *r); 275DH *DSA_dup_DH(const DSA *r);
250#endif 276#endif
251 277
278#ifdef OPENSSL_FIPS
279int FIPS_dsa_sig_encode(unsigned char *out, DSA_SIG *sig);
280int FIPS_dsa_sig_decode(DSA_SIG *sig, const unsigned char *in, int inlen);
281#endif
282
252/* BEGIN ERROR CODES */ 283/* BEGIN ERROR CODES */
253/* The following lines are auto generated by the script mkerr.pl. Any changes 284/* The following lines are auto generated by the script mkerr.pl. Any changes
254 * made after this point may be overwritten when the script is next run. 285 * made after this point may be overwritten when the script is next run.
@@ -261,11 +292,16 @@ void ERR_load_DSA_strings(void);
261#define DSA_F_D2I_DSA_SIG 110 292#define DSA_F_D2I_DSA_SIG 110
262#define DSA_F_DSAPARAMS_PRINT 100 293#define DSA_F_DSAPARAMS_PRINT 100
263#define DSA_F_DSAPARAMS_PRINT_FP 101 294#define DSA_F_DSAPARAMS_PRINT_FP 101
295#define DSA_F_DSA_BUILTIN_KEYGEN 119
296#define DSA_F_DSA_BUILTIN_PARAMGEN 118
264#define DSA_F_DSA_DO_SIGN 112 297#define DSA_F_DSA_DO_SIGN 112
265#define DSA_F_DSA_DO_VERIFY 113 298#define DSA_F_DSA_DO_VERIFY 113
299#define DSA_F_DSA_GENERATE_PARAMETERS 117
266#define DSA_F_DSA_NEW_METHOD 103 300#define DSA_F_DSA_NEW_METHOD 103
267#define DSA_F_DSA_PRINT 104 301#define DSA_F_DSA_PRINT 104
268#define DSA_F_DSA_PRINT_FP 105 302#define DSA_F_DSA_PRINT_FP 105
303#define DSA_F_DSA_SET_DEFAULT_METHOD 115
304#define DSA_F_DSA_SET_METHOD 116
269#define DSA_F_DSA_SIGN 106 305#define DSA_F_DSA_SIGN 106
270#define DSA_F_DSA_SIGN_SETUP 107 306#define DSA_F_DSA_SIGN_SETUP 107
271#define DSA_F_DSA_SIG_NEW 109 307#define DSA_F_DSA_SIG_NEW 109
@@ -276,8 +312,11 @@ void ERR_load_DSA_strings(void);
276/* Reason codes. */ 312/* Reason codes. */
277#define DSA_R_BAD_Q_VALUE 102 313#define DSA_R_BAD_Q_VALUE 102
278#define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100 314#define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100
315#define DSA_R_KEY_SIZE_TOO_SMALL 106
279#define DSA_R_MISSING_PARAMETERS 101 316#define DSA_R_MISSING_PARAMETERS 101
280#define DSA_R_MODULUS_TOO_LARGE 103 317#define DSA_R_MODULUS_TOO_LARGE 103
318#define DSA_R_NON_FIPS_METHOD 104
319#define DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE 105
281 320
282#ifdef __cplusplus 321#ifdef __cplusplus
283} 322}
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c
index 23fce555aa..0645facb4b 100644
--- a/src/lib/libcrypto/dsa/dsa_asn1.c
+++ b/src/lib/libcrypto/dsa/dsa_asn1.c
@@ -1,5 +1,5 @@
1/* dsa_asn1.c */ 1/* dsa_asn1.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
@@ -61,6 +61,11 @@
61#include <openssl/dsa.h> 61#include <openssl/dsa.h>
62#include <openssl/asn1.h> 62#include <openssl/asn1.h>
63#include <openssl/asn1t.h> 63#include <openssl/asn1t.h>
64#include <openssl/bn.h>
65#ifdef OPENSSL_FIPS
66#include <openssl/fips.h>
67#endif
68
64 69
65/* Override the default new methods */ 70/* Override the default new methods */
66static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) 71static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
@@ -83,7 +88,7 @@ ASN1_SEQUENCE_cb(DSA_SIG, sig_cb) = {
83 ASN1_SIMPLE(DSA_SIG, s, CBIGNUM) 88 ASN1_SIMPLE(DSA_SIG, s, CBIGNUM)
84} ASN1_SEQUENCE_END_cb(DSA_SIG, DSA_SIG) 89} ASN1_SEQUENCE_END_cb(DSA_SIG, DSA_SIG)
85 90
86IMPLEMENT_ASN1_FUNCTIONS_const(DSA_SIG) 91IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA_SIG,DSA_SIG,DSA_SIG)
87 92
88/* Override the default free and new methods */ 93/* Override the default free and new methods */
89static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) 94static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
@@ -138,3 +143,76 @@ ASN1_CHOICE_cb(DSAPublicKey, dsa_cb) = {
138} ASN1_CHOICE_END_cb(DSA, DSAPublicKey, write_params) 143} ASN1_CHOICE_END_cb(DSA, DSAPublicKey, write_params)
139 144
140IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPublicKey, DSAPublicKey) 145IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPublicKey, DSAPublicKey)
146
147int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
148 unsigned int *siglen, DSA *dsa)
149 {
150 DSA_SIG *s;
151#ifdef OPENSSL_FIPS
152 if(FIPS_mode() && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW))
153 {
154 DSAerr(DSA_F_DSA_SIGN, DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
155 return 0;
156 }
157#endif
158 s=DSA_do_sign(dgst,dlen,dsa);
159 if (s == NULL)
160 {
161 *siglen=0;
162 return(0);
163 }
164 *siglen=i2d_DSA_SIG(s,&sig);
165 DSA_SIG_free(s);
166 return(1);
167 }
168
169int DSA_size(const DSA *r)
170 {
171 int ret,i;
172 ASN1_INTEGER bs;
173 unsigned char buf[4]; /* 4 bytes looks really small.
174 However, i2d_ASN1_INTEGER() will not look
175 beyond the first byte, as long as the second
176 parameter is NULL. */
177
178 i=BN_num_bits(r->q);
179 bs.length=(i+7)/8;
180 bs.data=buf;
181 bs.type=V_ASN1_INTEGER;
182 /* If the top bit is set the asn1 encoding is 1 larger. */
183 buf[0]=0xff;
184
185 i=i2d_ASN1_INTEGER(&bs,NULL);
186 i+=i; /* r and s */
187 ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
188 return(ret);
189 }
190
191/* data has already been hashed (probably with SHA or SHA-1). */
192/* returns
193 * 1: correct signature
194 * 0: incorrect signature
195 * -1: error
196 */
197int DSA_verify(int type, const unsigned char *dgst, int dgst_len,
198 const unsigned char *sigbuf, int siglen, DSA *dsa)
199 {
200 DSA_SIG *s;
201 int ret=-1;
202#ifdef OPENSSL_FIPS
203 if(FIPS_mode() && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW))
204 {
205 DSAerr(DSA_F_DSA_VERIFY, DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
206 return 0;
207 }
208#endif
209
210 s = DSA_SIG_new();
211 if (s == NULL) return(ret);
212 if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;
213 ret=DSA_do_verify(dgst,dgst_len,s,dsa);
214err:
215 DSA_SIG_free(s);
216 return(ret);
217 }
218
diff --git a/src/lib/libcrypto/dsa/dsa_err.c b/src/lib/libcrypto/dsa/dsa_err.c
index 768711994b..872839af94 100644
--- a/src/lib/libcrypto/dsa/dsa_err.c
+++ b/src/lib/libcrypto/dsa/dsa_err.c
@@ -1,6 +1,6 @@
1/* crypto/dsa/dsa_err.c */ 1/* crypto/dsa/dsa_err.c */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -73,11 +73,16 @@ static ERR_STRING_DATA DSA_str_functs[]=
73{ERR_FUNC(DSA_F_D2I_DSA_SIG), "d2i_DSA_SIG"}, 73{ERR_FUNC(DSA_F_D2I_DSA_SIG), "d2i_DSA_SIG"},
74{ERR_FUNC(DSA_F_DSAPARAMS_PRINT), "DSAparams_print"}, 74{ERR_FUNC(DSA_F_DSAPARAMS_PRINT), "DSAparams_print"},
75{ERR_FUNC(DSA_F_DSAPARAMS_PRINT_FP), "DSAparams_print_fp"}, 75{ERR_FUNC(DSA_F_DSAPARAMS_PRINT_FP), "DSAparams_print_fp"},
76{ERR_FUNC(DSA_F_DSA_BUILTIN_KEYGEN), "DSA_BUILTIN_KEYGEN"},
77{ERR_FUNC(DSA_F_DSA_BUILTIN_PARAMGEN), "DSA_BUILTIN_PARAMGEN"},
76{ERR_FUNC(DSA_F_DSA_DO_SIGN), "DSA_do_sign"}, 78{ERR_FUNC(DSA_F_DSA_DO_SIGN), "DSA_do_sign"},
77{ERR_FUNC(DSA_F_DSA_DO_VERIFY), "DSA_do_verify"}, 79{ERR_FUNC(DSA_F_DSA_DO_VERIFY), "DSA_do_verify"},
80{ERR_FUNC(DSA_F_DSA_GENERATE_PARAMETERS), "DSA_generate_parameters"},
78{ERR_FUNC(DSA_F_DSA_NEW_METHOD), "DSA_new_method"}, 81{ERR_FUNC(DSA_F_DSA_NEW_METHOD), "DSA_new_method"},
79{ERR_FUNC(DSA_F_DSA_PRINT), "DSA_print"}, 82{ERR_FUNC(DSA_F_DSA_PRINT), "DSA_print"},
80{ERR_FUNC(DSA_F_DSA_PRINT_FP), "DSA_print_fp"}, 83{ERR_FUNC(DSA_F_DSA_PRINT_FP), "DSA_print_fp"},
84{ERR_FUNC(DSA_F_DSA_SET_DEFAULT_METHOD), "DSA_set_default_method"},
85{ERR_FUNC(DSA_F_DSA_SET_METHOD), "DSA_set_method"},
81{ERR_FUNC(DSA_F_DSA_SIGN), "DSA_sign"}, 86{ERR_FUNC(DSA_F_DSA_SIGN), "DSA_sign"},
82{ERR_FUNC(DSA_F_DSA_SIGN_SETUP), "DSA_sign_setup"}, 87{ERR_FUNC(DSA_F_DSA_SIGN_SETUP), "DSA_sign_setup"},
83{ERR_FUNC(DSA_F_DSA_SIG_NEW), "DSA_SIG_new"}, 88{ERR_FUNC(DSA_F_DSA_SIG_NEW), "DSA_SIG_new"},
@@ -91,8 +96,11 @@ static ERR_STRING_DATA DSA_str_reasons[]=
91 { 96 {
92{ERR_REASON(DSA_R_BAD_Q_VALUE) ,"bad q value"}, 97{ERR_REASON(DSA_R_BAD_Q_VALUE) ,"bad q value"},
93{ERR_REASON(DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE),"data too large for key size"}, 98{ERR_REASON(DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE),"data too large for key size"},
99{ERR_REASON(DSA_R_KEY_SIZE_TOO_SMALL) ,"key size too small"},
94{ERR_REASON(DSA_R_MISSING_PARAMETERS) ,"missing parameters"}, 100{ERR_REASON(DSA_R_MISSING_PARAMETERS) ,"missing parameters"},
95{ERR_REASON(DSA_R_MODULUS_TOO_LARGE) ,"modulus too large"}, 101{ERR_REASON(DSA_R_MODULUS_TOO_LARGE) ,"modulus too large"},
102{ERR_REASON(DSA_R_NON_FIPS_METHOD) ,"non fips method"},
103{ERR_REASON(DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE),"operation not allowed in fips mode"},
96{0,NULL} 104{0,NULL}
97 }; 105 };
98 106
diff --git a/src/lib/libcrypto/dsa/dsa_gen.c b/src/lib/libcrypto/dsa/dsa_gen.c
index ca0b86a6cf..6f1728e3cf 100644
--- a/src/lib/libcrypto/dsa/dsa_gen.c
+++ b/src/lib/libcrypto/dsa/dsa_gen.c
@@ -82,6 +82,8 @@
82#include <openssl/rand.h> 82#include <openssl/rand.h>
83#include <openssl/sha.h> 83#include <openssl/sha.h>
84 84
85#ifndef OPENSSL_FIPS
86
85static int dsa_builtin_paramgen(DSA *ret, int bits, 87static int dsa_builtin_paramgen(DSA *ret, int bits,
86 unsigned char *seed_in, int seed_len, 88 unsigned char *seed_in, int seed_len,
87 int *counter_ret, unsigned long *h_ret, BN_GENCB *cb); 89 int *counter_ret, unsigned long *h_ret, BN_GENCB *cb);
@@ -320,3 +322,4 @@ err:
320 return ok; 322 return ok;
321 } 323 }
322#endif 324#endif
325#endif
diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c
index c4aa86bc6d..5e39124230 100644
--- a/src/lib/libcrypto/dsa/dsa_key.c
+++ b/src/lib/libcrypto/dsa/dsa_key.c
@@ -64,6 +64,8 @@
64#include <openssl/dsa.h> 64#include <openssl/dsa.h>
65#include <openssl/rand.h> 65#include <openssl/rand.h>
66 66
67#ifndef OPENSSL_FIPS
68
67static int dsa_builtin_keygen(DSA *dsa); 69static int dsa_builtin_keygen(DSA *dsa);
68 70
69int DSA_generate_key(DSA *dsa) 71int DSA_generate_key(DSA *dsa)
@@ -126,3 +128,5 @@ err:
126 return(ok); 128 return(ok);
127 } 129 }
128#endif 130#endif
131
132#endif
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c
index e9b75902db..7ac9dc8c89 100644
--- a/src/lib/libcrypto/dsa/dsa_lib.c
+++ b/src/lib/libcrypto/dsa/dsa_lib.c
@@ -76,6 +76,14 @@ static const DSA_METHOD *default_DSA_method = NULL;
76 76
77void DSA_set_default_method(const DSA_METHOD *meth) 77void DSA_set_default_method(const DSA_METHOD *meth)
78 { 78 {
79#ifdef OPENSSL_FIPS
80 if (FIPS_mode() && !(meth->flags & DSA_FLAG_FIPS_METHOD))
81 {
82 DSAerr(DSA_F_DSA_SET_DEFAULT_METHOD, DSA_R_NON_FIPS_METHOD);
83 return;
84 }
85#endif
86
79 default_DSA_method = meth; 87 default_DSA_method = meth;
80 } 88 }
81 89
@@ -96,6 +104,13 @@ int DSA_set_method(DSA *dsa, const DSA_METHOD *meth)
96 /* NB: The caller is specifically setting a method, so it's not up to us 104 /* NB: The caller is specifically setting a method, so it's not up to us
97 * to deal with which ENGINE it comes from. */ 105 * to deal with which ENGINE it comes from. */
98 const DSA_METHOD *mtmp; 106 const DSA_METHOD *mtmp;
107#ifdef OPENSSL_FIPS
108 if (FIPS_mode() && !(meth->flags & DSA_FLAG_FIPS_METHOD))
109 {
110 DSAerr(DSA_F_DSA_SET_METHOD, DSA_R_NON_FIPS_METHOD);
111 return 0;
112 }
113#endif
99 mtmp = dsa->meth; 114 mtmp = dsa->meth;
100 if (mtmp->finish) mtmp->finish(dsa); 115 if (mtmp->finish) mtmp->finish(dsa);
101#ifndef OPENSSL_NO_ENGINE 116#ifndef OPENSSL_NO_ENGINE
@@ -147,6 +162,18 @@ DSA *DSA_new_method(ENGINE *engine)
147 } 162 }
148 } 163 }
149#endif 164#endif
165#ifdef OPENSSL_FIPS
166 if (FIPS_mode() && !(ret->meth->flags & DSA_FLAG_FIPS_METHOD))
167 {
168 DSAerr(DSA_F_DSA_NEW_METHOD, DSA_R_NON_FIPS_METHOD);
169#ifndef OPENSSL_NO_ENGINE
170 if (ret->engine)
171 ENGINE_finish(ret->engine);
172#endif
173 OPENSSL_free(ret);
174 return NULL;
175 }
176#endif
150 177
151 ret->pad=0; 178 ret->pad=0;
152 ret->version=0; 179 ret->version=0;
@@ -233,28 +260,6 @@ int DSA_up_ref(DSA *r)
233 return ((i > 1) ? 1 : 0); 260 return ((i > 1) ? 1 : 0);
234 } 261 }
235 262
236int DSA_size(const DSA *r)
237 {
238 int ret,i;
239 ASN1_INTEGER bs;
240 unsigned char buf[4]; /* 4 bytes looks really small.
241 However, i2d_ASN1_INTEGER() will not look
242 beyond the first byte, as long as the second
243 parameter is NULL. */
244
245 i=BN_num_bits(r->q);
246 bs.length=(i+7)/8;
247 bs.data=buf;
248 bs.type=V_ASN1_INTEGER;
249 /* If the top bit is set the asn1 encoding is 1 larger. */
250 buf[0]=0xff;
251
252 i=i2d_ASN1_INTEGER(&bs,NULL);
253 i+=i; /* r and s */
254 ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
255 return(ret);
256 }
257
258int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, 263int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
259 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) 264 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
260 { 265 {
diff --git a/src/lib/libcrypto/dsa/dsa_ossl.c b/src/lib/libcrypto/dsa/dsa_ossl.c
index 75ff7cc4af..412cf1d88b 100644
--- a/src/lib/libcrypto/dsa/dsa_ossl.c
+++ b/src/lib/libcrypto/dsa/dsa_ossl.c
@@ -65,6 +65,8 @@
65#include <openssl/rand.h> 65#include <openssl/rand.h>
66#include <openssl/asn1.h> 66#include <openssl/asn1.h>
67 67
68#ifndef OPENSSL_FIPS
69
68static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); 70static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
69static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp); 71static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp);
70static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, 72static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
@@ -391,3 +393,4 @@ static int dsa_finish(DSA *dsa)
391 return(1); 393 return(1);
392} 394}
393 395
396#endif
diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c
index 89205026f0..4cfbbe57a8 100644
--- a/src/lib/libcrypto/dsa/dsa_sign.c
+++ b/src/lib/libcrypto/dsa/dsa_sign.c
@@ -64,29 +64,32 @@
64#include <openssl/dsa.h> 64#include <openssl/dsa.h>
65#include <openssl/rand.h> 65#include <openssl/rand.h>
66#include <openssl/asn1.h> 66#include <openssl/asn1.h>
67#ifdef OPENSSL_FIPS
68#include <openssl/fips.h>
69#endif
67 70
68DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
69 {
70 return dsa->meth->dsa_do_sign(dgst, dlen, dsa);
71 }
72 71
73int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig, 72DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
74 unsigned int *siglen, DSA *dsa)
75 { 73 {
76 DSA_SIG *s; 74#ifdef OPENSSL_FIPS
77 s=DSA_do_sign(dgst,dlen,dsa); 75 if(FIPS_mode() && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW))
78 if (s == NULL)
79 { 76 {
80 *siglen=0; 77 DSAerr(DSA_F_DSA_DO_SIGN, DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
81 return(0); 78 return NULL;
82 } 79 }
83 *siglen=i2d_DSA_SIG(s,&sig); 80#endif
84 DSA_SIG_free(s); 81 return dsa->meth->dsa_do_sign(dgst, dlen, dsa);
85 return(1);
86 } 82 }
87 83
88int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) 84int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
89 { 85 {
86#ifdef OPENSSL_FIPS
87 if(FIPS_mode() && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW))
88 {
89 DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
90 return 0;
91 }
92#endif
90 return dsa->meth->dsa_sign_setup(dsa, ctx_in, kinvp, rp); 93 return dsa->meth->dsa_sign_setup(dsa, ctx_in, kinvp, rp);
91 } 94 }
92 95
diff --git a/src/lib/libcrypto/dsa/dsa_vrf.c b/src/lib/libcrypto/dsa/dsa_vrf.c
index c4aeddd056..c75e423048 100644
--- a/src/lib/libcrypto/dsa/dsa_vrf.c
+++ b/src/lib/libcrypto/dsa/dsa_vrf.c
@@ -64,31 +64,21 @@
64#include <openssl/dsa.h> 64#include <openssl/dsa.h>
65#include <openssl/rand.h> 65#include <openssl/rand.h>
66#include <openssl/asn1.h> 66#include <openssl/asn1.h>
67#ifdef OPENSSL_FIPS
68#include <openssl/fips.h>
69#endif
70
67#include <openssl/asn1_mac.h> 71#include <openssl/asn1_mac.h>
68 72
69int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, 73int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
70 DSA *dsa) 74 DSA *dsa)
71 { 75 {
76#ifdef OPENSSL_FIPS
77 if(FIPS_mode() && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW))
78 {
79 DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
80 return 0;
81 }
82#endif
72 return dsa->meth->dsa_do_verify(dgst, dgst_len, sig, dsa); 83 return dsa->meth->dsa_do_verify(dgst, dgst_len, sig, dsa);
73 } 84 }
74
75/* data has already been hashed (probably with SHA or SHA-1). */
76/* returns
77 * 1: correct signature
78 * 0: incorrect signature
79 * -1: error
80 */
81int DSA_verify(int type, const unsigned char *dgst, int dgst_len,
82 const unsigned char *sigbuf, int siglen, DSA *dsa)
83 {
84 DSA_SIG *s;
85 int ret=-1;
86
87 s = DSA_SIG_new();
88 if (s == NULL) return(ret);
89 if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;
90 ret=DSA_do_verify(dgst,dgst_len,s,dsa);
91err:
92 DSA_SIG_free(s);
93 return(ret);
94 }