| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/hmac/hmac.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | int | - | ||||||||||||||||||
| 4 | HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md, | - | ||||||||||||||||||
| 5 | ENGINE *impl) | - | ||||||||||||||||||
| 6 | { | - | ||||||||||||||||||
| 7 | int i, j, reset = 0; | - | ||||||||||||||||||
| 8 | unsigned char pad[128]; | - | ||||||||||||||||||
| 9 | - | |||||||||||||||||||
| 10 | - | |||||||||||||||||||
| 11 | if (md !=
| 31-8908 | ||||||||||||||||||
| 12 | ((void *)0)
| 31-8908 | ||||||||||||||||||
| 13 | && md != ctx->md
| 2-6992 | ||||||||||||||||||
| 14 | ((void *)0)
| 2-1914 | ||||||||||||||||||
| 15 | || len < 0
| 1-1913 | ||||||||||||||||||
| 16 | return executed 3 times by 1 test: 0;return 0;Executed by:
executed 3 times by 1 test: return 0;Executed by:
| 3 | ||||||||||||||||||
| 17 | - | |||||||||||||||||||
| 18 | if (md !=
| 31-8905 | ||||||||||||||||||
| 19 | ((void *)0)
| 31-8905 | ||||||||||||||||||
| 20 | ) { | - | ||||||||||||||||||
| 21 | reset = 1; | - | ||||||||||||||||||
| 22 | ctx->md = md; | - | ||||||||||||||||||
| 23 | } executed 8905 times by 6 tests: else if (ctx->md != end of blockExecuted by:
| 2-8905 | ||||||||||||||||||
| 24 | ((void *)0)
| 2-29 | ||||||||||||||||||
| 25 | ) | - | ||||||||||||||||||
| 26 | md = ctx->md; executed 29 times by 2 tests: md = ctx->md;Executed by:
| 29 | ||||||||||||||||||
| 27 | else | - | ||||||||||||||||||
| 28 | return executed 2 times by 1 test: 0;return 0;Executed by:
executed 2 times by 1 test: return 0;Executed by:
| 2 | ||||||||||||||||||
| 29 | - | |||||||||||||||||||
| 30 | if (key !=
| 28-8906 | ||||||||||||||||||
| 31 | ((void *)0)
| 28-8906 | ||||||||||||||||||
| 32 | ) { | - | ||||||||||||||||||
| 33 | reset = 1; | - | ||||||||||||||||||
| 34 | j = EVP_MD_block_size(md); | - | ||||||||||||||||||
| 35 | if ((
| 0-8906 | ||||||||||||||||||
| 36 | ERR_put_error(6,(0xfff),(136),__FILE__,89); | - | ||||||||||||||||||
| 37 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 38 | } | - | ||||||||||||||||||
| 39 | if (j < len
| 52-8854 | ||||||||||||||||||
| 40 | if (!EVP_DigestInit_ex(&ctx->md_ctx, md, impl)
| 0-52 | ||||||||||||||||||
| 41 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 42 | if (!EVP_DigestUpdate(&ctx->md_ctx, key, len)
| 0-52 | ||||||||||||||||||
| 43 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 44 | if (!EVP_DigestFinal_ex(&(ctx->md_ctx), ctx->key,
| 0-52 | ||||||||||||||||||
| 45 | &ctx->key_length)
| 0-52 | ||||||||||||||||||
| 46 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 47 | } executed 52 times by 2 tests: else {end of blockExecuted by:
| 52 | ||||||||||||||||||
| 48 | if (len < 0
| 0-8854 | ||||||||||||||||||
| 49 | ERR_put_error(6,(0xfff),(137),__FILE__,102); | - | ||||||||||||||||||
| 50 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 51 | } | - | ||||||||||||||||||
| 52 | memcpy(ctx->key, key, len); | - | ||||||||||||||||||
| 53 | ctx->key_length = len; | - | ||||||||||||||||||
| 54 | } executed 8854 times by 6 tests: end of blockExecuted by:
| 8854 | ||||||||||||||||||
| 55 | if (ctx->key_length != 128
| 4-8902 | ||||||||||||||||||
| 56 | memset(&ctx->key[ctx->key_length], 0, executed 8902 times by 6 tests: memset(&ctx->key[ctx->key_length], 0, 128 - ctx->key_length);Executed by:
| 8902 | ||||||||||||||||||
| 57 | 128 - ctx->key_length); executed 8902 times by 6 tests: memset(&ctx->key[ctx->key_length], 0, 128 - ctx->key_length);Executed by:
| 8902 | ||||||||||||||||||
| 58 | } executed 8906 times by 6 tests: end of blockExecuted by:
| 8906 | ||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | if (reset
| 28-8906 | ||||||||||||||||||
| 61 | for (i = 0; i < 128
| 8906-1139968 | ||||||||||||||||||
| 62 | pad[i] = 0x36 ^ ctx->key[i]; executed 1139968 times by 6 tests: pad[i] = 0x36 ^ ctx->key[i];Executed by:
| 1139968 | ||||||||||||||||||
| 63 | if (!EVP_DigestInit_ex(&ctx->i_ctx, md, impl)
| 0-8906 | ||||||||||||||||||
| 64 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 65 | if (!EVP_DigestUpdate(&ctx->i_ctx, pad, EVP_MD_block_size(md))
| 0-8906 | ||||||||||||||||||
| 66 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 67 | - | |||||||||||||||||||
| 68 | for (i = 0; i < 128
| 8906-1139968 | ||||||||||||||||||
| 69 | pad[i] = 0x5c ^ ctx->key[i]; executed 1139968 times by 6 tests: pad[i] = 0x5c ^ ctx->key[i];Executed by:
| 1139968 | ||||||||||||||||||
| 70 | if (!EVP_DigestInit_ex(&ctx->o_ctx, md, impl)
| 0-8906 | ||||||||||||||||||
| 71 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 72 | if (!EVP_DigestUpdate(&ctx->o_ctx, pad, EVP_MD_block_size(md))
| 0-8906 | ||||||||||||||||||
| 73 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 74 | } executed 8906 times by 6 tests: end of blockExecuted by:
| 8906 | ||||||||||||||||||
| 75 | if (!EVP_MD_CTX_copy_ex(&ctx->md_ctx, &ctx->i_ctx)
| 0-8934 | ||||||||||||||||||
| 76 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 77 | return executed 8934 times by 6 tests: 1;return 1;Executed by:
executed 8934 times by 6 tests: return 1;Executed by:
| 8934 | ||||||||||||||||||
| 78 | err: | - | ||||||||||||||||||
| 79 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 80 | } | - | ||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | int | - | ||||||||||||||||||
| 83 | HMAC_Init(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md) | - | ||||||||||||||||||
| 84 | { | - | ||||||||||||||||||
| 85 | if (key
| 0-18 | ||||||||||||||||||
| 86 | HMAC_CTX_init(ctx); executed 18 times by 2 tests: HMAC_CTX_init(ctx);Executed by:
| 18 | ||||||||||||||||||
| 87 | return executed 18 times by 2 tests: HMAC_Init_ex(ctx, key, len, md, return HMAC_Init_ex(ctx, key, len, md, ((void *)0) );Executed by:
executed 18 times by 2 tests: return HMAC_Init_ex(ctx, key, len, md, ((void *)0) );Executed by:
| 18 | ||||||||||||||||||
| 88 | ((void *)0) executed 18 times by 2 tests: return HMAC_Init_ex(ctx, key, len, md, ((void *)0) );Executed by:
| 18 | ||||||||||||||||||
| 89 | ); executed 18 times by 2 tests: return HMAC_Init_ex(ctx, key, len, md, ((void *)0) );Executed by:
| 18 | ||||||||||||||||||
| 90 | } | - | ||||||||||||||||||
| 91 | - | |||||||||||||||||||
| 92 | int | - | ||||||||||||||||||
| 93 | HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len) | - | ||||||||||||||||||
| 94 | { | - | ||||||||||||||||||
| 95 | if (ctx->md ==
| 3-75871 | ||||||||||||||||||
| 96 | ((void *)0)
| 3-75871 | ||||||||||||||||||
| 97 | ) | - | ||||||||||||||||||
| 98 | return executed 3 times by 1 test: 0;return 0;Executed by:
executed 3 times by 1 test: return 0;Executed by:
| 3 | ||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | return executed 75871 times by 6 tests: EVP_DigestUpdate(&ctx->md_ctx, data, len);return EVP_DigestUpdate(&ctx->md_ctx, data, len);Executed by:
executed 75871 times by 6 tests: return EVP_DigestUpdate(&ctx->md_ctx, data, len);Executed by:
| 75871 | ||||||||||||||||||
| 101 | } | - | ||||||||||||||||||
| 102 | - | |||||||||||||||||||
| 103 | int | - | ||||||||||||||||||
| 104 | HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len) | - | ||||||||||||||||||
| 105 | { | - | ||||||||||||||||||
| 106 | unsigned int i; | - | ||||||||||||||||||
| 107 | unsigned char buf[64]; | - | ||||||||||||||||||
| 108 | - | |||||||||||||||||||
| 109 | if (ctx->md ==
| 0-54112 | ||||||||||||||||||
| 110 | ((void *)0)
| 0-54112 | ||||||||||||||||||
| 111 | ) | - | ||||||||||||||||||
| 112 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 113 | - | |||||||||||||||||||
| 114 | if (!EVP_DigestFinal_ex(&ctx->md_ctx, buf, &i)
| 0-54112 | ||||||||||||||||||
| 115 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 116 | if (!EVP_MD_CTX_copy_ex(&ctx->md_ctx, &ctx->o_ctx)
| 0-54112 | ||||||||||||||||||
| 117 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 118 | if (!EVP_DigestUpdate(&ctx->md_ctx, buf, i)
| 0-54112 | ||||||||||||||||||
| 119 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 120 | if (!EVP_DigestFinal_ex(&ctx->md_ctx, md, len)
| 0-54112 | ||||||||||||||||||
| 121 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 122 | return executed 54112 times by 6 tests: 1;return 1;Executed by:
executed 54112 times by 6 tests: return 1;Executed by:
| 54112 | ||||||||||||||||||
| 123 | err: | - | ||||||||||||||||||
| 124 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 125 | } | - | ||||||||||||||||||
| 126 | - | |||||||||||||||||||
| 127 | HMAC_CTX * | - | ||||||||||||||||||
| 128 | HMAC_CTX_new(void) | - | ||||||||||||||||||
| 129 | { | - | ||||||||||||||||||
| 130 | HMAC_CTX *ctx; | - | ||||||||||||||||||
| 131 | - | |||||||||||||||||||
| 132 | if ((
| 0 | ||||||||||||||||||
| 133 | ((void *)0)
| 0 | ||||||||||||||||||
| 134 | ) | - | ||||||||||||||||||
| 135 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 136 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 137 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 138 | - | |||||||||||||||||||
| 139 | HMAC_CTX_init(ctx); | - | ||||||||||||||||||
| 140 | - | |||||||||||||||||||
| 141 | return never executed: ctx;return ctx;never executed: return ctx; | 0 | ||||||||||||||||||
| 142 | } | - | ||||||||||||||||||
| 143 | - | |||||||||||||||||||
| 144 | void | - | ||||||||||||||||||
| 145 | HMAC_CTX_free(HMAC_CTX *ctx) | - | ||||||||||||||||||
| 146 | { | - | ||||||||||||||||||
| 147 | if (ctx ==
| 0-1 | ||||||||||||||||||
| 148 | ((void *)0)
| 0-1 | ||||||||||||||||||
| 149 | ) | - | ||||||||||||||||||
| 150 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||
| 151 | - | |||||||||||||||||||
| 152 | HMAC_CTX_cleanup(ctx); | - | ||||||||||||||||||
| 153 | - | |||||||||||||||||||
| 154 | free(ctx); | - | ||||||||||||||||||
| 155 | } never executed: end of block | 0 | ||||||||||||||||||
| 156 | - | |||||||||||||||||||
| 157 | int | - | ||||||||||||||||||
| 158 | HMAC_CTX_reset(HMAC_CTX *ctx) | - | ||||||||||||||||||
| 159 | { | - | ||||||||||||||||||
| 160 | HMAC_CTX_cleanup(ctx); | - | ||||||||||||||||||
| 161 | HMAC_CTX_init(ctx); | - | ||||||||||||||||||
| 162 | return never executed: 1;return 1;never executed: return 1; | 0 | ||||||||||||||||||
| 163 | } | - | ||||||||||||||||||
| 164 | - | |||||||||||||||||||
| 165 | void | - | ||||||||||||||||||
| 166 | HMAC_CTX_init(HMAC_CTX *ctx) | - | ||||||||||||||||||
| 167 | { | - | ||||||||||||||||||
| 168 | EVP_MD_CTX_init(&ctx->i_ctx); | - | ||||||||||||||||||
| 169 | EVP_MD_CTX_init(&ctx->o_ctx); | - | ||||||||||||||||||
| 170 | EVP_MD_CTX_init(&ctx->md_ctx); | - | ||||||||||||||||||
| 171 | ctx->md = | - | ||||||||||||||||||
| 172 | ((void *)0) | - | ||||||||||||||||||
| 173 | ; | - | ||||||||||||||||||
| 174 | } executed 22527 times by 6 tests: end of blockExecuted by:
| 22527 | ||||||||||||||||||
| 175 | - | |||||||||||||||||||
| 176 | int | - | ||||||||||||||||||
| 177 | HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx) | - | ||||||||||||||||||
| 178 | { | - | ||||||||||||||||||
| 179 | if (!EVP_MD_CTX_copy(&dctx->i_ctx, &sctx->i_ctx)
| 0-54462 | ||||||||||||||||||
| 180 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 181 | if (!EVP_MD_CTX_copy(&dctx->o_ctx, &sctx->o_ctx)
| 0-54462 | ||||||||||||||||||
| 182 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 183 | if (!EVP_MD_CTX_copy(&dctx->md_ctx, &sctx->md_ctx)
| 0-54462 | ||||||||||||||||||
| 184 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 185 | memcpy(dctx->key, sctx->key, 128); | - | ||||||||||||||||||
| 186 | dctx->key_length = sctx->key_length; | - | ||||||||||||||||||
| 187 | dctx->md = sctx->md; | - | ||||||||||||||||||
| 188 | return executed 54462 times by 5 tests: 1;return 1;Executed by:
executed 54462 times by 5 tests: return 1;Executed by:
| 54462 | ||||||||||||||||||
| 189 | err: | - | ||||||||||||||||||
| 190 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 191 | } | - | ||||||||||||||||||
| 192 | - | |||||||||||||||||||
| 193 | void | - | ||||||||||||||||||
| 194 | HMAC_CTX_cleanup(HMAC_CTX *ctx) | - | ||||||||||||||||||
| 195 | { | - | ||||||||||||||||||
| 196 | EVP_MD_CTX_cleanup(&ctx->i_ctx); | - | ||||||||||||||||||
| 197 | EVP_MD_CTX_cleanup(&ctx->o_ctx); | - | ||||||||||||||||||
| 198 | EVP_MD_CTX_cleanup(&ctx->md_ctx); | - | ||||||||||||||||||
| 199 | explicit_bzero(ctx, sizeof(*ctx)); | - | ||||||||||||||||||
| 200 | } executed 58178 times by 6 tests: end of blockExecuted by:
| 58178 | ||||||||||||||||||
| 201 | - | |||||||||||||||||||
| 202 | void | - | ||||||||||||||||||
| 203 | HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags) | - | ||||||||||||||||||
| 204 | { | - | ||||||||||||||||||
| 205 | EVP_MD_CTX_set_flags(&ctx->i_ctx, flags); | - | ||||||||||||||||||
| 206 | EVP_MD_CTX_set_flags(&ctx->o_ctx, flags); | - | ||||||||||||||||||
| 207 | EVP_MD_CTX_set_flags(&ctx->md_ctx, flags); | - | ||||||||||||||||||
| 208 | } executed 8796 times by 3 tests: end of blockExecuted by:
| 8796 | ||||||||||||||||||
| 209 | - | |||||||||||||||||||
| 210 | const EVP_MD * | - | ||||||||||||||||||
| 211 | HMAC_CTX_get_md(const HMAC_CTX *ctx) | - | ||||||||||||||||||
| 212 | { | - | ||||||||||||||||||
| 213 | return never executed: ctx->md;return ctx->md;never executed: return ctx->md; | 0 | ||||||||||||||||||
| 214 | } | - | ||||||||||||||||||
| 215 | - | |||||||||||||||||||
| 216 | unsigned char * | - | ||||||||||||||||||
| 217 | HMAC(const EVP_MD *evp_md, const void *key, int key_len, const unsigned char *d, | - | ||||||||||||||||||
| 218 | size_t n, unsigned char *md, unsigned int *md_len) | - | ||||||||||||||||||
| 219 | { | - | ||||||||||||||||||
| 220 | HMAC_CTX c; | - | ||||||||||||||||||
| 221 | static unsigned char m[64]; | - | ||||||||||||||||||
| 222 | - | |||||||||||||||||||
| 223 | if (md ==
| 4-14 | ||||||||||||||||||
| 224 | ((void *)0)
| 4-14 | ||||||||||||||||||
| 225 | ) | - | ||||||||||||||||||
| 226 | md = m; executed 4 times by 1 test: md = m;Executed by:
| 4 | ||||||||||||||||||
| 227 | HMAC_CTX_init(&c); | - | ||||||||||||||||||
| 228 | if (!HMAC_Init(&c, key, key_len, evp_md)
| 0-18 | ||||||||||||||||||
| 229 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 230 | if (!HMAC_Update(&c, d, n)
| 0-18 | ||||||||||||||||||
| 231 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 232 | if (!HMAC_Final(&c, md, md_len)
| 0-18 | ||||||||||||||||||
| 233 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||||||||
| 234 | HMAC_CTX_cleanup(&c); | - | ||||||||||||||||||
| 235 | return executed 18 times by 2 tests: md;return md;Executed by:
executed 18 times by 2 tests: return md;Executed by:
| 18 | ||||||||||||||||||
| 236 | err: | - | ||||||||||||||||||
| 237 | HMAC_CTX_cleanup(&c); | - | ||||||||||||||||||
| 238 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 239 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 240 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 241 | } | - | ||||||||||||||||||
| Switch to Source code | Preprocessed file |