archive_hmac.c (348608) | archive_hmac.c (358090) |
---|---|
1/*- 2* Copyright (c) 2014 Michihiro NAKAJIMA 3* All rights reserved. 4* 5* Redistribution and use in source and binary forms, with or without 6* modification, are permitted provided that the following conditions 7* are met: 8* 1. Redistributions of source code must retain the above copyright --- 69 unchanged lines hidden (view full) --- 78 79#ifndef BCRYPT_HASH_REUSABLE_FLAG 80# define BCRYPT_HASH_REUSABLE_FLAG 0x00000020 81#endif 82 83static int 84__hmac_sha1_init(archive_hmac_sha1_ctx *ctx, const uint8_t *key, size_t key_len) 85{ | 1/*- 2* Copyright (c) 2014 Michihiro NAKAJIMA 3* All rights reserved. 4* 5* Redistribution and use in source and binary forms, with or without 6* modification, are permitted provided that the following conditions 7* are met: 8* 1. Redistributions of source code must retain the above copyright --- 69 unchanged lines hidden (view full) --- 78 79#ifndef BCRYPT_HASH_REUSABLE_FLAG 80# define BCRYPT_HASH_REUSABLE_FLAG 0x00000020 81#endif 82 83static int 84__hmac_sha1_init(archive_hmac_sha1_ctx *ctx, const uint8_t *key, size_t key_len) 85{ |
86#ifdef __GNUC__ |
|
86#pragma GCC diagnostic ignored "-Wcast-qual" | 87#pragma GCC diagnostic ignored "-Wcast-qual" |
88#endif |
|
87 BCRYPT_ALG_HANDLE hAlg; 88 BCRYPT_HASH_HANDLE hHash; 89 DWORD hash_len; 90 PBYTE hash; 91 ULONG result; 92 NTSTATUS status; 93 94 ctx->hAlg = NULL; --- 48 unchanged lines hidden (view full) --- 143{ 144 if (ctx->hAlg != NULL) { 145 BCryptCloseAlgorithmProvider(ctx->hAlg, 0); 146 HeapFree(GetProcessHeap(), 0, ctx->hash); 147 ctx->hAlg = NULL; 148 } 149} 150 | 89 BCRYPT_ALG_HANDLE hAlg; 90 BCRYPT_HASH_HANDLE hHash; 91 DWORD hash_len; 92 PBYTE hash; 93 ULONG result; 94 NTSTATUS status; 95 96 ctx->hAlg = NULL; --- 48 unchanged lines hidden (view full) --- 145{ 146 if (ctx->hAlg != NULL) { 147 BCryptCloseAlgorithmProvider(ctx->hAlg, 0); 148 HeapFree(GetProcessHeap(), 0, ctx->hash); 149 ctx->hAlg = NULL; 150 } 151} 152 |
153#elif defined(HAVE_LIBMBEDCRYPTO) && defined(HAVE_MBEDTLS_MD_H) 154 155static int 156__hmac_sha1_init(archive_hmac_sha1_ctx *ctx, const uint8_t *key, size_t key_len) 157{ 158 const mbedtls_md_info_t *info; 159 int ret; 160 161 mbedtls_md_init(ctx); 162 info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA1); 163 if (info == NULL) { 164 mbedtls_md_free(ctx); 165 return (-1); 166 } 167 ret = mbedtls_md_setup(ctx, info, 1); 168 if (ret != 0) { 169 mbedtls_md_free(ctx); 170 return (-1); 171 } 172 ret = mbedtls_md_hmac_starts(ctx, key, key_len); 173 if (ret != 0) { 174 mbedtls_md_free(ctx); 175 return (-1); 176 } 177 return 0; 178} 179 180static void 181__hmac_sha1_update(archive_hmac_sha1_ctx *ctx, const uint8_t *data, 182 size_t data_len) 183{ 184 mbedtls_md_hmac_update(ctx, data, data_len); 185} 186 187static void __hmac_sha1_final(archive_hmac_sha1_ctx *ctx, uint8_t *out, size_t *out_len) 188{ 189 (void)out_len; /* UNUSED */ 190 191 mbedtls_md_hmac_finish(ctx, out); 192} 193 194static void __hmac_sha1_cleanup(archive_hmac_sha1_ctx *ctx) 195{ 196 mbedtls_md_free(ctx); 197 memset(ctx, 0, sizeof(*ctx)); 198} 199 |
|
151#elif defined(HAVE_LIBNETTLE) && defined(HAVE_NETTLE_HMAC_H) 152 153static int 154__hmac_sha1_init(archive_hmac_sha1_ctx *ctx, const uint8_t *key, size_t key_len) 155{ 156 hmac_sha1_set_key(ctx, key_len, key); 157 return 0; 158} --- 35 unchanged lines hidden (view full) --- 194{ 195 HMAC_Update(*ctx, data, data_len); 196} 197 198static void 199__hmac_sha1_final(archive_hmac_sha1_ctx *ctx, uint8_t *out, size_t *out_len) 200{ 201 unsigned int len = (unsigned int)*out_len; | 200#elif defined(HAVE_LIBNETTLE) && defined(HAVE_NETTLE_HMAC_H) 201 202static int 203__hmac_sha1_init(archive_hmac_sha1_ctx *ctx, const uint8_t *key, size_t key_len) 204{ 205 hmac_sha1_set_key(ctx, key_len, key); 206 return 0; 207} --- 35 unchanged lines hidden (view full) --- 243{ 244 HMAC_Update(*ctx, data, data_len); 245} 246 247static void 248__hmac_sha1_final(archive_hmac_sha1_ctx *ctx, uint8_t *out, size_t *out_len) 249{ 250 unsigned int len = (unsigned int)*out_len; |
251 |
|
202 HMAC_Final(*ctx, out, &len); 203 *out_len = len; 204} 205 206static void 207__hmac_sha1_cleanup(archive_hmac_sha1_ctx *ctx) 208{ 209 HMAC_CTX_free(*ctx); --- 46 unchanged lines hidden --- | 252 HMAC_Final(*ctx, out, &len); 253 *out_len = len; 254} 255 256static void 257__hmac_sha1_cleanup(archive_hmac_sha1_ctx *ctx) 258{ 259 HMAC_CTX_free(*ctx); --- 46 unchanged lines hidden --- |