emp-toolkit
com.h
Go to the documentation of this file.
1 #ifndef COM_H__
2 #define COM_H__
3 #include "string.h"
4 #include "hash.h"
5 #include "prg.h"
10 typedef char Com[20];
11 typedef block Decom[1];
12 
13 class Commitment{ public:
16  void commit(Decom decom, Com com, const void * message, int nbytes) {
17  prg.random_block(decom, 1);
18  h.reset();
19  h.put_block(decom, 1);
20  h.put(message, nbytes);
21  h.digest(com);
22  }
23 
24  bool open(Decom decom, Com com, const void * message, int nbytes) {
25  h.reset();
26  h.put_block(decom, 1);
27  h.put(message, nbytes);
28  Com res;
29  h.digest(res);
30  return strncmp(com, res, Hash::DIGEST_SIZE)==0;
31  }
32 };
34 #endif// COM_H__
void reset()
Definition: hash.h:45
Definition: com.h:13
Hash h
Definition: com.h:14
__m128i block
Definition: block.h:8
void put_block(const block *block, int nblock=1)
Definition: hash.h:35
void put(const void *data, int nbyte)
Definition: hash.h:23
void random_block(block *data, int nblocks=1)
Definition: prg.h:75
char Com[20]
Definition: com.h:10
block Decom[1]
Definition: com.h:11
Definition: prg.h:16
Definition: hash.h:12
void digest(char *a)
Definition: hash.h:38
bool open(Decom decom, Com com, const void *message, int nbytes)
Definition: com.h:24
static const int DIGEST_SIZE
Definition: hash.h:17
void commit(Decom decom, Com com, const void *message, int nbytes)
Definition: com.h:16
PRG prg
Definition: com.h:15