summaryrefslogtreecommitdiff
path: root/vere/pkg/noun/jets/e/keccak.c
blob: 6149c55bda06e2b689a64024231b994f4cfc2f14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/// @file

#include "jets/q.h"
#include "jets/w.h"

#include "noun.h"
#include "urcrypt.h"

#define defw(bits,byts) \
  u3_atom \
  _kecc_##bits(c3_w len_w, u3_atom a) \
  { \
    c3_y  out[byts]; \
    c3_y* buf_y = u3r_bytes_alloc(0, len_w, a); \
    if ( 0 != urcrypt_keccak_##bits(buf_y, len_w, out) ) { \
      /* urcrypt_keccac_##bits always succeeds when called correctly */ \
      return u3m_bail(c3__oops); \
    } \
    else { \
      u3_atom pro = u3i_bytes(byts, out); \
      u3a_free(buf_y); \
      return pro; \
    } \
  } \
  \
  u3_weak \
  u3we_kecc##bits(u3_noun cor) \
  { \
    c3_w    len_w; \
    u3_noun len, tom; \
    u3x_mean(cor, u3x_sam_2, &len, u3x_sam_3, &tom, 0); \
    return ( (c3n == u3ud(len)) || (c3n == u3ud(tom)) ) \
      ? u3m_bail(c3__exit) \
      : (!u3r_word_fit(&len_w, len)) \
      ? u3m_bail(c3__fail) \
      : _kecc_##bits(len_w, tom); \
  }

defw(224, 28)
defw(256, 32)
defw(384, 48)
defw(512, 64)