Coverage Report

Created: 2023-03-20 06:33

/src/dropbear/libtomcrypt/src/stream/chacha/chacha_ivctr64.c
Line
Count
Source
1
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2
 *
3
 * LibTomCrypt is a library that provides various cryptographic
4
 * algorithms in a highly modular and flexible manner.
5
 *
6
 * The library is free for all purposes without any express
7
 * guarantee it works.
8
 */
9
10
/* The implementation is based on:
11
 * chacha-ref.c version 20080118
12
 * Public domain from D. J. Bernstein
13
 */
14
15
#include "tomcrypt.h"
16
17
#ifdef LTC_CHACHA
18
19
/**
20
  Set IV + counter data to the ChaCha state
21
  @param st      The ChaCha20 state
22
  @param iv      The IV data to add
23
  @param ivlen   The length of the IV (must be 8)
24
  @param counter 64bit (unsigned) initial counter value
25
  @return CRYPT_OK on success
26
 */
27
int chacha_ivctr64(chacha_state *st, const unsigned char *iv, unsigned long ivlen, ulong64 counter)
28
736k
{
29
736k
   LTC_ARGCHK(st != NULL);
30
736k
   LTC_ARGCHK(iv != NULL);
31
   /* 64bit IV + 64bit counter */
32
736k
   LTC_ARGCHK(ivlen == 8);
33
34
736k
   st->input[12] = (ulong32)(counter & 0xFFFFFFFF);
35
736k
   st->input[13] = (ulong32)(counter >> 32);
36
736k
   LOAD32L(st->input[14], iv + 0);
37
736k
   LOAD32L(st->input[15], iv + 4);
38
736k
   st->ksleft = 0;
39
736k
   st->ivlen = ivlen;
40
736k
   return CRYPT_OK;
41
736k
}
42
43
#endif
44
45
/* ref:         $Format:%D$ */
46
/* git commit:  $Format:%H$ */
47
/* commit time: $Format:%ai$ */