diff options
Diffstat (limited to 'src/lib/libcrypto/hmac')
| -rw-r--r-- | src/lib/libcrypto/hmac/Makefile.ssl | 101 | ||||
| -rw-r--r-- | src/lib/libcrypto/hmac/hmac.c | 90 | ||||
| -rw-r--r-- | src/lib/libcrypto/hmac/hmac.h | 9 |
3 files changed, 67 insertions, 133 deletions
diff --git a/src/lib/libcrypto/hmac/Makefile.ssl b/src/lib/libcrypto/hmac/Makefile.ssl deleted file mode 100644 index f1c07322c4..0000000000 --- a/src/lib/libcrypto/hmac/Makefile.ssl +++ /dev/null | |||
| @@ -1,101 +0,0 @@ | |||
| 1 | # | ||
| 2 | # SSLeay/crypto/md/Makefile | ||
| 3 | # | ||
| 4 | |||
| 5 | DIR= hmac | ||
| 6 | TOP= ../.. | ||
| 7 | CC= cc | ||
| 8 | INCLUDES= | ||
| 9 | CFLAG=-g | ||
| 10 | INSTALL_PREFIX= | ||
| 11 | OPENSSLDIR= /usr/local/ssl | ||
| 12 | INSTALLTOP=/usr/local/ssl | ||
| 13 | MAKE= make -f Makefile.ssl | ||
| 14 | MAKEDEPPROG= makedepend | ||
| 15 | MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) | ||
| 16 | MAKEFILE= Makefile.ssl | ||
| 17 | AR= ar r | ||
| 18 | |||
| 19 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 20 | |||
| 21 | GENERAL=Makefile | ||
| 22 | TEST=hmactest.c | ||
| 23 | APPS= | ||
| 24 | |||
| 25 | LIB=$(TOP)/libcrypto.a | ||
| 26 | LIBSRC=hmac.c | ||
| 27 | LIBOBJ=hmac.o | ||
| 28 | |||
| 29 | SRC= $(LIBSRC) | ||
| 30 | |||
| 31 | EXHEADER= hmac.h | ||
| 32 | HEADER= $(EXHEADER) | ||
| 33 | |||
| 34 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 35 | |||
| 36 | top: | ||
| 37 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 38 | |||
| 39 | all: lib | ||
| 40 | |||
| 41 | lib: $(LIBOBJ) | ||
| 42 | $(AR) $(LIB) $(LIBOBJ) | ||
| 43 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 44 | @touch lib | ||
| 45 | |||
| 46 | files: | ||
| 47 | $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
| 48 | |||
| 49 | links: | ||
| 50 | @sh $(TOP)/util/point.sh Makefile.ssl Makefile | ||
| 51 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 52 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 53 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
| 54 | |||
| 55 | install: | ||
| 56 | @for i in $(EXHEADER) ; \ | ||
| 57 | do \ | ||
| 58 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 59 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 60 | done; | ||
| 61 | |||
| 62 | tags: | ||
| 63 | ctags $(SRC) | ||
| 64 | |||
| 65 | tests: | ||
| 66 | |||
| 67 | lint: | ||
| 68 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 69 | |||
| 70 | depend: | ||
| 71 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
| 72 | |||
| 73 | dclean: | ||
| 74 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 75 | mv -f Makefile.new $(MAKEFILE) | ||
| 76 | |||
| 77 | clean: | ||
| 78 | rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
| 79 | |||
| 80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 81 | |||
| 82 | hmac.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
| 83 | hmac.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
| 84 | hmac.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
| 85 | hmac.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h | ||
| 86 | hmac.o: ../../include/openssl/des.h ../../include/openssl/des_old.h | ||
| 87 | hmac.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 88 | hmac.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 89 | hmac.o: ../../include/openssl/evp.h ../../include/openssl/hmac.h | ||
| 90 | hmac.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
| 91 | hmac.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
| 92 | hmac.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
| 93 | hmac.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
| 94 | hmac.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 95 | hmac.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rc2.h | ||
| 96 | hmac.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
| 97 | hmac.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
| 98 | hmac.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 99 | hmac.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 100 | hmac.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 101 | hmac.o: ../cryptlib.h hmac.c | ||
diff --git a/src/lib/libcrypto/hmac/hmac.c b/src/lib/libcrypto/hmac/hmac.c index cbc1c76a57..45015fe754 100644 --- a/src/lib/libcrypto/hmac/hmac.c +++ b/src/lib/libcrypto/hmac/hmac.c | |||
| @@ -61,9 +61,7 @@ | |||
| 61 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
| 62 | #include <openssl/hmac.h> | 62 | #include <openssl/hmac.h> |
| 63 | 63 | ||
| 64 | #ifndef OPENSSL_FIPS | 64 | int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, |
| 65 | |||
| 66 | void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, | ||
| 67 | const EVP_MD *md, ENGINE *impl) | 65 | const EVP_MD *md, ENGINE *impl) |
| 68 | { | 66 | { |
| 69 | int i,j,reset=0; | 67 | int i,j,reset=0; |
| @@ -84,10 +82,13 @@ void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, | |||
| 84 | OPENSSL_assert(j <= (int)sizeof(ctx->key)); | 82 | OPENSSL_assert(j <= (int)sizeof(ctx->key)); |
| 85 | if (j < len) | 83 | if (j < len) |
| 86 | { | 84 | { |
| 87 | EVP_DigestInit_ex(&ctx->md_ctx,md, impl); | 85 | if (!EVP_DigestInit_ex(&ctx->md_ctx,md, impl)) |
| 88 | EVP_DigestUpdate(&ctx->md_ctx,key,len); | 86 | goto err; |
| 89 | EVP_DigestFinal_ex(&(ctx->md_ctx),ctx->key, | 87 | if (!EVP_DigestUpdate(&ctx->md_ctx,key,len)) |
| 90 | &ctx->key_length); | 88 | goto err; |
| 89 | if (!EVP_DigestFinal_ex(&(ctx->md_ctx),ctx->key, | ||
| 90 | &ctx->key_length)) | ||
| 91 | goto err; | ||
| 91 | } | 92 | } |
| 92 | else | 93 | else |
| 93 | { | 94 | { |
| @@ -104,31 +105,38 @@ void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, | |||
| 104 | { | 105 | { |
| 105 | for (i=0; i<HMAC_MAX_MD_CBLOCK; i++) | 106 | for (i=0; i<HMAC_MAX_MD_CBLOCK; i++) |
| 106 | pad[i]=0x36^ctx->key[i]; | 107 | pad[i]=0x36^ctx->key[i]; |
| 107 | EVP_DigestInit_ex(&ctx->i_ctx,md, impl); | 108 | if (!EVP_DigestInit_ex(&ctx->i_ctx,md, impl)) |
| 108 | EVP_DigestUpdate(&ctx->i_ctx,pad,EVP_MD_block_size(md)); | 109 | goto err; |
| 110 | if (!EVP_DigestUpdate(&ctx->i_ctx,pad,EVP_MD_block_size(md))) | ||
| 111 | goto err; | ||
| 109 | 112 | ||
| 110 | for (i=0; i<HMAC_MAX_MD_CBLOCK; i++) | 113 | for (i=0; i<HMAC_MAX_MD_CBLOCK; i++) |
| 111 | pad[i]=0x5c^ctx->key[i]; | 114 | pad[i]=0x5c^ctx->key[i]; |
| 112 | EVP_DigestInit_ex(&ctx->o_ctx,md, impl); | 115 | if (!EVP_DigestInit_ex(&ctx->o_ctx,md, impl)) |
| 113 | EVP_DigestUpdate(&ctx->o_ctx,pad,EVP_MD_block_size(md)); | 116 | goto err; |
| 117 | if (!EVP_DigestUpdate(&ctx->o_ctx,pad,EVP_MD_block_size(md))) | ||
| 118 | goto err; | ||
| 114 | } | 119 | } |
| 115 | EVP_MD_CTX_copy_ex(&ctx->md_ctx,&ctx->i_ctx); | 120 | if (!EVP_MD_CTX_copy_ex(&ctx->md_ctx,&ctx->i_ctx)) |
| 121 | goto err; | ||
| 122 | return 1; | ||
| 123 | err: | ||
| 124 | return 0; | ||
| 116 | } | 125 | } |
| 117 | 126 | ||
| 118 | void HMAC_Init(HMAC_CTX *ctx, const void *key, int len, | 127 | int HMAC_Init(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md) |
| 119 | const EVP_MD *md) | ||
| 120 | { | 128 | { |
| 121 | if(key && md) | 129 | if(key && md) |
| 122 | HMAC_CTX_init(ctx); | 130 | HMAC_CTX_init(ctx); |
| 123 | HMAC_Init_ex(ctx,key,len,md, NULL); | 131 | return HMAC_Init_ex(ctx,key,len,md, NULL); |
| 124 | } | 132 | } |
| 125 | 133 | ||
| 126 | void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len) | 134 | int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len) |
| 127 | { | 135 | { |
| 128 | EVP_DigestUpdate(&ctx->md_ctx,data,len); | 136 | return EVP_DigestUpdate(&ctx->md_ctx,data,len); |
| 129 | } | 137 | } |
| 130 | 138 | ||
| 131 | void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len) | 139 | int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len) |
| 132 | { | 140 | { |
| 133 | int j; | 141 | int j; |
| 134 | unsigned int i; | 142 | unsigned int i; |
| @@ -136,10 +144,17 @@ void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len) | |||
| 136 | 144 | ||
| 137 | j=EVP_MD_block_size(ctx->md); | 145 | j=EVP_MD_block_size(ctx->md); |
| 138 | 146 | ||
| 139 | EVP_DigestFinal_ex(&ctx->md_ctx,buf,&i); | 147 | if (!EVP_DigestFinal_ex(&ctx->md_ctx,buf,&i)) |
| 140 | EVP_MD_CTX_copy_ex(&ctx->md_ctx,&ctx->o_ctx); | 148 | goto err; |
| 141 | EVP_DigestUpdate(&ctx->md_ctx,buf,i); | 149 | if (!EVP_MD_CTX_copy_ex(&ctx->md_ctx,&ctx->o_ctx)) |
| 142 | EVP_DigestFinal_ex(&ctx->md_ctx,md,len); | 150 | goto err; |
| 151 | if (!EVP_DigestUpdate(&ctx->md_ctx,buf,i)) | ||
| 152 | goto err; | ||
| 153 | if (!EVP_DigestFinal_ex(&ctx->md_ctx,md,len)) | ||
| 154 | goto err; | ||
| 155 | return 1; | ||
| 156 | err: | ||
| 157 | return 0; | ||
| 143 | } | 158 | } |
| 144 | 159 | ||
| 145 | void HMAC_CTX_init(HMAC_CTX *ctx) | 160 | void HMAC_CTX_init(HMAC_CTX *ctx) |
| @@ -149,6 +164,22 @@ void HMAC_CTX_init(HMAC_CTX *ctx) | |||
| 149 | EVP_MD_CTX_init(&ctx->md_ctx); | 164 | EVP_MD_CTX_init(&ctx->md_ctx); |
| 150 | } | 165 | } |
| 151 | 166 | ||
| 167 | int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx) | ||
| 168 | { | ||
| 169 | if (!EVP_MD_CTX_copy(&dctx->i_ctx, &sctx->i_ctx)) | ||
| 170 | goto err; | ||
| 171 | if (!EVP_MD_CTX_copy(&dctx->o_ctx, &sctx->o_ctx)) | ||
| 172 | goto err; | ||
| 173 | if (!EVP_MD_CTX_copy(&dctx->md_ctx, &sctx->md_ctx)) | ||
| 174 | goto err; | ||
| 175 | memcpy(dctx->key, sctx->key, HMAC_MAX_MD_CBLOCK); | ||
| 176 | dctx->key_length = sctx->key_length; | ||
| 177 | dctx->md = sctx->md; | ||
| 178 | return 1; | ||
| 179 | err: | ||
| 180 | return 0; | ||
| 181 | } | ||
| 182 | |||
| 152 | void HMAC_CTX_cleanup(HMAC_CTX *ctx) | 183 | void HMAC_CTX_cleanup(HMAC_CTX *ctx) |
| 153 | { | 184 | { |
| 154 | EVP_MD_CTX_cleanup(&ctx->i_ctx); | 185 | EVP_MD_CTX_cleanup(&ctx->i_ctx); |
| @@ -166,11 +197,16 @@ unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, | |||
| 166 | 197 | ||
| 167 | if (md == NULL) md=m; | 198 | if (md == NULL) md=m; |
| 168 | HMAC_CTX_init(&c); | 199 | HMAC_CTX_init(&c); |
| 169 | HMAC_Init(&c,key,key_len,evp_md); | 200 | if (!HMAC_Init(&c,key,key_len,evp_md)) |
| 170 | HMAC_Update(&c,d,n); | 201 | goto err; |
| 171 | HMAC_Final(&c,md,md_len); | 202 | if (!HMAC_Update(&c,d,n)) |
| 203 | goto err; | ||
| 204 | if (!HMAC_Final(&c,md,md_len)) | ||
| 205 | goto err; | ||
| 172 | HMAC_CTX_cleanup(&c); | 206 | HMAC_CTX_cleanup(&c); |
| 173 | return(md); | 207 | return md; |
| 208 | err: | ||
| 209 | return NULL; | ||
| 174 | } | 210 | } |
| 175 | 211 | ||
| 176 | void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags) | 212 | void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags) |
| @@ -179,5 +215,3 @@ void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags) | |||
| 179 | EVP_MD_CTX_set_flags(&ctx->o_ctx, flags); | 215 | EVP_MD_CTX_set_flags(&ctx->o_ctx, flags); |
| 180 | EVP_MD_CTX_set_flags(&ctx->md_ctx, flags); | 216 | EVP_MD_CTX_set_flags(&ctx->md_ctx, flags); |
| 181 | } | 217 | } |
| 182 | |||
| 183 | #endif | ||
diff --git a/src/lib/libcrypto/hmac/hmac.h b/src/lib/libcrypto/hmac/hmac.h index fc38ffb52b..1be0022190 100644 --- a/src/lib/libcrypto/hmac/hmac.h +++ b/src/lib/libcrypto/hmac/hmac.h | |||
| @@ -90,15 +90,16 @@ void HMAC_CTX_cleanup(HMAC_CTX *ctx); | |||
| 90 | 90 | ||
| 91 | #define HMAC_cleanup(ctx) HMAC_CTX_cleanup(ctx) /* deprecated */ | 91 | #define HMAC_cleanup(ctx) HMAC_CTX_cleanup(ctx) /* deprecated */ |
| 92 | 92 | ||
| 93 | void HMAC_Init(HMAC_CTX *ctx, const void *key, int len, | 93 | int HMAC_Init(HMAC_CTX *ctx, const void *key, int len, |
| 94 | const EVP_MD *md); /* deprecated */ | 94 | const EVP_MD *md); /* deprecated */ |
| 95 | void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, | 95 | int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, |
| 96 | const EVP_MD *md, ENGINE *impl); | 96 | const EVP_MD *md, ENGINE *impl); |
| 97 | void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len); | 97 | int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len); |
| 98 | void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len); | 98 | int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len); |
| 99 | unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, | 99 | unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, |
| 100 | const unsigned char *d, size_t n, unsigned char *md, | 100 | const unsigned char *d, size_t n, unsigned char *md, |
| 101 | unsigned int *md_len); | 101 | unsigned int *md_len); |
| 102 | int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx); | ||
| 102 | 103 | ||
| 103 | void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags); | 104 | void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags); |
| 104 | 105 | ||
