-
Notifications
You must be signed in to change notification settings - Fork 0
/
balloon.h
69 lines (59 loc) · 1.95 KB
/
balloon.h
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <openssl/aes.h>
#include <openssl/evp.h>
#include <openssl/sha.h>
#ifdef __cplusplus
extern "C" {
#endif
#define BITSTREAM_BUF_SIZE ((32) * (AES_BLOCK_SIZE))
#define N_NEIGHBORS (3)
#define SALT_LEN (32)
#define INLEN_MAX (1ull<<20)
#define TCOST_MIN 1ull
#define SCOST_MIN (1)
#define SCOST_MAX (UINT32_MAX)
#define BLOCKS_MIN (1ull)
#define THREADS_MAX 4096
#define BLOCK_SIZE (32)
#define UNUSED __attribute__ ((unused))
struct bitstream {
bool initialized;
uint8_t *zeros;
SHA256_CTX c;
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
EVP_CIPHER_CTX* ctx;
#else
//EVP_CIPHER_CTX ctx;
#endif
};
struct hash_state;
struct hash_state {
uint64_t counter;
uint64_t n_blocks;
bool has_mixed;
uint8_t *buffer;
struct bitstream bstream;
const struct balloon_options *opts;
};
struct balloon_options {
int64_t s_cost;
int32_t t_cost;
};
void balloon_hash(unsigned char *input, unsigned char *output);
void balloon(int thr_id, uint32_t threads, const uint8_t* input, uint8_t* output, uint32_t *h_nounce);
extern void balloon_128_cuda(int thr_id, uint32_t threads, const uint8_t* input, uint8_t* output, uint32_t *h_nounce);
static inline void bitstream_seed_finalize(struct bitstream *b);
void hash_state_init(struct hash_state *s, const struct balloon_options *opts, const uint8_t salt[SALT_LEN]);
void hash_state_free(struct hash_state *s);
void hash_state_fill(struct hash_state *s, const uint8_t *in, size_t inlen);
void hash_state_mix(struct hash_state *s);
extern void hash_state_fill_cuda(struct hash_state *s, const uint8_t *in, size_t inlen);
extern void hash_state_mix_cuda(struct hash_state *s);
void hash_state_extract(const struct hash_state *s, uint8_t out[BLOCK_SIZE]);
uint8_t * block_index(const struct hash_state *s, size_t i);
void * block_last(const struct hash_state *s);
#ifdef __cplusplus
}
#endif