Electroneum
keccak.cpp File Reference
#include "gtest/gtest.h"
#include "crypto/keccak.h"
Include dependency graph for keccak.cpp:

Go to the source code of this file.

Macros

#define KECCAK_BLOCKLEN   136
 
#define TEST_KECCAK(sz, chunks)
 

Functions

 TEST (keccak, 0_and_0)
 
 TEST (keccak, 1_and_1)
 
 TEST (keccak, 1_and_0_1_0)
 
 TEST (keccak, 2_and_1_1)
 
 TEST (keccak, 4_and_0_0_1_0_2_1_0)
 
 TEST (keccak, 15_and_1_14)
 
 TEST (keccak, 135_and_134_1)
 
 TEST (keccak, 135_and_135_0)
 
 TEST (keccak, 135_and_0_135)
 
 TEST (keccak, 136_and_135_1)
 
 TEST (keccak, 136_and_136_0)
 
 TEST (keccak, 136_and_0_136)
 
 TEST (keccak, 136_and_136)
 
 TEST (keccak, 137_and_136_1)
 
 TEST (keccak, 137_and_1_136)
 
 TEST (keccak, alignment)
 

Macro Definition Documentation

◆ KECCAK_BLOCKLEN

#define KECCAK_BLOCKLEN   136

Definition at line 35 of file keccak.cpp.

◆ TEST_KECCAK

#define TEST_KECCAK (   sz,
  chunks 
)
Value:
std::string data; \
data.resize(sz); \
for (size_t i = 0; i < data.size(); ++i) \
data[i] = i * 17; \
uint8_t md0[32], md1[32]; \
keccak((const uint8_t*)data.data(), data.size(), md0, 32); \
KECCAK_CTX ctx; \
keccak_init(&ctx); \
size_t offset = 0; \
for (size_t i = 0; i < sizeof(chunks) / sizeof(chunks[0]); ++i) \
{ \
ASSERT_TRUE(offset + chunks[i] <= data.size()); \
keccak_update(&ctx, (const uint8_t*)data.data() + offset, chunks[i]); \
offset += chunks[i]; \
} \
ASSERT_TRUE(offset == data.size()); \
keccak_finish(&ctx, md1); \
ASSERT_EQ(memcmp(md0, md1, 32), 0);
::std::string string
Definition: gtest-port.h:1097
unsigned char uint8_t
Definition: stdint.h:124

Definition at line 37 of file keccak.cpp.

Function Documentation

◆ TEST() [1/16]

TEST ( keccak  ,
0_and_0   
)

Definition at line 57 of file keccak.cpp.

58 {
59  static const size_t chunks[] = {0};
60  TEST_KECCAK(0, chunks);
61 }
#define TEST_KECCAK(sz, chunks)
Definition: keccak.cpp:37

◆ TEST() [2/16]

TEST ( keccak  ,
1_and_1   
)

Definition at line 63 of file keccak.cpp.

64 {
65  static const size_t chunks[] = {1};
66  TEST_KECCAK(1, chunks);
67 }
#define TEST_KECCAK(sz, chunks)
Definition: keccak.cpp:37

◆ TEST() [3/16]

TEST ( keccak  ,
1_and_0_1_0   
)

Definition at line 69 of file keccak.cpp.

70 {
71  static const size_t chunks[] = {0, 1, 0};
72  TEST_KECCAK(1, chunks);
73 }
#define TEST_KECCAK(sz, chunks)
Definition: keccak.cpp:37

◆ TEST() [4/16]

TEST ( keccak  ,
2_and_1_1   
)

Definition at line 75 of file keccak.cpp.

76 {
77  static const size_t chunks[] = {1, 1};
78  TEST_KECCAK(2, chunks);
79 }
#define TEST_KECCAK(sz, chunks)
Definition: keccak.cpp:37

◆ TEST() [5/16]

TEST ( keccak  ,
4_and_0_0_1_0_2_1_0   
)

Definition at line 81 of file keccak.cpp.

82 {
83  static const size_t chunks[] = {0, 0, 1, 0, 2, 1, 0};
84  TEST_KECCAK(4, chunks);
85 }
#define TEST_KECCAK(sz, chunks)
Definition: keccak.cpp:37

◆ TEST() [6/16]

TEST ( keccak  ,
15_and_1_14   
)

Definition at line 87 of file keccak.cpp.

