tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

compat_blake2.h (1061B)


      1 /* Copyright (c) 2023, The Tor Project, Inc. */
      2 /* See LICENSE for licensing information */
      3 
      4 /**
      5 * \file compat_blake2.h
      6 *
      7 * \brief Compatibility adapter providing blake2b using ext/equix/hashx
      8 **/
      9 
     10 #ifndef TOR_COMPAT_BLAKE2_H
     11 #define TOR_COMPAT_BLAKE2_H
     12 
     13 #include <stddef.h>
     14 #include <string.h>
     15 #include "lib/cc/compat_compiler.h"
     16 #include "ext/equix/hashx/src/blake2.h"
     17 
     18 static inline int
     19 blake2b_init_param(blake2b_state *S, const blake2b_param *P)
     20 {
     21    return hashx_blake2b_init_param(S, P);
     22 }
     23 
     24 static inline int
     25 blake2b_init(blake2b_state *S, const uint8_t digest_length)
     26 {
     27    blake2b_param P;
     28    memset(&P, 0, sizeof P);
     29    P.digest_length = digest_length;
     30    P.fanout = 1;
     31    P.depth = 1;
     32    return blake2b_init_param(S, &P);
     33 }
     34 
     35 static inline int
     36 blake2b_update(blake2b_state *S, const uint8_t *in, uint64_t inlen)
     37 {
     38    return hashx_blake2b_update(S, in, inlen);
     39 }
     40 
     41 static inline int
     42 blake2b_final(blake2b_state *S, uint8_t *out, uint8_t outlen)
     43 {
     44    return hashx_blake2b_final(S, out, outlen);
     45 }
     46 
     47 #endif /* !defined(TOR_COMPAT_BLAKE2_H) */