aboutsummaryrefslogtreecommitdiff
path: root/crypto.h
blob: d536a3936a0f79c9fd09a265c7b3043306bcbb13 (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
#ifndef CSAA_CRYPTO_H
#define CSAA_CRYPTO_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

/* Various useful cryptographic functions; shared between TM and SP. */

/* we use SHA256 for h() */
typedef struct hash_t {
    /* a hash of all zeros is given a special meaning */
    unsigned char hash[32];
} hash_t;

struct iomt_node {
    int idx, next_idx; /* idx cannot be zero */
    hash_t val; /* all zero indicates placeholder */
};

/* guaranteed to be zero */
static const struct hash_t hash_null = { { 0 } };

bool encloses(int b, int bprime, int a);
bool hash_equals(hash_t a, hash_t b);
bool is_zero(hash_t u);

hash_t hash_node(const struct iomt_node *node);
hash_t hash_xor(hash_t a, hash_t b);
void hash_zero(hash_t *h);

hash_t sha256(const void *data, size_t datalen);
hash_t hmac_sha256(const void *data, size_t datalen, const void *key, size_t keylen);

hash_t merkle_compute(hash_t node, const hash_t *comp, const int *orders, size_t n);
hash_t merkle_parent(hash_t u, hash_t v, int order);

uint64_t hash_to_u64(hash_t h);
void dump_hash(hash_t u);

#endif