88 {
89  static const size_t chunks[] = {1, 14};
90  TEST_KECCAK(15, chunks);
91 }
#define TEST_KECCAK(sz, chunks)
Definition: keccak.cpp:37

◆ TEST() [7/16]

TEST ( keccak  ,
135_and_134_1   
)

Definition at line 93 of file keccak.cpp.

94 {
95  static const size_t chunks[] = {134, 1};
96  TEST_KECCAK(135, chunks);
97 }
#define TEST_KECCAK(sz, chunks)
Definition: keccak.cpp:37

◆ TEST() [8/16]

TEST ( keccak  ,
135_and_135_0   
)

Definition at line 99 of file keccak.cpp.

100 {
101  static const size_t chunks[] = {135, 0};
102  TEST_KECCAK(135, chunks);
103 }
#define TEST_KECCAK(sz, chunks)
Definition: keccak.cpp:37

◆ TEST() [9/16]

TEST ( keccak  ,
135_and_0_135   
)

Definition at line 105 of file keccak.cpp.

106 {
107  static const size_t chunks[] = {0, 135};
108  TEST_KECCAK(135, chunks);
109 }
#define TEST_KECCAK(sz, chunks)
Definition: keccak.cpp:37

◆ TEST() [10/16]

TEST ( keccak  ,
136_and_135_1   
)

Definition at line 111 of file keccak.cpp.

112 {
113  static const size_t chunks[] = {135, 1};
114  TEST_KECCAK(136, chunks);
115 }
#define TEST_KECCAK(sz, chunks)
Definition: keccak.cpp:37

◆ TEST() [11/16]

TEST ( keccak  ,
136_and_136_0   
)

Definition at line 117 of file keccak.cpp.

118 {
119  static const size_t chunks[] = {136, 0};
120  TEST_KECCAK(136, chunks);
121 }
#define TEST_KECCAK(sz, chunks)
Definition: keccak.cpp:37

◆ TEST() [12/16]

TEST ( keccak  ,
136_and_0_136   
)

Definition at line 123 of file keccak.cpp.

124 {
125  static const size_t chunks[] = {0, 136};
126  TEST_KECCAK(136, chunks);
127 }
#define TEST_KECCAK(sz, chunks)
Definition: keccak.cpp:37

◆ TEST() [13/16]

TEST ( keccak  ,
136_and_136   
)

Definition at line 129 of file keccak.cpp.

130 {
131  static const size_t chunks[] = {136};
132  TEST_KECCAK(136, chunks);
133 }
#define TEST_KECCAK(sz, chunks)
Definition: keccak.cpp:37

◆ TEST() [14/16]

TEST ( keccak  ,
137_and_136_1   
)

Definition at line 135 of file keccak.cpp.

136 {
137  static const size_t chunks[] = {136, 1};
138  TEST_KECCAK(137, chunks);
139 }
#define TEST_KECCAK(sz, chunks)
Definition: keccak.cpp:37

◆ TEST() [15/16]

TEST ( keccak  ,
137_and_1_136   
)

Definition at line 141 of file keccak.cpp.

142 {
143  static const size_t chunks[] = {1, 136};
144  TEST_KECCAK(137, chunks);
145 }
#define TEST_KECCAK(sz, chunks)
Definition: keccak.cpp:37

◆ TEST() [16/16]

TEST ( keccak  ,
alignment   
)

Definition at line 147 of file keccak.cpp.

148 {
149  uint8_t data[6064];
150  __attribute__ ((aligned(16))) char adata[6000];
151 
152  for (size_t i = 0; i < sizeof(data) / sizeof(data[0]); ++i)
153  data[i] = i & 1;
154 
155  uint8_t md[32], amd[32];
156  for (int offset = 0; offset < 64; ++offset)
157  {
158  memcpy(adata, data + offset, 6000);
159  keccak((const uint8_t*)&data[offset], 6000, md, 32);
160  keccak((const uint8_t*)adata, 6000, amd, 32);
161  ASSERT_TRUE(!memcmp(md, amd, 32));
162  }
163 }
unsigned char uint8_t
Definition: stdint.h:124
for(i=1;i< 1;++i) fe_sq(t0
void * memcpy(void *a, const void *b, size_t c)
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
void keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen)
__attribute__((noreturn)) void CXA_THROW(void *ex
Here is the call graph for this function: