diff options
| author | beck <> | 1999-09-29 04:37:45 +0000 |
|---|---|---|
| committer | beck <> | 1999-09-29 04:37:45 +0000 |
| commit | de8f24ea083384bb66b32ec105dc4743c5663cdf (patch) | |
| tree | 1412176ae62a3cab2cf2b0b92150fcbceaac6092 /src/lib/libcrypto/dsa | |
| parent | cb929d29896bcb87c2a97417fbd03e50078fc178 (diff) | |
| download | openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.tar.gz openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.tar.bz2 openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.zip | |
OpenSSL 0.9.4 merge
Diffstat (limited to 'src/lib/libcrypto/dsa')
| -rw-r--r-- | src/lib/libcrypto/dsa/Makefile.ssl | 91 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa.err | 15 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa.h | 80 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_asn1.c | 96 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_err.c | 123 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_gen.c | 109 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_key.c | 14 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_lib.c | 59 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_sign.c | 152 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_vrf.c | 140 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsagen.c | 5 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsatest.c | 52 |
12 files changed, 568 insertions, 368 deletions
diff --git a/src/lib/libcrypto/dsa/Makefile.ssl b/src/lib/libcrypto/dsa/Makefile.ssl index 2cc4ddb39e..6d80ce77be 100644 --- a/src/lib/libcrypto/dsa/Makefile.ssl +++ b/src/lib/libcrypto/dsa/Makefile.ssl | |||
| @@ -7,23 +7,23 @@ TOP= ../.. | |||
| 7 | CC= cc | 7 | CC= cc |
| 8 | INCLUDES= -I.. -I../../include | 8 | INCLUDES= -I.. -I../../include |
| 9 | CFLAG=-g | 9 | CFLAG=-g |
| 10 | INSTALL_PREFIX= | ||
| 11 | OPENSSLDIR= /usr/local/ssl | ||
| 10 | INSTALLTOP=/usr/local/ssl | 12 | INSTALLTOP=/usr/local/ssl |
| 11 | MAKE= make -f Makefile.ssl | 13 | MAKE= make -f Makefile.ssl |
| 12 | MAKEDEPEND= makedepend -f Makefile.ssl | 14 | MAKEDEPEND= $(TOP)/util/domd $(TOP) |
| 13 | MAKEFILE= Makefile.ssl | 15 | MAKEFILE= Makefile.ssl |
| 14 | AR= ar r | 16 | AR= ar r |
| 15 | 17 | ||
| 16 | CFLAGS= $(INCLUDES) $(CFLAG) | 18 | CFLAGS= $(INCLUDES) $(CFLAG) |
| 17 | 19 | ||
| 18 | ERR=dsa | ||
| 19 | ERRC=dsa_err | ||
| 20 | GENERAL=Makefile | 20 | GENERAL=Makefile |
| 21 | TEST=dsatest.c | 21 | TEST=dsatest.c |
| 22 | APPS= | 22 | APPS= |
| 23 | 23 | ||
| 24 | LIB=$(TOP)/libcrypto.a | 24 | LIB=$(TOP)/libcrypto.a |
| 25 | LIBSRC= dsa_gen.c dsa_key.c dsa_lib.c dsa_vrf.c dsa_sign.c $(ERRC).c | 25 | LIBSRC= dsa_gen.c dsa_key.c dsa_lib.c dsa_asn1.c dsa_vrf.c dsa_sign.c dsa_err.c |
| 26 | LIBOBJ= dsa_gen.o dsa_key.o dsa_lib.o dsa_vrf.o dsa_sign.o $(ERRC).o | 26 | LIBOBJ= dsa_gen.o dsa_key.o dsa_lib.o dsa_asn1.o dsa_vrf.o dsa_sign.o dsa_err.o |
| 27 | 27 | ||
| 28 | SRC= $(LIBSRC) | 28 | SRC= $(LIBSRC) |
| 29 | 29 | ||
| @@ -39,24 +39,23 @@ all: lib | |||
| 39 | 39 | ||
| 40 | lib: $(LIBOBJ) | 40 | lib: $(LIBOBJ) |
| 41 | $(AR) $(LIB) $(LIBOBJ) | 41 | $(AR) $(LIB) $(LIBOBJ) |
| 42 | sh $(TOP)/util/ranlib.sh $(LIB) | 42 | $(RANLIB) $(LIB) |
| 43 | @touch lib | 43 | @touch lib |
| 44 | 44 | ||
| 45 | files: | 45 | files: |
| 46 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | 46 | $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO |
| 47 | 47 | ||
| 48 | links: | 48 | links: |
| 49 | /bin/rm -f Makefile | 49 | @$(TOP)/util/point.sh Makefile.ssl Makefile |
| 50 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | 50 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) |
| 51 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | 51 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) |
| 52 | $(TOP)/util/mklink.sh ../../test $(TEST) | 52 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) |
| 53 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
| 54 | 53 | ||
| 55 | install: | 54 | install: |
| 56 | @for i in $(EXHEADER) ; \ | 55 | @for i in $(EXHEADER) ; \ |
| 57 | do \ | 56 | do \ |
| 58 | (cp $$i $(INSTALLTOP)/include/$$i; \ | 57 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ |
| 59 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | 58 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ |
| 60 | done; | 59 | done; |
| 61 | 60 | ||
| 62 | tags: | 61 | tags: |
| @@ -68,17 +67,67 @@ lint: | |||
| 68 | lint -DLINT $(INCLUDES) $(SRC)>fluff | 67 | lint -DLINT $(INCLUDES) $(SRC)>fluff |
| 69 | 68 | ||
| 70 | depend: | 69 | depend: |
| 71 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | 70 | $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) |
| 72 | 71 | ||
| 73 | dclean: | 72 | dclean: |
| 74 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | 73 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new |
| 75 | mv -f Makefile.new $(MAKEFILE) | 74 | mv -f Makefile.new $(MAKEFILE) |
| 76 | 75 | ||
| 77 | clean: | 76 | clean: |
| 78 | /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | 77 | rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff |
| 79 | |||
| 80 | errors: | ||
| 81 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
| 82 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
| 83 | 78 | ||
| 84 | # DO NOT DELETE THIS LINE -- make depend depends on it. | 79 | # DO NOT DELETE THIS LINE -- make depend depends on it. |
| 80 | |||
| 81 | dsa_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h | ||
| 82 | dsa_asn1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
| 83 | dsa_asn1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 84 | dsa_asn1.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 85 | dsa_asn1.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h | ||
| 86 | dsa_asn1.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h | ||
| 87 | dsa_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
| 88 | dsa_asn1.o: ../../include/openssl/stack.h ../cryptlib.h | ||
| 89 | dsa_err.o: ../../include/openssl/bn.h ../../include/openssl/dh.h | ||
| 90 | dsa_err.o: ../../include/openssl/dsa.h ../../include/openssl/err.h | ||
| 91 | dsa_err.o: ../../include/openssl/opensslconf.h | ||
| 92 | dsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
| 93 | dsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 94 | dsa_gen.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 95 | dsa_gen.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h | ||
| 96 | dsa_gen.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h | ||
| 97 | dsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h | ||
| 98 | dsa_gen.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 99 | dsa_gen.o: ../cryptlib.h | ||
| 100 | dsa_key.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
| 101 | dsa_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 102 | dsa_key.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 103 | dsa_key.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h | ||
| 104 | dsa_key.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h | ||
| 105 | dsa_key.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h | ||
| 106 | dsa_key.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 107 | dsa_key.o: ../cryptlib.h | ||
| 108 | dsa_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 109 | dsa_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 110 | dsa_lib.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h | ||
| 111 | dsa_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h | ||
| 112 | dsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 113 | dsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 114 | dsa_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 115 | dsa_lib.o: ../cryptlib.h | ||
| 116 | dsa_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 117 | dsa_sign.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 118 | dsa_sign.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h | ||
| 119 | dsa_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h | ||
| 120 | dsa_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 121 | dsa_sign.o: ../../include/openssl/opensslconf.h | ||
| 122 | dsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h | ||
| 123 | dsa_sign.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 124 | dsa_sign.o: ../cryptlib.h | ||
| 125 | dsa_vrf.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h | ||
| 126 | dsa_vrf.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
| 127 | dsa_vrf.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 128 | dsa_vrf.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 129 | dsa_vrf.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h | ||
| 130 | dsa_vrf.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h | ||
| 131 | dsa_vrf.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h | ||
| 132 | dsa_vrf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 133 | dsa_vrf.o: ../cryptlib.h | ||
diff --git a/src/lib/libcrypto/dsa/dsa.err b/src/lib/libcrypto/dsa/dsa.err deleted file mode 100644 index 1131e9fa74..0000000000 --- a/src/lib/libcrypto/dsa/dsa.err +++ /dev/null | |||
| @@ -1,15 +0,0 @@ | |||
| 1 | /* Error codes for the DSA functions. */ | ||
| 2 | |||
| 3 | /* Function codes. */ | ||
| 4 | #define DSA_F_DSAPARAMS_PRINT 100 | ||
| 5 | #define DSA_F_DSAPARAMS_PRINT_FP 101 | ||
| 6 | #define DSA_F_DSA_IS_PRIME 102 | ||
| 7 | #define DSA_F_DSA_NEW 103 | ||
| 8 | #define DSA_F_DSA_PRINT 104 | ||
| 9 | #define DSA_F_DSA_PRINT_FP 105 | ||
| 10 | #define DSA_F_DSA_SIGN 106 | ||
| 11 | #define DSA_F_DSA_SIGN_SETUP 107 | ||
| 12 | #define DSA_F_DSA_VERIFY 108 | ||
| 13 | |||
| 14 | /* Reason codes. */ | ||
| 15 | #define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100 | ||
diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h index 1ca87c1cbe..20b3f8d90a 100644 --- a/src/lib/libcrypto/dsa/dsa.h +++ b/src/lib/libcrypto/dsa/dsa.h | |||
| @@ -69,7 +69,16 @@ | |||
| 69 | extern "C" { | 69 | extern "C" { |
| 70 | #endif | 70 | #endif |
| 71 | 71 | ||
| 72 | #include "bn.h" | 72 | #ifdef NO_DSA |
| 73 | #error DSA is disabled. | ||
| 74 | #endif | ||
| 75 | |||
| 76 | #include <openssl/bn.h> | ||
| 77 | #ifndef NO_DH | ||
| 78 | # include <openssl/dh.h> | ||
| 79 | #endif | ||
| 80 | |||
| 81 | #define DSA_FLAG_CACHE_MONT_P 0x01 | ||
| 73 | 82 | ||
| 74 | typedef struct dsa_st | 83 | typedef struct dsa_st |
| 75 | { | 84 | { |
| @@ -88,9 +97,19 @@ typedef struct dsa_st | |||
| 88 | BIGNUM *kinv; /* Signing pre-calc */ | 97 | BIGNUM *kinv; /* Signing pre-calc */ |
| 89 | BIGNUM *r; /* Signing pre-calc */ | 98 | BIGNUM *r; /* Signing pre-calc */ |
| 90 | 99 | ||
| 100 | int flags; | ||
| 101 | /* Normally used to cache montgomery values */ | ||
| 102 | char *method_mont_p; | ||
| 103 | |||
| 91 | int references; | 104 | int references; |
| 92 | } DSA; | 105 | } DSA; |
| 93 | 106 | ||
| 107 | typedef struct DSA_SIG_st | ||
| 108 | { | ||
| 109 | BIGNUM *r; | ||
| 110 | BIGNUM *s; | ||
| 111 | } DSA_SIG; | ||
| 112 | |||
| 94 | #define DSAparams_dup(x) (DSA *)ASN1_dup((int (*)())i2d_DSAparams, \ | 113 | #define DSAparams_dup(x) (DSA *)ASN1_dup((int (*)())i2d_DSAparams, \ |
| 95 | (char *(*)())d2i_DSAparams,(char *)(x)) | 114 | (char *(*)())d2i_DSAparams,(char *)(x)) |
| 96 | #define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \ | 115 | #define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \ |
| @@ -102,15 +121,23 @@ typedef struct dsa_st | |||
| 102 | #define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio(i2d_DSAparams,(bp), \ | 121 | #define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio(i2d_DSAparams,(bp), \ |
| 103 | (unsigned char *)(x)) | 122 | (unsigned char *)(x)) |
| 104 | 123 | ||
| 105 | #ifndef NOPROTO | 124 | |
| 125 | DSA_SIG * DSA_SIG_new(void); | ||
| 126 | void DSA_SIG_free(DSA_SIG *a); | ||
| 127 | int i2d_DSA_SIG(DSA_SIG *a, unsigned char **pp); | ||
| 128 | DSA_SIG * d2i_DSA_SIG(DSA_SIG **v, unsigned char **pp, long length); | ||
| 129 | |||
| 130 | DSA_SIG * DSA_do_sign(const unsigned char *dgst,int dlen,DSA *dsa); | ||
| 131 | int DSA_do_verify(const unsigned char *dgst,int dgst_len, | ||
| 132 | DSA_SIG *sig,DSA *dsa); | ||
| 106 | 133 | ||
| 107 | DSA * DSA_new(void); | 134 | DSA * DSA_new(void); |
| 108 | int DSA_size(DSA *); | 135 | int DSA_size(DSA *); |
| 109 | /* next 4 return -1 on error */ | 136 | /* next 4 return -1 on error */ |
| 110 | int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp); | 137 | int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp); |
| 111 | int DSA_sign(int type,unsigned char *dgst,int dlen, | 138 | int DSA_sign(int type,const unsigned char *dgst,int dlen, |
| 112 | unsigned char *sig, unsigned int *siglen, DSA *dsa); | 139 | unsigned char *sig, unsigned int *siglen, DSA *dsa); |
| 113 | int DSA_verify(int type,unsigned char *dgst,int dgst_len, | 140 | int DSA_verify(int type,const unsigned char *dgst,int dgst_len, |
| 114 | unsigned char *sigbuf, int siglen, DSA *dsa); | 141 | unsigned char *sigbuf, int siglen, DSA *dsa); |
| 115 | void DSA_free (DSA *r); | 142 | void DSA_free (DSA *r); |
| 116 | 143 | ||
| @@ -138,55 +165,38 @@ int DSA_print_fp(FILE *bp, DSA *x, int off); | |||
| 138 | 165 | ||
| 139 | int DSA_is_prime(BIGNUM *q,void (*callback)(),char *cb_arg); | 166 | int DSA_is_prime(BIGNUM *q,void (*callback)(),char *cb_arg); |
| 140 | 167 | ||
| 141 | #else | 168 | #ifndef NO_DH |
| 142 | 169 | /* Convert DSA structure (key or just parameters) into DH structure | |
| 143 | DSA * DSA_new(); | 170 | * (be careful to avoid small subgroup attacks when using this!) */ |
| 144 | int DSA_size(); | 171 | DH *DSA_dup_DH(DSA *r); |
| 145 | int DSA_sign_setup(); | ||
| 146 | int DSA_sign(); | ||
| 147 | int DSA_verify(); | ||
| 148 | void DSA_free (); | ||
| 149 | |||
| 150 | void ERR_load_DSA_strings(); | ||
| 151 | |||
| 152 | DSA * d2i_DSAPublicKey(); | ||
| 153 | DSA * d2i_DSAPrivateKey(); | ||
| 154 | DSA * d2i_DSAparams(); | ||
| 155 | DSA * DSA_generate_parameters(); | ||
| 156 | int DSA_generate_key(); | ||
| 157 | int i2d_DSAPublicKey(); | ||
| 158 | int i2d_DSAPrivateKey(); | ||
| 159 | int i2d_DSAparams(); | ||
| 160 | |||
| 161 | int DSA_is_prime(); | ||
| 162 | |||
| 163 | int DSAparams_print(); | ||
| 164 | int DSA_print(); | ||
| 165 | |||
| 166 | #ifndef NO_FP_API | ||
| 167 | int DSAparams_print_fp(); | ||
| 168 | int DSA_print_fp(); | ||
| 169 | #endif | ||
| 170 | |||
| 171 | #endif | 172 | #endif |
| 172 | 173 | ||
| 173 | /* BEGIN ERROR CODES */ | 174 | /* BEGIN ERROR CODES */ |
| 175 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
| 176 | * made after this point may be overwritten when the script is next run. | ||
| 177 | */ | ||
| 178 | |||
| 174 | /* Error codes for the DSA functions. */ | 179 | /* Error codes for the DSA functions. */ |
| 175 | 180 | ||
| 176 | /* Function codes. */ | 181 | /* Function codes. */ |
| 182 | #define DSA_F_D2I_DSA_SIG 110 | ||
| 177 | #define DSA_F_DSAPARAMS_PRINT 100 | 183 | #define DSA_F_DSAPARAMS_PRINT 100 |
| 178 | #define DSA_F_DSAPARAMS_PRINT_FP 101 | 184 | #define DSA_F_DSAPARAMS_PRINT_FP 101 |
| 185 | #define DSA_F_DSA_DO_SIGN 112 | ||
| 186 | #define DSA_F_DSA_DO_VERIFY 113 | ||
| 179 | #define DSA_F_DSA_IS_PRIME 102 | 187 | #define DSA_F_DSA_IS_PRIME 102 |
| 180 | #define DSA_F_DSA_NEW 103 | 188 | #define DSA_F_DSA_NEW 103 |
| 181 | #define DSA_F_DSA_PRINT 104 | 189 | #define DSA_F_DSA_PRINT 104 |
| 182 | #define DSA_F_DSA_PRINT_FP 105 | 190 | #define DSA_F_DSA_PRINT_FP 105 |
| 183 | #define DSA_F_DSA_SIGN 106 | 191 | #define DSA_F_DSA_SIGN 106 |
| 184 | #define DSA_F_DSA_SIGN_SETUP 107 | 192 | #define DSA_F_DSA_SIGN_SETUP 107 |
| 193 | #define DSA_F_DSA_SIG_NEW 109 | ||
| 185 | #define DSA_F_DSA_VERIFY 108 | 194 | #define DSA_F_DSA_VERIFY 108 |
| 195 | #define DSA_F_I2D_DSA_SIG 111 | ||
| 186 | 196 | ||
| 187 | /* Reason codes. */ | 197 | /* Reason codes. */ |
| 188 | #define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100 | 198 | #define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100 |
| 189 | 199 | ||
| 190 | #ifdef __cplusplus | 200 | #ifdef __cplusplus |
| 191 | } | 201 | } |
| 192 | #endif | 202 | #endif |
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c new file mode 100644 index 0000000000..7523b21654 --- /dev/null +++ b/src/lib/libcrypto/dsa/dsa_asn1.c | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | /* crypto/dsa/dsa_asn1.c */ | ||
| 2 | |||
| 3 | #include <stdio.h> | ||
| 4 | #include "cryptlib.h" | ||
| 5 | #include <openssl/dsa.h> | ||
| 6 | #include <openssl/asn1.h> | ||
| 7 | #include <openssl/asn1_mac.h> | ||
| 8 | |||
| 9 | DSA_SIG *DSA_SIG_new(void) | ||
| 10 | { | ||
| 11 | DSA_SIG *ret; | ||
| 12 | |||
| 13 | ret = Malloc(sizeof(DSA_SIG)); | ||
| 14 | if (ret == NULL) | ||
| 15 | { | ||
| 16 | DSAerr(DSA_F_DSA_SIG_NEW,ERR_R_MALLOC_FAILURE); | ||
| 17 | return(NULL); | ||
| 18 | } | ||
| 19 | ret->r = NULL; | ||
| 20 | ret->s = NULL; | ||
| 21 | return(ret); | ||
| 22 | } | ||
| 23 | |||
| 24 | void DSA_SIG_free(DSA_SIG *r) | ||
| 25 | { | ||
| 26 | if (r == NULL) return; | ||
| 27 | if (r->r) BN_clear_free(r->r); | ||
| 28 | if (r->s) BN_clear_free(r->s); | ||
| 29 | Free(r); | ||
| 30 | } | ||
| 31 | |||
| 32 | int i2d_DSA_SIG(DSA_SIG *v, unsigned char **pp) | ||
| 33 | { | ||
| 34 | int t=0,len; | ||
| 35 | ASN1_INTEGER rbs,sbs; | ||
| 36 | unsigned char *p; | ||
| 37 | |||
| 38 | rbs.data=Malloc(BN_num_bits(v->r)/8+1); | ||
| 39 | if (rbs.data == NULL) | ||
| 40 | { | ||
| 41 | DSAerr(DSA_F_I2D_DSA_SIG, ERR_R_MALLOC_FAILURE); | ||
| 42 | return(0); | ||
| 43 | } | ||
| 44 | rbs.type=V_ASN1_INTEGER; | ||
| 45 | rbs.length=BN_bn2bin(v->r,rbs.data); | ||
| 46 | sbs.data=Malloc(BN_num_bits(v->s)/8+1); | ||
| 47 | if (sbs.data == NULL) | ||
| 48 | { | ||
| 49 | Free(rbs.data); | ||
| 50 | DSAerr(DSA_F_I2D_DSA_SIG, ERR_R_MALLOC_FAILURE); | ||
| 51 | return(0); | ||
| 52 | } | ||
| 53 | sbs.type=V_ASN1_INTEGER; | ||
| 54 | sbs.length=BN_bn2bin(v->s,sbs.data); | ||
| 55 | |||
| 56 | len=i2d_ASN1_INTEGER(&rbs,NULL); | ||
| 57 | len+=i2d_ASN1_INTEGER(&sbs,NULL); | ||
| 58 | |||
| 59 | if (pp) | ||
| 60 | { | ||
| 61 | p=*pp; | ||
| 62 | ASN1_put_object(&p,1,len,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
| 63 | i2d_ASN1_INTEGER(&rbs,&p); | ||
| 64 | i2d_ASN1_INTEGER(&sbs,&p); | ||
| 65 | } | ||
| 66 | t=ASN1_object_size(1,len,V_ASN1_SEQUENCE); | ||
| 67 | Free(rbs.data); | ||
| 68 | Free(sbs.data); | ||
| 69 | return(t); | ||
| 70 | } | ||
| 71 | |||
| 72 | DSA_SIG *d2i_DSA_SIG(DSA_SIG **a, unsigned char **pp, long length) | ||
| 73 | { | ||
| 74 | int i=ERR_R_NESTED_ASN1_ERROR; | ||
| 75 | ASN1_INTEGER *bs=NULL; | ||
| 76 | M_ASN1_D2I_vars(a,DSA_SIG *,DSA_SIG_new); | ||
| 77 | |||
| 78 | M_ASN1_D2I_Init(); | ||
| 79 | M_ASN1_D2I_start_sequence(); | ||
| 80 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
| 81 | if ((ret->r=BN_bin2bn(bs->data,bs->length,ret->r)) == NULL) | ||
| 82 | goto err_bn; | ||
| 83 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
| 84 | if ((ret->s=BN_bin2bn(bs->data,bs->length,ret->s)) == NULL) | ||
| 85 | goto err_bn; | ||
| 86 | ASN1_BIT_STRING_free(bs); | ||
| 87 | M_ASN1_D2I_Finish_2(a); | ||
| 88 | |||
| 89 | err_bn: | ||
| 90 | i=ERR_R_BN_LIB; | ||
| 91 | err: | ||
| 92 | DSAerr(DSA_F_D2I_DSA_SIG,i); | ||
| 93 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_SIG_free(ret); | ||
| 94 | if (bs != NULL) ASN1_BIT_STRING_free(bs); | ||
| 95 | return(NULL); | ||
| 96 | } | ||
diff --git a/src/lib/libcrypto/dsa/dsa_err.c b/src/lib/libcrypto/dsa/dsa_err.c index 318e9f31aa..33a8270afd 100644 --- a/src/lib/libcrypto/dsa/dsa_err.c +++ b/src/lib/libcrypto/dsa/dsa_err.c | |||
| @@ -1,94 +1,101 @@ | |||
| 1 | /* lib/dsa/dsa_err.c */ | 1 | /* crypto/dsa/dsa_err.c */ |
| 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | 2 | /* ==================================================================== |
| 3 | * All rights reserved. | 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
| 24 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
| 25 | * are met: | 7 | * are met: |
| 26 | * 1. Redistributions of source code must retain the copyright | 8 | * |
| 27 | * notice, this list of conditions and the following disclaimer. | 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 29 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in |
| 30 | * documentation and/or other materials provided with the distribution. | 14 | * the documentation and/or other materials provided with the |
| 31 | * 3. All advertising materials mentioning features or use of this software | 15 | * distribution. |
| 32 | * must display the following acknowledgement: | 16 | * |
| 33 | * "This product includes cryptographic software written by | 17 | * 3. All advertising materials mentioning features or use of this |
| 34 | * Eric Young (eay@cryptsoft.com)" | 18 | * software must display the following acknowledgment: |
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | 19 | * "This product includes software developed by the OpenSSL Project |
| 36 | * being used are not cryptographic related :-). | 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" |
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 21 | * |
| 38 | * the apps directory (application code) you must include an acknowledgement: | 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 23 | * endorse or promote products derived from this software without |
| 40 | * | 24 | * prior written permission. For written permission, please contact |
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 25 | * openssl-core@OpenSSL.org. |
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 26 | * |
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 27 | * 5. Products derived from this software may not be called "OpenSSL" |
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 28 | * nor may "OpenSSL" appear in their names without prior written |
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 29 | * permission of the OpenSSL Project. |
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 30 | * |
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 31 | * 6. Redistributions of any form whatsoever must retain the following |
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 32 | * acknowledgment: |
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 33 | * "This product includes software developed by the OpenSSL Project |
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" |
| 51 | * SUCH DAMAGE. | 35 | * |
| 52 | * | 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
| 53 | * The licence and distribution terms for any publically available version or | 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 55 | * copied and put under another distribution licence | 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR |
| 56 | * [including the GNU Public Licence.] | 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 57 | */ | 54 | */ |
| 55 | |||
| 56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
| 57 | * made to it will be overwritten when the script next updates this file. | ||
| 58 | */ | ||
| 59 | |||
| 58 | #include <stdio.h> | 60 | #include <stdio.h> |
| 59 | #include "err.h" | 61 | #include <openssl/err.h> |
| 60 | #include "dsa.h" | 62 | #include <openssl/dsa.h> |
| 61 | 63 | ||
| 62 | /* BEGIN ERROR CODES */ | 64 | /* BEGIN ERROR CODES */ |
| 63 | #ifndef NO_ERR | 65 | #ifndef NO_ERR |
| 64 | static ERR_STRING_DATA DSA_str_functs[]= | 66 | static ERR_STRING_DATA DSA_str_functs[]= |
| 65 | { | 67 | { |
| 68 | {ERR_PACK(0,DSA_F_D2I_DSA_SIG,0), "d2i_DSA_SIG"}, | ||
| 66 | {ERR_PACK(0,DSA_F_DSAPARAMS_PRINT,0), "DSAparams_print"}, | 69 | {ERR_PACK(0,DSA_F_DSAPARAMS_PRINT,0), "DSAparams_print"}, |
| 67 | {ERR_PACK(0,DSA_F_DSAPARAMS_PRINT_FP,0), "DSAparams_print_fp"}, | 70 | {ERR_PACK(0,DSA_F_DSAPARAMS_PRINT_FP,0), "DSAparams_print_fp"}, |
| 71 | {ERR_PACK(0,DSA_F_DSA_DO_SIGN,0), "DSA_do_sign"}, | ||
| 72 | {ERR_PACK(0,DSA_F_DSA_DO_VERIFY,0), "DSA_do_verify"}, | ||
| 68 | {ERR_PACK(0,DSA_F_DSA_IS_PRIME,0), "DSA_is_prime"}, | 73 | {ERR_PACK(0,DSA_F_DSA_IS_PRIME,0), "DSA_is_prime"}, |
| 69 | {ERR_PACK(0,DSA_F_DSA_NEW,0), "DSA_new"}, | 74 | {ERR_PACK(0,DSA_F_DSA_NEW,0), "DSA_new"}, |
| 70 | {ERR_PACK(0,DSA_F_DSA_PRINT,0), "DSA_print"}, | 75 | {ERR_PACK(0,DSA_F_DSA_PRINT,0), "DSA_print"}, |
| 71 | {ERR_PACK(0,DSA_F_DSA_PRINT_FP,0), "DSA_print_fp"}, | 76 | {ERR_PACK(0,DSA_F_DSA_PRINT_FP,0), "DSA_print_fp"}, |
| 72 | {ERR_PACK(0,DSA_F_DSA_SIGN,0), "DSA_sign"}, | 77 | {ERR_PACK(0,DSA_F_DSA_SIGN,0), "DSA_sign"}, |
| 73 | {ERR_PACK(0,DSA_F_DSA_SIGN_SETUP,0), "DSA_sign_setup"}, | 78 | {ERR_PACK(0,DSA_F_DSA_SIGN_SETUP,0), "DSA_sign_setup"}, |
| 79 | {ERR_PACK(0,DSA_F_DSA_SIG_NEW,0), "DSA_SIG_new"}, | ||
| 74 | {ERR_PACK(0,DSA_F_DSA_VERIFY,0), "DSA_verify"}, | 80 | {ERR_PACK(0,DSA_F_DSA_VERIFY,0), "DSA_verify"}, |
| 75 | {0,NULL}, | 81 | {ERR_PACK(0,DSA_F_I2D_DSA_SIG,0), "i2d_DSA_SIG"}, |
| 82 | {0,NULL} | ||
| 76 | }; | 83 | }; |
| 77 | 84 | ||
| 78 | static ERR_STRING_DATA DSA_str_reasons[]= | 85 | static ERR_STRING_DATA DSA_str_reasons[]= |
| 79 | { | 86 | { |
| 80 | {DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"}, | 87 | {DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"}, |
| 81 | {0,NULL}, | 88 | {0,NULL} |
| 82 | }; | 89 | }; |
| 83 | 90 | ||
| 84 | #endif | 91 | #endif |
| 85 | 92 | ||
| 86 | void ERR_load_DSA_strings() | 93 | void ERR_load_DSA_strings(void) |
| 87 | { | 94 | { |
| 88 | static int init=1; | 95 | static int init=1; |
| 89 | 96 | ||
| 90 | if (init); | 97 | if (init) |
| 91 | {; | 98 | { |
| 92 | init=0; | 99 | init=0; |
| 93 | #ifndef NO_ERR | 100 | #ifndef NO_ERR |
| 94 | ERR_load_strings(ERR_LIB_DSA,DSA_str_functs); | 101 | ERR_load_strings(ERR_LIB_DSA,DSA_str_functs); |
diff --git a/src/lib/libcrypto/dsa/dsa_gen.c b/src/lib/libcrypto/dsa/dsa_gen.c index d7d30bf90a..b5e5ec06e5 100644 --- a/src/lib/libcrypto/dsa/dsa_gen.c +++ b/src/lib/libcrypto/dsa/dsa_gen.c | |||
| @@ -64,23 +64,18 @@ | |||
| 64 | #define HASH SHA1 | 64 | #define HASH SHA1 |
| 65 | #endif | 65 | #endif |
| 66 | 66 | ||
| 67 | #ifndef NO_SHA | ||
| 67 | #include <stdio.h> | 68 | #include <stdio.h> |
| 68 | #include <time.h> | 69 | #include <time.h> |
| 69 | #include "cryptlib.h" | 70 | #include "cryptlib.h" |
| 70 | #include "sha.h" | 71 | #include <openssl/sha.h> |
| 71 | #include "bn.h" | 72 | #include <openssl/bn.h> |
| 72 | #include "dsa.h" | 73 | #include <openssl/dsa.h> |
| 73 | #include "rand.h" | 74 | #include <openssl/rand.h> |
| 74 | 75 | ||
| 75 | DSA *DSA_generate_parameters(bits,seed_in,seed_len,counter_ret,h_ret,callback, | 76 | DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len, |
| 76 | cb_arg) | 77 | int *counter_ret, unsigned long *h_ret, void (*callback)(), |
| 77 | int bits; | 78 | char *cb_arg) |
| 78 | unsigned char *seed_in; | ||
| 79 | int seed_len; | ||
| 80 | int *counter_ret; | ||
| 81 | unsigned long *h_ret; | ||
| 82 | void (*callback)(); | ||
| 83 | char *cb_arg; | ||
| 84 | { | 79 | { |
| 85 | int ok=0; | 80 | int ok=0; |
| 86 | unsigned char seed[SHA_DIGEST_LENGTH]; | 81 | unsigned char seed[SHA_DIGEST_LENGTH]; |
| @@ -88,6 +83,7 @@ char *cb_arg; | |||
| 88 | unsigned char buf[SHA_DIGEST_LENGTH],buf2[SHA_DIGEST_LENGTH]; | 83 | unsigned char buf[SHA_DIGEST_LENGTH],buf2[SHA_DIGEST_LENGTH]; |
| 89 | BIGNUM *r0,*W,*X,*c,*test; | 84 | BIGNUM *r0,*W,*X,*c,*test; |
| 90 | BIGNUM *g=NULL,*q=NULL,*p=NULL; | 85 | BIGNUM *g=NULL,*q=NULL,*p=NULL; |
| 86 | BN_MONT_CTX *mont=NULL; | ||
| 91 | int k,n=0,i,b,m=0; | 87 | int k,n=0,i,b,m=0; |
| 92 | int counter=0; | 88 | int counter=0; |
| 93 | BN_CTX *ctx=NULL,*ctx2=NULL; | 89 | BN_CTX *ctx=NULL,*ctx2=NULL; |
| @@ -100,20 +96,20 @@ char *cb_arg; | |||
| 100 | if ((seed_in != NULL) && (seed_len == 20)) | 96 | if ((seed_in != NULL) && (seed_len == 20)) |
| 101 | memcpy(seed,seed_in,seed_len); | 97 | memcpy(seed,seed_in,seed_len); |
| 102 | 98 | ||
| 103 | ctx=BN_CTX_new(); | 99 | if ((ctx=BN_CTX_new()) == NULL) goto err; |
| 104 | if (ctx == NULL) goto err; | 100 | if ((ctx2=BN_CTX_new()) == NULL) goto err; |
| 105 | ctx2=BN_CTX_new(); | 101 | if ((ret=DSA_new()) == NULL) goto err; |
| 106 | if (ctx2 == NULL) goto err; | 102 | |
| 107 | ret=DSA_new(); | 103 | if ((mont=BN_MONT_CTX_new()) == NULL) goto err; |
| 108 | if (ret == NULL) goto err; | 104 | |
| 109 | r0=ctx2->bn[0]; | 105 | r0= &(ctx2->bn[0]); |
| 110 | g=ctx2->bn[1]; | 106 | g= &(ctx2->bn[1]); |
| 111 | W=ctx2->bn[2]; | 107 | W= &(ctx2->bn[2]); |
| 112 | q=ctx2->bn[3]; | 108 | q= &(ctx2->bn[3]); |
| 113 | X=ctx2->bn[4]; | 109 | X= &(ctx2->bn[4]); |
| 114 | c=ctx2->bn[5]; | 110 | c= &(ctx2->bn[5]); |
| 115 | p=ctx2->bn[6]; | 111 | p= &(ctx2->bn[6]); |
| 116 | test=ctx2->bn[7]; | 112 | test= &(ctx2->bn[7]); |
| 117 | 113 | ||
| 118 | BN_lshift(test,BN_value_one(),bits-1); | 114 | BN_lshift(test,BN_value_one(),bits-1); |
| 119 | 115 | ||
| @@ -216,14 +212,16 @@ end: | |||
| 216 | 212 | ||
| 217 | /* We now need to gernerate g */ | 213 | /* We now need to gernerate g */ |
| 218 | /* Set r0=(p-1)/q */ | 214 | /* Set r0=(p-1)/q */ |
| 219 | BN_sub(test,p,BN_value_one()); | 215 | BN_sub(test,p,BN_value_one()); |
| 220 | BN_div(r0,NULL,test,q,ctx); | 216 | BN_div(r0,NULL,test,q,ctx); |
| 221 | 217 | ||
| 222 | BN_set_word(test,h); | 218 | BN_set_word(test,h); |
| 219 | BN_MONT_CTX_set(mont,p,ctx); | ||
| 220 | |||
| 223 | for (;;) | 221 | for (;;) |
| 224 | { | 222 | { |
| 225 | /* g=test^r0%p */ | 223 | /* g=test^r0%p */ |
| 226 | BN_mod_exp(g,test,r0,p,ctx); | 224 | BN_mod_exp_mont(g,test,r0,p,ctx,mont); |
| 227 | if (!BN_is_one(g)) break; | 225 | if (!BN_is_one(g)) break; |
| 228 | BN_add(test,test,BN_value_one()); | 226 | BN_add(test,test,BN_value_one()); |
| 229 | h++; | 227 | h++; |
| @@ -246,32 +244,32 @@ err: | |||
| 246 | if (counter_ret != NULL) *counter_ret=counter; | 244 | if (counter_ret != NULL) *counter_ret=counter; |
| 247 | if (h_ret != NULL) *h_ret=h; | 245 | if (h_ret != NULL) *h_ret=h; |
| 248 | } | 246 | } |
| 249 | BN_CTX_free(ctx); | 247 | if (ctx != NULL) BN_CTX_free(ctx); |
| 250 | BN_CTX_free(ctx2); | 248 | if (ctx != NULL) BN_CTX_free(ctx2); |
| 249 | if (mont != NULL) BN_MONT_CTX_free(mont); | ||
| 251 | return(ok?ret:NULL); | 250 | return(ok?ret:NULL); |
| 252 | } | 251 | } |
| 253 | 252 | ||
| 254 | int DSA_is_prime(w, callback,cb_arg) | 253 | int DSA_is_prime(BIGNUM *w, void (*callback)(), char *cb_arg) |
| 255 | BIGNUM *w; | ||
| 256 | void (*callback)(); | ||
| 257 | char *cb_arg; | ||
| 258 | { | 254 | { |
| 259 | int ok= -1,j,i,n; | 255 | int ok= -1,j,i,n; |
| 260 | BN_CTX *ctx=NULL,*ctx2=NULL; | 256 | BN_CTX *ctx=NULL,*ctx2=NULL; |
| 261 | BIGNUM *w_1,*b,*m,*z; | 257 | BIGNUM *w_1,*b,*m,*z,*tmp,*mont_1; |
| 262 | int a; | 258 | int a; |
| 259 | BN_MONT_CTX *mont=NULL; | ||
| 263 | 260 | ||
| 264 | if (!BN_is_bit_set(w,0)) return(0); | 261 | if (!BN_is_bit_set(w,0)) return(0); |
| 265 | 262 | ||
| 266 | ctx=BN_CTX_new(); | 263 | if ((ctx=BN_CTX_new()) == NULL) goto err; |
| 267 | if (ctx == NULL) goto err; | 264 | if ((ctx2=BN_CTX_new()) == NULL) goto err; |
| 268 | ctx2=BN_CTX_new(); | 265 | if ((mont=BN_MONT_CTX_new()) == NULL) goto err; |
| 269 | if (ctx2 == NULL) goto err; | ||
| 270 | 266 | ||
| 271 | m= ctx2->bn[2]; | 267 | m= &(ctx2->bn[2]); |
| 272 | b= ctx2->bn[3]; | 268 | b= &(ctx2->bn[3]); |
| 273 | z= ctx2->bn[4]; | 269 | z= &(ctx2->bn[4]); |
| 274 | w_1=ctx2->bn[5]; | 270 | w_1= &(ctx2->bn[5]); |
| 271 | tmp= &(ctx2->bn[6]); | ||
| 272 | mont_1= &(ctx2->bn[7]); | ||
| 275 | 273 | ||
| 276 | /* step 1 */ | 274 | /* step 1 */ |
| 277 | n=50; | 275 | n=50; |
| @@ -282,24 +280,30 @@ char *cb_arg; | |||
| 282 | ; | 280 | ; |
| 283 | if (!BN_rshift(m,w_1,a)) goto err; | 281 | if (!BN_rshift(m,w_1,a)) goto err; |
| 284 | 282 | ||
| 283 | BN_MONT_CTX_set(mont,w,ctx); | ||
| 284 | BN_to_montgomery(mont_1,BN_value_one(),mont,ctx); | ||
| 285 | BN_to_montgomery(w_1,w_1,mont,ctx); | ||
| 285 | for (i=1; i < n; i++) | 286 | for (i=1; i < n; i++) |
| 286 | { | 287 | { |
| 287 | /* step 3 */ | 288 | /* step 3 */ |
| 288 | BN_rand(b,BN_num_bits(w)-2/*-1*/,0,0); | 289 | BN_rand(b,BN_num_bits(w)-2/*-1*/,0,0); |
| 289 | BN_set_word(b,0x10001L); | 290 | /* BN_set_word(b,0x10001L); */ |
| 290 | 291 | ||
| 291 | /* step 4 */ | 292 | /* step 4 */ |
| 292 | j=0; | 293 | j=0; |
| 293 | if (!BN_mod_exp(z,b,m,w,ctx)) goto err; | 294 | if (!BN_mod_exp_mont(z,b,m,w,ctx,mont)) goto err; |
| 295 | |||
| 296 | if (!BN_to_montgomery(z,z,mont,ctx)) goto err; | ||
| 294 | 297 | ||
| 295 | /* step 5 */ | 298 | /* step 5 */ |
| 296 | for (;;) | 299 | for (;;) |
| 297 | { | 300 | { |
| 298 | if (((j == 0) && BN_is_one(z)) || (BN_cmp(z,w_1) == 0)) | 301 | if (((j == 0) && (BN_cmp(z,mont_1) == 0)) || |
| 302 | (BN_cmp(z,w_1) == 0)) | ||
| 299 | break; | 303 | break; |
| 300 | 304 | ||
| 301 | /* step 6 */ | 305 | /* step 6 */ |
| 302 | if ((j > 0) && BN_is_one(z)) | 306 | if ((j > 0) && (BN_cmp(z,mont_1) == 0)) |
| 303 | { | 307 | { |
| 304 | ok=0; | 308 | ok=0; |
| 305 | goto err; | 309 | goto err; |
| @@ -312,7 +316,7 @@ char *cb_arg; | |||
| 312 | goto err; | 316 | goto err; |
| 313 | } | 317 | } |
| 314 | 318 | ||
| 315 | if (!BN_mod_mul(z,z,z,w,ctx)) goto err; | 319 | if (!BN_mod_mul_montgomery(z,z,z,mont,ctx)) goto err; |
| 316 | if (callback != NULL) callback(1,j,cb_arg); | 320 | if (callback != NULL) callback(1,j,cb_arg); |
| 317 | } | 321 | } |
| 318 | } | 322 | } |
| @@ -322,7 +326,8 @@ err: | |||
| 322 | if (ok == -1) DSAerr(DSA_F_DSA_IS_PRIME,ERR_R_BN_LIB); | 326 | if (ok == -1) DSAerr(DSA_F_DSA_IS_PRIME,ERR_R_BN_LIB); |
| 323 | BN_CTX_free(ctx); | 327 | BN_CTX_free(ctx); |
| 324 | BN_CTX_free(ctx2); | 328 | BN_CTX_free(ctx2); |
| 329 | BN_MONT_CTX_free(mont); | ||
| 325 | 330 | ||
| 326 | return(ok); | 331 | return(ok); |
| 327 | } | 332 | } |
| 328 | 333 | #endif | |
diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c index d51ed9395f..ab7f38fc7c 100644 --- a/src/lib/libcrypto/dsa/dsa_key.c +++ b/src/lib/libcrypto/dsa/dsa_key.c | |||
| @@ -56,16 +56,16 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #ifndef NO_SHA | ||
| 59 | #include <stdio.h> | 60 | #include <stdio.h> |
| 60 | #include <time.h> | 61 | #include <time.h> |
| 61 | #include "cryptlib.h" | 62 | #include "cryptlib.h" |
| 62 | #include "sha.h" | 63 | #include <openssl/sha.h> |
| 63 | #include "bn.h" | 64 | #include <openssl/bn.h> |
| 64 | #include "dsa.h" | 65 | #include <openssl/dsa.h> |
| 65 | #include "rand.h" | 66 | #include <openssl/rand.h> |
| 66 | 67 | ||
| 67 | int DSA_generate_key(dsa) | 68 | int DSA_generate_key(DSA *dsa) |
| 68 | DSA *dsa; | ||
| 69 | { | 69 | { |
| 70 | int ok=0; | 70 | int ok=0; |
| 71 | unsigned int i; | 71 | unsigned int i; |
| @@ -109,4 +109,4 @@ err: | |||
| 109 | if (ctx != NULL) BN_CTX_free(ctx); | 109 | if (ctx != NULL) BN_CTX_free(ctx); |
| 110 | return(ok); | 110 | return(ok); |
| 111 | } | 111 | } |
| 112 | 112 | #endif | |
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c index b647257f9f..ce8e204f7e 100644 --- a/src/lib/libcrypto/dsa/dsa_lib.c +++ b/src/lib/libcrypto/dsa/dsa_lib.c | |||
| @@ -56,17 +56,17 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | /* Origional version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ | 59 | /* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ |
| 60 | 60 | ||
| 61 | #include <stdio.h> | 61 | #include <stdio.h> |
| 62 | #include "cryptlib.h" | 62 | #include "cryptlib.h" |
| 63 | #include "bn.h" | 63 | #include <openssl/bn.h> |
| 64 | #include "dsa.h" | 64 | #include <openssl/dsa.h> |
| 65 | #include "asn1.h" | 65 | #include <openssl/asn1.h> |
| 66 | 66 | ||
| 67 | char *DSA_version="\0DSA part of SSLeay 0.9.0b 29-Jun-1998"; | 67 | const char *DSA_version="DSA" OPENSSL_VERSION_PTEXT; |
| 68 | 68 | ||
| 69 | DSA *DSA_new() | 69 | DSA *DSA_new(void) |
| 70 | { | 70 | { |
| 71 | DSA *ret; | 71 | DSA *ret; |
| 72 | 72 | ||
| @@ -82,19 +82,20 @@ DSA *DSA_new() | |||
| 82 | ret->p=NULL; | 82 | ret->p=NULL; |
| 83 | ret->q=NULL; | 83 | ret->q=NULL; |
| 84 | ret->g=NULL; | 84 | ret->g=NULL; |
| 85 | ret->flags=DSA_FLAG_CACHE_MONT_P; | ||
| 85 | 86 | ||
| 86 | ret->pub_key=NULL; | 87 | ret->pub_key=NULL; |
| 87 | ret->priv_key=NULL; | 88 | ret->priv_key=NULL; |
| 88 | 89 | ||
| 89 | ret->kinv=NULL; | 90 | ret->kinv=NULL; |
| 90 | ret->r=NULL; | 91 | ret->r=NULL; |
| 92 | ret->method_mont_p=NULL; | ||
| 91 | 93 | ||
| 92 | ret->references=1; | 94 | ret->references=1; |
| 93 | return(ret); | 95 | return(ret); |
| 94 | } | 96 | } |
| 95 | 97 | ||
| 96 | void DSA_free(r) | 98 | void DSA_free(DSA *r) |
| 97 | DSA *r; | ||
| 98 | { | 99 | { |
| 99 | int i; | 100 | int i; |
| 100 | 101 | ||
| @@ -120,11 +121,12 @@ DSA *r; | |||
| 120 | if (r->priv_key != NULL) BN_clear_free(r->priv_key); | 121 | if (r->priv_key != NULL) BN_clear_free(r->priv_key); |
| 121 | if (r->kinv != NULL) BN_clear_free(r->kinv); | 122 | if (r->kinv != NULL) BN_clear_free(r->kinv); |
| 122 | if (r->r != NULL) BN_clear_free(r->r); | 123 | if (r->r != NULL) BN_clear_free(r->r); |
| 124 | if (r->method_mont_p != NULL) | ||
| 125 | BN_MONT_CTX_free((BN_MONT_CTX *)r->method_mont_p); | ||
| 123 | Free(r); | 126 | Free(r); |
| 124 | } | 127 | } |
| 125 | 128 | ||
| 126 | int DSA_size(r) | 129 | int DSA_size(DSA *r) |
| 127 | DSA *r; | ||
| 128 | { | 130 | { |
| 129 | int ret,i; | 131 | int ret,i; |
| 130 | ASN1_INTEGER bs; | 132 | ASN1_INTEGER bs; |
| @@ -143,3 +145,40 @@ DSA *r; | |||
| 143 | return(ret); | 145 | return(ret); |
| 144 | } | 146 | } |
| 145 | 147 | ||
| 148 | #ifndef NO_DH | ||
| 149 | DH *DSA_dup_DH(DSA *r) | ||
| 150 | { | ||
| 151 | /* DSA has p, q, g, optional pub_key, optional priv_key. | ||
| 152 | * DH has p, optional length, g, optional pub_key, optional priv_key. | ||
| 153 | */ | ||
| 154 | |||
| 155 | DH *ret = NULL; | ||
| 156 | |||
| 157 | if (r == NULL) | ||
| 158 | goto err; | ||
| 159 | ret = DH_new(); | ||
| 160 | if (ret == NULL) | ||
| 161 | goto err; | ||
| 162 | if (r->p != NULL) | ||
| 163 | if ((ret->p = BN_dup(r->p)) == NULL) | ||
| 164 | goto err; | ||
| 165 | if (r->q != NULL) | ||
| 166 | ret->length = BN_num_bits(r->q); | ||
| 167 | if (r->g != NULL) | ||
| 168 | if ((ret->g = BN_dup(r->g)) == NULL) | ||
| 169 | goto err; | ||
| 170 | if (r->pub_key != NULL) | ||
| 171 | if ((ret->pub_key = BN_dup(r->pub_key)) == NULL) | ||
| 172 | goto err; | ||
| 173 | if (r->priv_key != NULL) | ||
| 174 | if ((ret->priv_key = BN_dup(r->priv_key)) == NULL) | ||
| 175 | goto err; | ||
| 176 | |||
| 177 | return ret; | ||
| 178 | |||
| 179 | err: | ||
| 180 | if (ret != NULL) | ||
| 181 | DH_free(ret); | ||
| 182 | return NULL; | ||
| 183 | } | ||
| 184 | #endif | ||
diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c index 6ca1c318f2..774c161964 100644 --- a/src/lib/libcrypto/dsa/dsa_sign.c +++ b/src/lib/libcrypto/dsa/dsa_sign.c | |||
| @@ -56,35 +56,28 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | /* Origional version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ | 59 | /* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ |
| 60 | 60 | ||
| 61 | #include <stdio.h> | 61 | #include <stdio.h> |
| 62 | #include "cryptlib.h" | 62 | #include "cryptlib.h" |
| 63 | #include "bn.h" | 63 | #include <openssl/bn.h> |
| 64 | #include "dsa.h" | 64 | #include <openssl/dsa.h> |
| 65 | #include "rand.h" | 65 | #include <openssl/rand.h> |
| 66 | #include "asn1.h" | 66 | #include <openssl/asn1.h> |
| 67 | 67 | ||
| 68 | /* data has already been hashed (probably with SHA or SHA-1). */ | 68 | DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) |
| 69 | /* DSAerr(DSA_F_DSA_SIGN,DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); */ | ||
| 70 | |||
| 71 | int DSA_sign(type,dgst,dlen,sig,siglen,dsa) | ||
| 72 | int type; | ||
| 73 | unsigned char *dgst; | ||
| 74 | int dlen; | ||
| 75 | unsigned char *sig; /* out */ | ||
| 76 | unsigned int *siglen; /* out */ | ||
| 77 | DSA *dsa; | ||
| 78 | { | 69 | { |
| 79 | BIGNUM *kinv=NULL,*r=NULL; | 70 | BIGNUM *kinv=NULL,*r=NULL,*s=NULL; |
| 80 | BIGNUM *m=NULL; | 71 | BIGNUM m; |
| 81 | BIGNUM *xr=NULL,*s=NULL; | 72 | BIGNUM xr; |
| 82 | BN_CTX *ctx=NULL; | 73 | BN_CTX *ctx=NULL; |
| 83 | unsigned char *p; | 74 | int i,reason=ERR_R_BN_LIB; |
| 84 | int i,len=0,ret=0,reason=ERR_R_BN_LIB; | 75 | DSA_SIG *ret=NULL; |
| 85 | ASN1_INTEGER rbs,sbs; | 76 | |
| 86 | MS_STATIC unsigned char rbuf[50]; /* assuming r is 20 bytes +extra */ | 77 | BN_init(&m); |
| 87 | MS_STATIC unsigned char sbuf[50]; /* assuming s is 20 bytes +extra */ | 78 | BN_init(&xr); |
| 79 | s=BN_new(); | ||
| 80 | if (s == NULL) goto err; | ||
| 88 | 81 | ||
| 89 | i=BN_num_bytes(dsa->q); /* should be 20 */ | 82 | i=BN_num_bytes(dsa->q); /* should be 20 */ |
| 90 | if ((dlen > i) || (dlen > 50)) | 83 | if ((dlen > i) || (dlen > 50)) |
| @@ -108,59 +101,58 @@ DSA *dsa; | |||
| 108 | dsa->r=NULL; | 101 | dsa->r=NULL; |
| 109 | } | 102 | } |
| 110 | 103 | ||
| 111 | m=BN_new(); | 104 | if (BN_bin2bn(dgst,dlen,&m) == NULL) goto err; |
| 112 | xr=BN_new(); | ||
| 113 | s=BN_new(); | ||
| 114 | if (m == NULL || xr == NULL || s == NULL) goto err; | ||
| 115 | |||
| 116 | if (BN_bin2bn(dgst,dlen,m) == NULL) goto err; | ||
| 117 | 105 | ||
| 118 | /* Compute s = inv(k) (m + xr) mod q */ | 106 | /* Compute s = inv(k) (m + xr) mod q */ |
| 119 | if (!BN_mul(xr, dsa->priv_key, r)) goto err; /* s = xr */ | 107 | if (!BN_mod_mul(&xr,dsa->priv_key,r,dsa->q,ctx)) goto err;/* s = xr */ |
| 120 | if (!BN_add(s, xr, m)) goto err; /* s = m + xr */ | 108 | if (!BN_add(s, &xr, &m)) goto err; /* s = m + xr */ |
| 109 | if (BN_cmp(s,dsa->q) > 0) | ||
| 110 | BN_sub(s,s,dsa->q); | ||
| 121 | if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err; | 111 | if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err; |
| 122 | 112 | ||
| 123 | /* | 113 | ret=DSA_SIG_new(); |
| 124 | * Now create a ASN.1 sequence of the integers R and S. | 114 | if (ret == NULL) goto err; |
| 125 | */ | 115 | ret->r = r; |
| 126 | rbs.data=rbuf; | 116 | ret->s = s; |
| 127 | sbs.data=sbuf; | 117 | |
| 128 | rbs.type = V_ASN1_INTEGER; | ||
| 129 | sbs.type = V_ASN1_INTEGER; | ||
| 130 | rbs.length=BN_bn2bin(r,rbs.data); | ||
| 131 | sbs.length=BN_bn2bin(s,sbs.data); | ||
| 132 | |||
| 133 | len =i2d_ASN1_INTEGER(&rbs,NULL); | ||
| 134 | len+=i2d_ASN1_INTEGER(&sbs,NULL); | ||
| 135 | |||
| 136 | p=sig; | ||
| 137 | ASN1_put_object(&p,1,len,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
| 138 | i2d_ASN1_INTEGER(&rbs,&p); | ||
| 139 | i2d_ASN1_INTEGER(&sbs,&p); | ||
| 140 | *siglen=(p-sig); | ||
| 141 | ret=1; | ||
| 142 | err: | 118 | err: |
| 143 | if (!ret) DSAerr(DSA_F_DSA_SIGN,reason); | 119 | if (!ret) |
| 144 | 120 | { | |
| 145 | #if 1 /* do the right thing :-) */ | 121 | DSAerr(DSA_F_DSA_DO_SIGN,reason); |
| 146 | if (kinv != NULL) BN_clear_free(kinv); | 122 | BN_free(r); |
| 147 | if (r != NULL) BN_clear_free(r); | 123 | BN_free(s); |
| 148 | #endif | 124 | } |
| 149 | if (ctx != NULL) BN_CTX_free(ctx); | 125 | if (ctx != NULL) BN_CTX_free(ctx); |
| 150 | if (m != NULL) BN_clear_free(m); | 126 | BN_clear_free(&m); |
| 151 | if (xr != NULL) BN_clear_free(xr); | 127 | BN_clear_free(&xr); |
| 152 | if (s != NULL) BN_clear_free(s); | 128 | if (kinv != NULL) /* dsa->kinv is NULL now if we used it */ |
| 129 | BN_clear_free(kinv); | ||
| 153 | return(ret); | 130 | return(ret); |
| 154 | } | 131 | } |
| 155 | 132 | ||
| 156 | int DSA_sign_setup(dsa,ctx_in,kinvp,rp) | 133 | /* data has already been hashed (probably with SHA or SHA-1). */ |
| 157 | DSA *dsa; | 134 | |
| 158 | BN_CTX *ctx_in; | 135 | /* unsigned char *sig: out */ |
| 159 | BIGNUM **kinvp; | 136 | /* unsigned int *siglen: out */ |
| 160 | BIGNUM **rp; | 137 | int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig, |
| 138 | unsigned int *siglen, DSA *dsa) | ||
| 139 | { | ||
| 140 | DSA_SIG *s; | ||
| 141 | s=DSA_do_sign(dgst,dlen,dsa); | ||
| 142 | if (s == NULL) | ||
| 143 | { | ||
| 144 | *siglen=0; | ||
| 145 | return(0); | ||
| 146 | } | ||
| 147 | *siglen=i2d_DSA_SIG(s,&sig); | ||
| 148 | DSA_SIG_free(s); | ||
| 149 | return(1); | ||
| 150 | } | ||
| 151 | |||
| 152 | int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) | ||
| 161 | { | 153 | { |
| 162 | BN_CTX *ctx; | 154 | BN_CTX *ctx; |
| 163 | BIGNUM *k=NULL,*kinv=NULL,*r=NULL; | 155 | BIGNUM k,*kinv=NULL,*r=NULL; |
| 164 | int ret=0; | 156 | int ret=0; |
| 165 | 157 | ||
| 166 | if (ctx_in == NULL) | 158 | if (ctx_in == NULL) |
| @@ -170,29 +162,33 @@ BIGNUM **rp; | |||
| 170 | else | 162 | else |
| 171 | ctx=ctx_in; | 163 | ctx=ctx_in; |
| 172 | 164 | ||
| 173 | r=BN_new(); | 165 | BN_init(&k); |
| 174 | k=BN_new(); | 166 | if ((r=BN_new()) == NULL) goto err; |
| 175 | if ((r == NULL) || (k == NULL)) | ||
| 176 | goto err; | ||
| 177 | kinv=NULL; | 167 | kinv=NULL; |
| 178 | 168 | ||
| 179 | if (r == NULL) goto err; | ||
| 180 | |||
| 181 | /* Get random k */ | 169 | /* Get random k */ |
| 182 | for (;;) | 170 | for (;;) |
| 183 | { | 171 | { |
| 184 | if (!BN_rand(k, BN_num_bits(dsa->q), 1, 0)) goto err; | 172 | if (!BN_rand(&k, BN_num_bits(dsa->q), 1, 0)) goto err; |
| 185 | if (BN_cmp(k,dsa->q) >= 0) | 173 | if (BN_cmp(&k,dsa->q) >= 0) |
| 186 | BN_sub(k,k,dsa->q); | 174 | BN_sub(&k,&k,dsa->q); |
| 187 | if (!BN_is_zero(k)) break; | 175 | if (!BN_is_zero(&k)) break; |
| 176 | } | ||
| 177 | |||
| 178 | if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P)) | ||
| 179 | { | ||
| 180 | if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL) | ||
| 181 | if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p, | ||
| 182 | dsa->p,ctx)) goto err; | ||
| 188 | } | 183 | } |
| 189 | 184 | ||
| 190 | /* Compute r = (g^k mod p) mod q */ | 185 | /* Compute r = (g^k mod p) mod q */ |
| 191 | if (!BN_mod_exp(r,dsa->g,k,dsa->p,ctx)) goto err; | 186 | if (!BN_mod_exp_mont(r,dsa->g,&k,dsa->p,ctx, |
| 187 | (BN_MONT_CTX *)dsa->method_mont_p)) goto err; | ||
| 192 | if (!BN_mod(r,r,dsa->q,ctx)) goto err; | 188 | if (!BN_mod(r,r,dsa->q,ctx)) goto err; |
| 193 | 189 | ||
| 194 | /* Compute part of 's = inv(k) (m + xr) mod q' */ | 190 | /* Compute part of 's = inv(k) (m + xr) mod q' */ |
| 195 | if ((kinv=BN_mod_inverse(k,dsa->q,ctx)) == NULL) goto err; | 191 | if ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err; |
| 196 | 192 | ||
| 197 | if (*kinvp != NULL) BN_clear_free(*kinvp); | 193 | if (*kinvp != NULL) BN_clear_free(*kinvp); |
| 198 | *kinvp=kinv; | 194 | *kinvp=kinv; |
| @@ -208,8 +204,8 @@ err: | |||
| 208 | if (r != NULL) BN_clear_free(r); | 204 | if (r != NULL) BN_clear_free(r); |
| 209 | } | 205 | } |
| 210 | if (ctx_in == NULL) BN_CTX_free(ctx); | 206 | if (ctx_in == NULL) BN_CTX_free(ctx); |
| 211 | if (k != NULL) BN_clear_free(k); | ||
| 212 | if (kinv != NULL) BN_clear_free(kinv); | 207 | if (kinv != NULL) BN_clear_free(kinv); |
| 208 | BN_clear_free(&k); | ||
| 213 | return(ret); | 209 | return(ret); |
| 214 | } | 210 | } |
| 215 | 211 | ||
diff --git a/src/lib/libcrypto/dsa/dsa_vrf.c b/src/lib/libcrypto/dsa/dsa_vrf.c index 0f860984ed..ff552208aa 100644 --- a/src/lib/libcrypto/dsa/dsa_vrf.c +++ b/src/lib/libcrypto/dsa/dsa_vrf.c | |||
| @@ -56,97 +56,105 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | /* Origional version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ | 59 | /* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ |
| 60 | 60 | ||
| 61 | #include <stdio.h> | 61 | #include <stdio.h> |
| 62 | #include "cryptlib.h" | 62 | #include "cryptlib.h" |
| 63 | #include "bn.h" | 63 | #include <openssl/bn.h> |
| 64 | #include "dsa.h" | 64 | #include <openssl/dsa.h> |
| 65 | #include "rand.h" | 65 | #include <openssl/rand.h> |
| 66 | #include "asn1.h" | 66 | #include <openssl/asn1.h> |
| 67 | #include "asn1_mac.h" | 67 | #include <openssl/asn1_mac.h> |
| 68 | 68 | ||
| 69 | /* data has already been hashed (probably with SHA or SHA-1). */ | 69 | int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, |
| 70 | /* returns | 70 | DSA *dsa) |
| 71 | * 1: correct signature | ||
| 72 | * 0: incorrect signature | ||
| 73 | * -1: error | ||
| 74 | */ | ||
| 75 | int DSA_verify(type,dgst,dgst_len,sigbuf,siglen, dsa) | ||
| 76 | int type; | ||
| 77 | unsigned char *dgst; | ||
| 78 | int dgst_len; | ||
| 79 | unsigned char *sigbuf; | ||
| 80 | int siglen; | ||
| 81 | DSA *dsa; | ||
| 82 | { | 71 | { |
| 83 | /* The next 3 are used by the M_ASN1 macros */ | ||
| 84 | long length=siglen; | ||
| 85 | ASN1_CTX c; | ||
| 86 | unsigned char **pp= &sigbuf; | ||
| 87 | BN_CTX *ctx; | 72 | BN_CTX *ctx; |
| 88 | BIGNUM *r=NULL; | 73 | BIGNUM u1,u2,t1; |
| 89 | BIGNUM *t1=NULL,*t2=NULL; | 74 | BN_MONT_CTX *mont=NULL; |
| 90 | BIGNUM *u1=NULL,*u2=NULL; | ||
| 91 | ASN1_INTEGER *bs=NULL; | ||
| 92 | int ret = -1; | 75 | int ret = -1; |
| 93 | 76 | ||
| 94 | ctx=BN_CTX_new(); | 77 | if ((ctx=BN_CTX_new()) == NULL) goto err; |
| 95 | if (ctx == NULL) goto err; | 78 | BN_init(&u1); |
| 96 | 79 | BN_init(&u2); | |
| 97 | t1=BN_new(); | 80 | BN_init(&t1); |
| 98 | t2=BN_new(); | ||
| 99 | if (t1 == NULL || t2 == NULL) goto err; | ||
| 100 | |||
| 101 | M_ASN1_D2I_Init(); | ||
| 102 | M_ASN1_D2I_start_sequence(); | ||
| 103 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
| 104 | if ((r=BN_bin2bn(bs->data,bs->length,NULL)) == NULL) goto err_bn; | ||
| 105 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
| 106 | if ((u1=BN_bin2bn(bs->data,bs->length,NULL)) == NULL) goto err_bn; | ||
| 107 | if (!asn1_Finish(&c)) goto err; | ||
| 108 | 81 | ||
| 109 | /* Calculate W = inv(S) mod Q | 82 | /* Calculate W = inv(S) mod Q |
| 110 | * save W in u2 */ | 83 | * save W in u2 */ |
| 111 | if ((u2=BN_mod_inverse(u1,dsa->q,ctx)) == NULL) goto err_bn; | 84 | if ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err; |
| 112 | 85 | ||
| 113 | /* save M in u1 */ | 86 | /* save M in u1 */ |
| 114 | if (BN_bin2bn(dgst,dgst_len,u1) == NULL) goto err_bn; | 87 | if (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err; |
| 115 | 88 | ||
| 116 | /* u1 = M * w mod q */ | 89 | /* u1 = M * w mod q */ |
| 117 | if (!BN_mod_mul(u1,u1,u2,dsa->q,ctx)) goto err_bn; | 90 | if (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err; |
| 118 | 91 | ||
| 119 | /* u2 = r * w mod q */ | 92 | /* u2 = r * w mod q */ |
| 120 | if (!BN_mod_mul(u2,r,u2,dsa->q,ctx)) goto err_bn; | 93 | if (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err; |
| 94 | |||
| 95 | if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P)) | ||
| 96 | { | ||
| 97 | if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL) | ||
| 98 | if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p, | ||
| 99 | dsa->p,ctx)) goto err; | ||
| 100 | } | ||
| 101 | mont=(BN_MONT_CTX *)dsa->method_mont_p; | ||
| 102 | |||
| 103 | #if 0 | ||
| 104 | { | ||
| 105 | BIGNUM t2; | ||
| 121 | 106 | ||
| 107 | BN_init(&t2); | ||
| 122 | /* v = ( g^u1 * y^u2 mod p ) mod q */ | 108 | /* v = ( g^u1 * y^u2 mod p ) mod q */ |
| 123 | /* let t1 = g ^ u1 mod p */ | 109 | /* let t1 = g ^ u1 mod p */ |
| 124 | if (!BN_mod_exp(t1,dsa->g,u1,dsa->p,ctx)) goto err_bn; | 110 | if (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err; |
| 125 | /* let t2 = y ^ u2 mod p */ | 111 | /* let t2 = y ^ u2 mod p */ |
| 126 | if (!BN_mod_exp(t2,dsa->pub_key,u2,dsa->p,ctx)) goto err_bn; | 112 | if (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err; |
| 127 | /* let u1 = t1 * t2 mod p */ | 113 | /* let u1 = t1 * t2 mod p */ |
| 128 | if (!BN_mod_mul(u1,t1,t2,dsa->p,ctx)) goto err_bn; | 114 | if (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn; |
| 115 | BN_free(&t2); | ||
| 116 | } | ||
| 129 | /* let u1 = u1 mod q */ | 117 | /* let u1 = u1 mod q */ |
| 130 | if (!BN_mod(u1,u1,dsa->q,ctx)) goto err_bn; | 118 | if (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err; |
| 119 | #else | ||
| 120 | { | ||
| 121 | if (!BN_mod_exp2_mont(&t1,dsa->g,&u1,dsa->pub_key,&u2,dsa->p,ctx,mont)) | ||
| 122 | goto err; | ||
| 123 | /* BN_copy(&u1,&t1); */ | ||
| 124 | /* let u1 = u1 mod q */ | ||
| 125 | if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err; | ||
| 126 | } | ||
| 127 | #endif | ||
| 131 | /* V is now in u1. If the signature is correct, it will be | 128 | /* V is now in u1. If the signature is correct, it will be |
| 132 | * equal to R. */ | 129 | * equal to R. */ |
| 133 | ret=(BN_ucmp(u1, r) == 0); | 130 | ret=(BN_ucmp(&u1, sig->r) == 0); |
| 134 | if (0) | 131 | |
| 135 | { | 132 | err: |
| 136 | err: /* ASN1 error */ | 133 | if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB); |
| 137 | DSAerr(DSA_F_DSA_VERIFY,c.error); | ||
| 138 | } | ||
| 139 | if (0) | ||
| 140 | { | ||
| 141 | err_bn: /* BN error */ | ||
| 142 | DSAerr(DSA_F_DSA_VERIFY,ERR_R_BN_LIB); | ||
| 143 | } | ||
| 144 | if (ctx != NULL) BN_CTX_free(ctx); | 134 | if (ctx != NULL) BN_CTX_free(ctx); |
| 145 | if (r != NULL) BN_free(r); | 135 | BN_free(&u1); |
| 146 | if (t1 != NULL) BN_free(t1); | 136 | BN_free(&u2); |
| 147 | if (t2 != NULL) BN_free(t2); | 137 | BN_free(&t1); |
| 148 | if (u1 != NULL) BN_free(u1); | 138 | return(ret); |
| 149 | if (u2 != NULL) BN_free(u2); | 139 | } |
| 150 | if (bs != NULL) ASN1_BIT_STRING_free(bs); | 140 | |
| 141 | /* data has already been hashed (probably with SHA or SHA-1). */ | ||
| 142 | /* returns | ||
| 143 | * 1: correct signature | ||
| 144 | * 0: incorrect signature | ||
| 145 | * -1: error | ||
| 146 | */ | ||
| 147 | int DSA_verify(int type, const unsigned char *dgst, int dgst_len, | ||
| 148 | unsigned char *sigbuf, int siglen, DSA *dsa) | ||
| 149 | { | ||
| 150 | DSA_SIG *s; | ||
| 151 | int ret=-1; | ||
| 152 | |||
| 153 | s = DSA_SIG_new(); | ||
| 154 | if (s == NULL) return(ret); | ||
| 155 | if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err; | ||
| 156 | ret=DSA_do_verify(dgst,dgst_len,s,dsa); | ||
| 157 | err: | ||
| 158 | DSA_SIG_free(s); | ||
| 151 | return(ret); | 159 | return(ret); |
| 152 | } | 160 | } |
diff --git a/src/lib/libcrypto/dsa/dsagen.c b/src/lib/libcrypto/dsa/dsagen.c index 20335de250..a0b0976640 100644 --- a/src/lib/libcrypto/dsa/dsagen.c +++ b/src/lib/libcrypto/dsa/dsagen.c | |||
| @@ -57,7 +57,7 @@ | |||
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #include "dsa.h" | 60 | #include <openssl/dsa.h> |
| 61 | 61 | ||
| 62 | #define TEST | 62 | #define TEST |
| 63 | #define GENUINE_DSA | 63 | #define GENUINE_DSA |
| @@ -77,8 +77,7 @@ unsigned char seed[20]={ | |||
| 77 | 0xe0,0x42,0x7d,LAST_VALUE}; | 77 | 0xe0,0x42,0x7d,LAST_VALUE}; |
| 78 | #endif | 78 | #endif |
| 79 | 79 | ||
| 80 | int cb(p,n) | 80 | int cb(int p, int n) |
| 81 | int p,n; | ||
| 82 | { | 81 | { |
| 83 | char c='*'; | 82 | char c='*'; |
| 84 | 83 | ||
diff --git a/src/lib/libcrypto/dsa/dsatest.c b/src/lib/libcrypto/dsa/dsatest.c index 39bb712c4a..fc25c9a1b7 100644 --- a/src/lib/libcrypto/dsa/dsatest.c +++ b/src/lib/libcrypto/dsa/dsatest.c | |||
| @@ -61,27 +61,30 @@ | |||
| 61 | #include <string.h> | 61 | #include <string.h> |
| 62 | #include <sys/types.h> | 62 | #include <sys/types.h> |
| 63 | #include <sys/stat.h> | 63 | #include <sys/stat.h> |
| 64 | #include "crypto.h" | 64 | #include <openssl/crypto.h> |
| 65 | #include "rand.h" | 65 | #include <openssl/rand.h> |
| 66 | #include "bio.h" | 66 | #include <openssl/bio.h> |
| 67 | #include "err.h" | 67 | #include <openssl/err.h> |
| 68 | #include "dsa.h" | ||
| 69 | #ifdef WINDOWS | 68 | #ifdef WINDOWS |
| 70 | #include "../bio/bss_file.c" | 69 | #include "../bio/bss_file.c" |
| 71 | #endif | 70 | #endif |
| 72 | 71 | ||
| 72 | #ifdef NO_DSA | ||
| 73 | int main(int argc, char *argv[]) | ||
| 74 | { | ||
| 75 | printf("No DSA support\n"); | ||
| 76 | return(0); | ||
| 77 | } | ||
| 78 | #else | ||
| 79 | #include <openssl/dsa.h> | ||
| 80 | |||
| 73 | #ifdef WIN16 | 81 | #ifdef WIN16 |
| 74 | #define MS_CALLBACK _far _loadds | 82 | #define MS_CALLBACK _far _loadds |
| 75 | #else | 83 | #else |
| 76 | #define MS_CALLBACK | 84 | #define MS_CALLBACK |
| 77 | #endif | 85 | #endif |
| 78 | 86 | ||
| 79 | #ifndef NOPROTO | ||
| 80 | static void MS_CALLBACK dsa_cb(int p, int n, char *arg); | 87 | static void MS_CALLBACK dsa_cb(int p, int n, char *arg); |
| 81 | #else | ||
| 82 | static void MS_CALLBACK dsa_cb(); | ||
| 83 | #endif | ||
| 84 | |||
| 85 | static unsigned char seed[20]={ | 88 | static unsigned char seed[20]={ |
| 86 | 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40, | 89 | 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40, |
| 87 | 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3, | 90 | 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3, |
| @@ -115,20 +118,24 @@ static unsigned char out_g[]={ | |||
| 115 | 0xc5,0x72,0xaf,0x53,0xe6,0xd7,0x88,0x02, | 118 | 0xc5,0x72,0xaf,0x53,0xe6,0xd7,0x88,0x02, |
| 116 | }; | 119 | }; |
| 117 | 120 | ||
| 121 | static const unsigned char str1[]="12345678901234567890"; | ||
| 122 | |||
| 118 | static BIO *bio_err=NULL; | 123 | static BIO *bio_err=NULL; |
| 119 | 124 | ||
| 120 | int main(argc, argv) | 125 | int main(int argc, char **argv) |
| 121 | int argc; | ||
| 122 | char **argv; | ||
| 123 | { | 126 | { |
| 124 | DSA *dsa=NULL; | 127 | DSA *dsa=NULL; |
| 125 | int counter,ret=0,i,j; | 128 | int counter,ret=0,i,j; |
| 126 | unsigned char buf[256]; | 129 | unsigned char buf[256]; |
| 127 | unsigned long h; | 130 | unsigned long h; |
| 131 | unsigned char sig[256]; | ||
| 132 | unsigned int siglen; | ||
| 128 | 133 | ||
| 129 | if (bio_err == NULL) | 134 | if (bio_err == NULL) |
| 130 | bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); | 135 | bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); |
| 131 | 136 | ||
| 137 | CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); | ||
| 138 | |||
| 132 | BIO_printf(bio_err,"test generation of DSA parameters\n"); | 139 | BIO_printf(bio_err,"test generation of DSA parameters\n"); |
| 133 | BIO_printf(bio_err,"expect '.*' followed by 5 lines of '.'s and '+'s\n"); | 140 | BIO_printf(bio_err,"expect '.*' followed by 5 lines of '.'s and '+'s\n"); |
| 134 | dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb, | 141 | dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb, |
| @@ -178,21 +185,21 @@ char **argv; | |||
| 178 | BIO_printf(bio_err,"g value is wrong\n"); | 185 | BIO_printf(bio_err,"g value is wrong\n"); |
| 179 | goto end; | 186 | goto end; |
| 180 | } | 187 | } |
| 181 | 188 | DSA_generate_key(dsa); | |
| 182 | ret=1; | 189 | DSA_sign(0, str1, 20, sig, &siglen, dsa); |
| 190 | if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1) | ||
| 191 | ret=1; | ||
| 183 | end: | 192 | end: |
| 184 | if (!ret) | 193 | if (!ret) |
| 185 | ERR_print_errors(bio_err); | 194 | ERR_print_errors(bio_err); |
| 186 | if (bio_err != NULL) BIO_free(bio_err); | ||
| 187 | if (dsa != NULL) DSA_free(dsa); | 195 | if (dsa != NULL) DSA_free(dsa); |
| 196 | CRYPTO_mem_leaks(bio_err); | ||
| 197 | if (bio_err != NULL) BIO_free(bio_err); | ||
| 188 | exit(!ret); | 198 | exit(!ret); |
| 189 | return(0); | 199 | return(0); |
| 190 | } | 200 | } |
| 191 | 201 | ||
| 192 | static void MS_CALLBACK dsa_cb(p, n, arg) | 202 | static void MS_CALLBACK dsa_cb(int p, int n, char *arg) |
| 193 | int p; | ||
| 194 | int n; | ||
| 195 | char *arg; | ||
| 196 | { | 203 | { |
| 197 | char c='*'; | 204 | char c='*'; |
| 198 | static int ok=0,num=0; | 205 | static int ok=0,num=0; |
| @@ -202,7 +209,7 @@ char *arg; | |||
| 202 | if (p == 2) { c='*'; ok++; } | 209 | if (p == 2) { c='*'; ok++; } |
| 203 | if (p == 3) c='\n'; | 210 | if (p == 3) c='\n'; |
| 204 | BIO_write((BIO *)arg,&c,1); | 211 | BIO_write((BIO *)arg,&c,1); |
| 205 | BIO_flush((BIO *)arg); | 212 | (void)BIO_flush((BIO *)arg); |
| 206 | 213 | ||
| 207 | if (!ok && (p == 0) && (num > 1)) | 214 | if (!ok && (p == 0) && (num > 1)) |
| 208 | { | 215 | { |
| @@ -210,5 +217,4 @@ char *arg; | |||
| 210 | exit(1); | 217 | exit(1); |
| 211 | } | 218 | } |
| 212 | } | 219 | } |
| 213 | 220 | #endif | |
| 214 | |||
