OpenCoverage

chacha.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/chacha/chacha.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* $OpenBSD: chacha.c,v 1.7 2015/12/09 14:07:55 bcook Exp $ */-
2/*-
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>-
4 *-
5 * Permission to use, copy, modify, and distribute this software for any-
6 * purpose with or without fee is hereby granted, provided that the above-
7 * copyright notice and this permission notice appear in all copies.-
8 *-
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES-
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF-
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR-
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES-
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN-
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF-
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.-
16 */-
17-
18#include <stdint.h>-
19-
20#include <openssl/chacha.h>-
21-
22#include "chacha-merged.c"-
23-
24void-
25ChaCha_set_key(ChaCha_ctx *ctx, const unsigned char *key, uint32_t keybits)-
26{-
27 chacha_keysetup((chacha_ctx *)ctx, key, keybits);-
28 ctx->unused = 0;-
29}
executed 32 times by 2 tests: end of block
Executed by:
  • chachatest
  • evptest
32
30-
31void-
32ChaCha_set_iv(ChaCha_ctx *ctx, const unsigned char *iv,-
33 const unsigned char *counter)-
34{-
35 chacha_ivsetup((chacha_ctx *)ctx, iv, counter);-
36 ctx->unused = 0;-
37}
executed 32 times by 2 tests: end of block
Executed by:
  • chachatest
  • evptest
32
38-
39void-
40ChaCha(ChaCha_ctx *ctx, unsigned char *out, const unsigned char *in, size_t len)-
41{-
42 unsigned char *k;-
43 int i, l;-
44-
45 /* Consume remaining keystream, if any exists. */-
46 if (ctx->unused > 0) {
ctx->unused > 0Description
TRUEevaluated 552 times by 1 test
Evaluated by:
  • chachatest
FALSEevaluated 32 times by 2 tests
Evaluated by:
  • chachatest
  • evptest
32-552
47 k = ctx->ks + 64 - ctx->unused;-
48 l = (len > ctx->unused) ? ctx->unused : len;
(len > ctx->unused)Description
TRUEnever evaluated
FALSEevaluated 552 times by 1 test
Evaluated by:
  • chachatest
0-552
49 for (i = 0; i < l; i++)
i < lDescription
TRUEevaluated 768 times by 1 test
Evaluated by:
  • chachatest
FALSEevaluated 552 times by 1 test
Evaluated by:
  • chachatest
552-768
50 *(out++) = *(in++) ^ *(k++);
executed 768 times by 1 test: *(out++) = *(in++) ^ *(k++);
Executed by:
  • chachatest
768
51 ctx->unused -= l;-
52 len -= l;-
53 }
executed 552 times by 1 test: end of block
Executed by:
  • chachatest
552
54-
55 chacha_encrypt_bytes((chacha_ctx *)ctx, in, out, (uint32_t)len);-
56}
executed 584 times by 2 tests: end of block
Executed by:
  • chachatest
  • evptest
584
57-
58void-
59CRYPTO_chacha_20(unsigned char *out, const unsigned char *in, size_t len,-
60 const unsigned char key[32], const unsigned char iv[8], uint64_t counter)-
61{-
62 struct chacha_ctx ctx;-
63-
64 /*-
65 * chacha_ivsetup expects the counter to be in u8. Rather than-
66 * converting size_t to u8 and then back again, pass a counter of-
67 * NULL and manually assign it afterwards.-
68 */-
69 chacha_keysetup(&ctx, key, 256);-
70 chacha_ivsetup(&ctx, iv, NULL);-
71 if (counter != 0) {
counter != 0Description
TRUEevaluated 325 times by 3 tests
Evaluated by:
  • aeadtest
  • ssltest
  • tlstest
FALSEevaluated 11 times by 2 tests
Evaluated by:
  • aeadtest
  • chachatest
11-325
72 ctx.input[12] = (uint32_t)counter;-
73 ctx.input[13] = (uint32_t)(counter >> 32);-
74 }
executed 325 times by 3 tests: end of block
Executed by:
  • aeadtest
  • ssltest
  • tlstest
325
75-
76 chacha_encrypt_bytes(&ctx, in, out, (uint32_t)len);-
77}
executed 336 times by 4 tests: end of block
Executed by:
  • aeadtest
  • chachatest
  • ssltest
  • tlstest
336
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2