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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
crate::ix!();

//-------------------------------------------[.cpp/bitcoin/src/bench/chacha_poly_aead.cpp]

/**
  | Number of bytes to process per iteration
  |
  */
pub const BUFFER_SIZE_TINY:  u64 = 64;
pub const BUFFER_SIZE_SMALL: u64 = 256;
pub const BUFFER_SIZE_LARGE: u64 = 1024 * 1024;

pub const K1: [u8; 32] = [0; 32];
pub const K2: [u8; 32] = [0; 32];

lazy_static!{
    /*
    static ChaCha20Poly1305AEAD aead(k1, 32, k2, 32);
    */
}

pub fn chacha20_poly1305_aead(
        bench:              &mut Bencher,
        buffersize:         usize,
        include_decryption: bool)  {
    
    todo!();
        /*
        std::vector<unsigned char> in(buffersize + CHACHA20_POLY1305_AEAD_AAD_LEN + POLY1305_TAGLEN, 0);
        std::vector<unsigned char> out(buffersize + CHACHA20_POLY1305_AEAD_AAD_LEN + POLY1305_TAGLEN, 0);
        uint64_t seqnr_payload = 0;
        uint64_t seqnr_aad = 0;
        int aad_pos = 0;
        uint32_t len = 0;
        bench.batch(buffersize).unit("byte").run([&] {
            // encrypt or decrypt the buffer with a static key
            const bool crypt_ok_1 = aead.Crypt(seqnr_payload, seqnr_aad, aad_pos, out.data(), out.size(), in.data(), buffersize, true);
            assert(crypt_ok_1);

            if (include_decryption) {
                // if we decrypt, include the GetLength
                const bool get_length_ok = aead.GetLength(&len, seqnr_aad, aad_pos, in.data());
                assert(get_length_ok);
                const bool crypt_ok_2 = aead.Crypt(seqnr_payload, seqnr_aad, aad_pos, out.data(), out.size(), in.data(), buffersize, true);
                assert(crypt_ok_2);
            }

            // increase main sequence number
            seqnr_payload++;
            // increase aad position (position in AAD keystream)
            aad_pos += CHACHA20_POLY1305_AEAD_AAD_LEN;
            if (aad_pos + CHACHA20_POLY1305_AEAD_AAD_LEN > CHACHA20_ROUND_OUTPUT) {
                aad_pos = 0;
                seqnr_aad++;
            }
            if (seqnr_payload + 1 == std::numeric_limits<uint64_t>::max()) {
                // reuse of nonce+key is okay while benchmarking.
                seqnr_payload = 0;
                seqnr_aad = 0;
                aad_pos = 0;
            }
        });
        */
}

#[bench] fn chacha20_poly1305_aead_64bytes_only_encrypt(b: &mut Bencher)  {
    
    todo!();
        /*
            CHACHA20_POLY1305_AEAD(bench, BUFFER_SIZE_TINY, false);
        */
}

#[bench] fn chacha20_poly1305_aead_256bytes_only_encrypt(b: &mut Bencher)  {
    
    todo!();
        /*
            CHACHA20_POLY1305_AEAD(bench, BUFFER_SIZE_SMALL, false);
        */
}

#[bench] fn chacha20_poly1305_aead_1mb_only_encrypt(b: &mut Bencher)  {
    
    todo!();
        /*
            CHACHA20_POLY1305_AEAD(bench, BUFFER_SIZE_LARGE, false);
        */
}

#[bench] fn chacha20_poly1305_aead_64bytes_encrypt_decrypt(b: &mut Bencher)  {
    
    todo!();
        /*
            CHACHA20_POLY1305_AEAD(bench, BUFFER_SIZE_TINY, true);
        */
}

#[bench] fn chacha20_poly1305_aead_256bytes_encrypt_decrypt(b: &mut Bencher)  {
    
    todo!();
        /*
            CHACHA20_POLY1305_AEAD(bench, BUFFER_SIZE_SMALL, true);
        */
}

#[bench] fn chacha20_poly1305_aead_1mb_encrypt_decrypt(b: &mut Bencher)  {
    
    todo!();
        /*
            CHACHA20_POLY1305_AEAD(bench, BUFFER_SIZE_LARGE, true);
        */
}

/* - * Add Hash() (dbl-sha256) bench for comparison  - */

pub fn hash(
    bench:      &mut Bencher,
    buffersize: usize)  {

    todo!();
        /*
        uint8_t hash[CHash256::OUTPUT_SIZE];
        std::vector<uint8_t> in(buffersize,0);
        bench.batch(in.size()).unit("byte").run([&] {
            CHash256().Write(in).Finalize(hash);
        });
        */
}

#[bench] fn hash_64bytes(b: &mut Bencher)  {
    
    todo!();
        /*
            HASH(bench, BUFFER_SIZE_TINY);
        */
}

#[bench] fn hash_256bytes(b: &mut Bencher)  {
    
    todo!();
        /*
            HASH(bench, BUFFER_SIZE_SMALL);
        */
}

#[bench] fn hash_1mb(b: &mut Bencher)  {
    
    todo!();
        /*
            HASH(bench, BUFFER_SIZE_LARGE);
        */
}