annotate libtomcrypt/src/hashes/blake2b.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1471
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 *
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 * LibTomCrypt is a library that provides various cryptographic
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 * algorithms in a highly modular and flexible manner.
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 *
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 * The library is free for all purposes without any express
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 * guarantee it works.
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 /*
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 BLAKE2 reference source code package - reference C implementations
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 Copyright 2012, Samuel Neves <[email protected]>. You may use this under the
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 your option. The terms of these licenses can be found at:
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 - OpenSSL license : https://www.openssl.org/source/license.html
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 More information about the BLAKE2 hash function can be found at
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 https://blake2.net.
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 /* see also https://www.ietf.org/rfc/rfc7693.txt */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 #include "tomcrypt.h"
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 #ifdef LTC_BLAKE2B
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 enum blake2b_constant {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 BLAKE2B_BLOCKBYTES = 128,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 BLAKE2B_OUTBYTES = 64,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 BLAKE2B_KEYBYTES = 64,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 BLAKE2B_SALTBYTES = 16,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 BLAKE2B_PERSONALBYTES = 16,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 BLAKE2B_PARAM_SIZE = 64
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 };
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 /* param offsets */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 enum {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 O_DIGEST_LENGTH = 0,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 O_KEY_LENGTH = 1,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 O_FANOUT = 2,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 O_DEPTH = 3,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 O_LEAF_LENGTH = 4,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 O_NODE_OFFSET = 8,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 O_XOF_LENGTH = 12,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 O_NODE_DEPTH = 16,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49 O_INNER_LENGTH = 17,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 O_RESERVED = 18,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51 O_SALT = 32,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 O_PERSONAL = 48
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53 };
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 /*
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 struct blake2b_param {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 unsigned char digest_length;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58 unsigned char key_length;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 unsigned char fanout;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 unsigned char depth;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 ulong32 leaf_length;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 ulong32 node_offset;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 ulong32 xof_length;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 unsigned char node_depth;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 unsigned char inner_length;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66 unsigned char reserved[14];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 unsigned char salt[BLAKE2B_SALTBYTES];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 unsigned char personal[BLAKE2B_PERSONALBYTES];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 };
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70 */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72 const struct ltc_hash_descriptor blake2b_160_desc =
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 "blake2b-160",
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 25,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76 20,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77 128,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78 { 1, 3, 6, 1, 4, 1, 1722, 12, 2, 1, 5 },
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 11,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 &blake2b_160_init,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81 &blake2b_process,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 &blake2b_done,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83 &blake2b_160_test,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 NULL
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 };
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 const struct ltc_hash_descriptor blake2b_256_desc =
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 "blake2b-256",
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 26,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 32,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92 128,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93 { 1, 3, 6, 1, 4, 1, 1722, 12, 2, 1, 8 },
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94 11,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 &blake2b_256_init,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96 &blake2b_process,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97 &blake2b_done,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 &blake2b_256_test,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99 NULL
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100 };
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
102 const struct ltc_hash_descriptor blake2b_384_desc =
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
103 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104 "blake2b-384",
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105 27,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106 48,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107 128,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108 { 1, 3, 6, 1, 4, 1, 1722, 12, 2, 1, 12 },
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109 11,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110 &blake2b_384_init,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
111 &blake2b_process,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112 &blake2b_done,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
113 &blake2b_384_test,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114 NULL
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115 };
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
117 const struct ltc_hash_descriptor blake2b_512_desc =
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
119 "blake2b-512",
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120 28,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121 64,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
122 128,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123 { 1, 3, 6, 1, 4, 1, 1722, 12, 2, 1, 16 },
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
124 11,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
125 &blake2b_512_init,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
126 &blake2b_process,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
127 &blake2b_done,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
128 &blake2b_512_test,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
129 NULL
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
130 };
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
131
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
132 static const ulong64 blake2b_IV[8] =
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
133 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134 CONST64(0x6a09e667f3bcc908), CONST64(0xbb67ae8584caa73b),
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135 CONST64(0x3c6ef372fe94f82b), CONST64(0xa54ff53a5f1d36f1),
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136 CONST64(0x510e527fade682d1), CONST64(0x9b05688c2b3e6c1f),
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137 CONST64(0x1f83d9abfb41bd6b), CONST64(0x5be0cd19137e2179)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138 };
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
139
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
140 static const unsigned char blake2b_sigma[12][16] =
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
141 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
142 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
143 { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } ,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
144 { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } ,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
145 { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } ,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
146 { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } ,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
147 { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } ,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
148 { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } ,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
149 { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } ,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150 { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } ,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
151 { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } ,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
152 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
153 { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
154 };
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
155
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
156 static void blake2b_set_lastnode(hash_state *md) { md->blake2b.f[1] = CONST64(0xffffffffffffffff); }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
157
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
158 /* Some helper functions, not necessarily useful */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
159 static int blake2b_is_lastblock(const hash_state *md) { return md->blake2b.f[0] != 0; }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
160
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
161 static void blake2b_set_lastblock(hash_state *md)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
162 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
163 if (md->blake2b.last_node)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
164 blake2b_set_lastnode(md);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
165
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
166 md->blake2b.f[0] = CONST64(0xffffffffffffffff);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
167 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
168
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
169 static void blake2b_increment_counter(hash_state *md, ulong64 inc)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
170 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
171 md->blake2b.t[0] += inc;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
172 if (md->blake2b.t[0] < inc) md->blake2b.t[1]++;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
173 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
174
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
175 static void blake2b_init0(hash_state *md)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
176 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
177 unsigned long i;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
178 XMEMSET(&md->blake2b, 0, sizeof(md->blake2b));
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
179
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
180 for (i = 0; i < 8; ++i)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
181 md->blake2b.h[i] = blake2b_IV[i];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
182 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
183
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
184 /* init xors IV with input parameter block */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
185 static int blake2b_init_param(hash_state *md, const unsigned char *P)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
186 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
187 unsigned long i;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
188
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
189 blake2b_init0(md);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
190
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
191 /* IV XOR ParamBlock */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
192 for (i = 0; i < 8; ++i) {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
193 ulong64 tmp;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
194 LOAD64L(tmp, P + i * 8);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
195 md->blake2b.h[i] ^= tmp;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
196 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
197
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
198 md->blake2b.outlen = P[O_DIGEST_LENGTH];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
199 return CRYPT_OK;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
200 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
201
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
202 int blake2b_init(hash_state *md, unsigned long outlen, const unsigned char *key, unsigned long keylen)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
203 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
204 unsigned char P[BLAKE2B_PARAM_SIZE];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
205 int err;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
206
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
207 LTC_ARGCHK(md != NULL);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
208
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
209 if ((!outlen) || (outlen > BLAKE2B_OUTBYTES))
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
210 return CRYPT_INVALID_ARG;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
211
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
212 if ((key && !keylen) || (keylen && !key) || (keylen > BLAKE2B_KEYBYTES))
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
213 return CRYPT_INVALID_ARG;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
214
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
215 XMEMSET(P, 0, sizeof(P));
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
216
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
217 P[O_DIGEST_LENGTH] = (unsigned char)outlen;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
218 P[O_KEY_LENGTH] = (unsigned char)keylen;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
219 P[O_FANOUT] = 1;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
220 P[O_DEPTH] = 1;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
221
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
222 err = blake2b_init_param(md, P);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
223 if (err != CRYPT_OK) return err;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
224
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
225 if (key) {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
226 unsigned char block[BLAKE2B_BLOCKBYTES];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
227
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
228 XMEMSET(block, 0, BLAKE2B_BLOCKBYTES);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
229 XMEMCPY(block, key, keylen);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
230 blake2b_process(md, block, BLAKE2B_BLOCKBYTES);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
231
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
232 #ifdef LTC_CLEAN_STACK
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
233 zeromem(block, sizeof(block));
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
234 #endif
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
235 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
236
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
237 return CRYPT_OK;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
238 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
239
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
240 int blake2b_160_init(hash_state *md) { return blake2b_init(md, 20, NULL, 0); }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
241
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
242 int blake2b_256_init(hash_state *md) { return blake2b_init(md, 32, NULL, 0); }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
243
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
244 int blake2b_384_init(hash_state *md) { return blake2b_init(md, 48, NULL, 0); }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
245
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
246 int blake2b_512_init(hash_state *md) { return blake2b_init(md, 64, NULL, 0); }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
247
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
248 #define G(r, i, a, b, c, d) \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
249 do { \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
250 a = a + b + m[blake2b_sigma[r][2 * i + 0]]; \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
251 d = ROR64(d ^ a, 32); \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
252 c = c + d; \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
253 b = ROR64(b ^ c, 24); \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
254 a = a + b + m[blake2b_sigma[r][2 * i + 1]]; \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
255 d = ROR64(d ^ a, 16); \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
256 c = c + d; \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
257 b = ROR64(b ^ c, 63); \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
258 } while (0)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
259
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
260 #define ROUND(r) \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
261 do { \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
262 G(r, 0, v[0], v[4], v[8], v[12]); \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
263 G(r, 1, v[1], v[5], v[9], v[13]); \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
264 G(r, 2, v[2], v[6], v[10], v[14]); \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
265 G(r, 3, v[3], v[7], v[11], v[15]); \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
266 G(r, 4, v[0], v[5], v[10], v[15]); \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
267 G(r, 5, v[1], v[6], v[11], v[12]); \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
268 G(r, 6, v[2], v[7], v[8], v[13]); \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
269 G(r, 7, v[3], v[4], v[9], v[14]); \
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
270 } while (0)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
271
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
272 #ifdef LTC_CLEAN_STACK
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
273 static int _blake2b_compress(hash_state *md, const unsigned char *buf)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
274 #else
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
275 static int blake2b_compress(hash_state *md, const unsigned char *buf)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
276 #endif
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
277 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
278 ulong64 m[16];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
279 ulong64 v[16];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
280 unsigned long i;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
281
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
282 for (i = 0; i < 16; ++i) {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
283 LOAD64L(m[i], buf + i * sizeof(m[i]));
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
284 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
285
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
286 for (i = 0; i < 8; ++i) {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
287 v[i] = md->blake2b.h[i];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
288 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
289
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
290 v[8] = blake2b_IV[0];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
291 v[9] = blake2b_IV[1];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
292 v[10] = blake2b_IV[2];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
293 v[11] = blake2b_IV[3];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
294 v[12] = blake2b_IV[4] ^ md->blake2b.t[0];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
295 v[13] = blake2b_IV[5] ^ md->blake2b.t[1];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
296 v[14] = blake2b_IV[6] ^ md->blake2b.f[0];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
297 v[15] = blake2b_IV[7] ^ md->blake2b.f[1];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
298
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
299 ROUND(0);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
300 ROUND(1);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
301 ROUND(2);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
302 ROUND(3);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
303 ROUND(4);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
304 ROUND(5);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
305 ROUND(6);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
306 ROUND(7);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
307 ROUND(8);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
308 ROUND(9);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
309 ROUND(10);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
310 ROUND(11);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
311
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
312 for (i = 0; i < 8; ++i) {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
313 md->blake2b.h[i] = md->blake2b.h[i] ^ v[i] ^ v[i + 8];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
314 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
315 return CRYPT_OK;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
316 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
317
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
318 #undef G
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
319 #undef ROUND
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
320
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
321 #ifdef LTC_CLEAN_STACK
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
322 static int blake2b_compress(hash_state *md, const unsigned char *buf)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
323 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
324 int err;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
325 err = _blake2b_compress(md, buf);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
326 burn_stack(sizeof(ulong64) * 32 + sizeof(unsigned long));
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
327 return err;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
328 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
329 #endif
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
330
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
331 int blake2b_process(hash_state *md, const unsigned char *in, unsigned long inlen)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
332 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
333 LTC_ARGCHK(md != NULL);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
334 LTC_ARGCHK(in != NULL);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
335
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
336 if (md->blake2b.curlen > sizeof(md->blake2b.buf)) {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
337 return CRYPT_INVALID_ARG;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
338 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
339
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
340 if (inlen > 0) {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
341 unsigned long left = md->blake2b.curlen;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
342 unsigned long fill = BLAKE2B_BLOCKBYTES - left;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
343 if (inlen > fill) {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
344 md->blake2b.curlen = 0;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
345 XMEMCPY(md->blake2b.buf + (left % sizeof(md->blake2b.buf)), in, fill); /* Fill buffer */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
346 blake2b_increment_counter(md, BLAKE2B_BLOCKBYTES);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
347 blake2b_compress(md, md->blake2b.buf); /* Compress */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
348 in += fill;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
349 inlen -= fill;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
350 while (inlen > BLAKE2B_BLOCKBYTES) {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
351 blake2b_increment_counter(md, BLAKE2B_BLOCKBYTES);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
352 blake2b_compress(md, in);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
353 in += BLAKE2B_BLOCKBYTES;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
354 inlen -= BLAKE2B_BLOCKBYTES;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
355 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
356 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
357 XMEMCPY(md->blake2b.buf + md->blake2b.curlen, in, inlen);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
358 md->blake2b.curlen += inlen;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
359 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
360 return CRYPT_OK;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
361 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
362
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
363 int blake2b_done(hash_state *md, unsigned char *out)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
364 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
365 unsigned char buffer[BLAKE2B_OUTBYTES] = { 0 };
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
366 unsigned long i;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
367
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
368 LTC_ARGCHK(md != NULL);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
369 LTC_ARGCHK(out != NULL);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
370
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
371 /* if(md->blakebs.outlen != outlen) return CRYPT_INVALID_ARG; */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
372
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
373 if (blake2b_is_lastblock(md))
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
374 return CRYPT_ERROR;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
375
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
376 blake2b_increment_counter(md, md->blake2b.curlen);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
377 blake2b_set_lastblock(md);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
378 XMEMSET(md->blake2b.buf + md->blake2b.curlen, 0, BLAKE2B_BLOCKBYTES - md->blake2b.curlen); /* Padding */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
379 blake2b_compress(md, md->blake2b.buf);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
380
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
381 for (i = 0; i < 8; ++i) /* Output full hash to temp buffer */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
382 STORE64L(md->blake2b.h[i], buffer + i * 8);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
383
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
384 XMEMCPY(out, buffer, md->blake2b.outlen);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
385 zeromem(md, sizeof(hash_state));
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
386 #ifdef LTC_CLEAN_STACK
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
387 zeromem(buffer, sizeof(buffer));
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
388 #endif
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
389 return CRYPT_OK;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
390 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
391
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
392 /**
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
393 Self-test the hash
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
394 @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
395 */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
396 int blake2b_512_test(void)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
397 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
398 #ifndef LTC_TEST
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
399 return CRYPT_NOP;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
400 #else
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
401 static const struct {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
402 const char *msg;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
403 unsigned char hash[64];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
404 } tests[] = {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
405 { "",
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
406 { 0x78, 0x6a, 0x02, 0xf7, 0x42, 0x01, 0x59, 0x03,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
407 0xc6, 0xc6, 0xfd, 0x85, 0x25, 0x52, 0xd2, 0x72,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
408 0x91, 0x2f, 0x47, 0x40, 0xe1, 0x58, 0x47, 0x61,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
409 0x8a, 0x86, 0xe2, 0x17, 0xf7, 0x1f, 0x54, 0x19,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
410 0xd2, 0x5e, 0x10, 0x31, 0xaf, 0xee, 0x58, 0x53,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
411 0x13, 0x89, 0x64, 0x44, 0x93, 0x4e, 0xb0, 0x4b,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
412 0x90, 0x3a, 0x68, 0x5b, 0x14, 0x48, 0xb7, 0x55,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
413 0xd5, 0x6f, 0x70, 0x1a, 0xfe, 0x9b, 0xe2, 0xce } },
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
414 { "abc",
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
415 { 0xba, 0x80, 0xa5, 0x3f, 0x98, 0x1c, 0x4d, 0x0d,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
416 0x6a, 0x27, 0x97, 0xb6, 0x9f, 0x12, 0xf6, 0xe9,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
417 0x4c, 0x21, 0x2f, 0x14, 0x68, 0x5a, 0xc4, 0xb7,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
418 0x4b, 0x12, 0xbb, 0x6f, 0xdb, 0xff, 0xa2, 0xd1,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
419 0x7d, 0x87, 0xc5, 0x39, 0x2a, 0xab, 0x79, 0x2d,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
420 0xc2, 0x52, 0xd5, 0xde, 0x45, 0x33, 0xcc, 0x95,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
421 0x18, 0xd3, 0x8a, 0xa8, 0xdb, 0xf1, 0x92, 0x5a,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
422 0xb9, 0x23, 0x86, 0xed, 0xd4, 0x00, 0x99, 0x23 } },
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
423
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
424 { NULL, { 0 } }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
425 };
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
426
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
427 int i;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
428 unsigned char tmp[64];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
429 hash_state md;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
430
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
431 for (i = 0; tests[i].msg != NULL; i++) {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
432 blake2b_512_init(&md);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
433 blake2b_process(&md, (unsigned char *)tests[i].msg, (unsigned long)strlen(tests[i].msg));
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
434 blake2b_done(&md, tmp);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
435 if (compare_testvector(tmp, sizeof(tmp), tests[i].hash, sizeof(tests[i].hash), "BLAKE2B_512", i)) {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
436 return CRYPT_FAIL_TESTVECTOR;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
437 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
438 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
439 return CRYPT_OK;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
440 #endif
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
441 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
442
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
443 /**
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
444 Self-test the hash
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
445 @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
446 */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
447 int blake2b_384_test(void)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
448 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
449 #ifndef LTC_TEST
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
450 return CRYPT_NOP;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
451 #else
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
452 static const struct {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
453 const char *msg;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
454 unsigned char hash[48];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
455 } tests[] = {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
456 { "",
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
457 { 0xb3, 0x28, 0x11, 0x42, 0x33, 0x77, 0xf5, 0x2d,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
458 0x78, 0x62, 0x28, 0x6e, 0xe1, 0xa7, 0x2e, 0xe5,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
459 0x40, 0x52, 0x43, 0x80, 0xfd, 0xa1, 0x72, 0x4a,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
460 0x6f, 0x25, 0xd7, 0x97, 0x8c, 0x6f, 0xd3, 0x24,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
461 0x4a, 0x6c, 0xaf, 0x04, 0x98, 0x81, 0x26, 0x73,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
462 0xc5, 0xe0, 0x5e, 0xf5, 0x83, 0x82, 0x51, 0x00 } },
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
463 { "abc",
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
464 { 0x6f, 0x56, 0xa8, 0x2c, 0x8e, 0x7e, 0xf5, 0x26,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
465 0xdf, 0xe1, 0x82, 0xeb, 0x52, 0x12, 0xf7, 0xdb,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
466 0x9d, 0xf1, 0x31, 0x7e, 0x57, 0x81, 0x5d, 0xbd,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
467 0xa4, 0x60, 0x83, 0xfc, 0x30, 0xf5, 0x4e, 0xe6,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
468 0xc6, 0x6b, 0xa8, 0x3b, 0xe6, 0x4b, 0x30, 0x2d,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
469 0x7c, 0xba, 0x6c, 0xe1, 0x5b, 0xb5, 0x56, 0xf4 } },
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
470
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
471 { NULL, { 0 } }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
472 };
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
473
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
474 int i;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
475 unsigned char tmp[48];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
476 hash_state md;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
477
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
478 for (i = 0; tests[i].msg != NULL; i++) {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
479 blake2b_384_init(&md);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
480 blake2b_process(&md, (unsigned char *)tests[i].msg, (unsigned long)strlen(tests[i].msg));
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
481 blake2b_done(&md, tmp);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
482 if (compare_testvector(tmp, sizeof(tmp), tests[i].hash, sizeof(tests[i].hash), "BLAKE2B_384", i)) {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
483 return CRYPT_FAIL_TESTVECTOR;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
484 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
485 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
486 return CRYPT_OK;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
487 #endif
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
488 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
489
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
490 /**
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
491 Self-test the hash
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
492 @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
493 */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
494 int blake2b_256_test(void)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
495 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
496 #ifndef LTC_TEST
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
497 return CRYPT_NOP;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
498 #else
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
499 static const struct {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
500 const char *msg;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
501 unsigned char hash[32];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
502 } tests[] = {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
503 { "",
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
504 { 0x0e, 0x57, 0x51, 0xc0, 0x26, 0xe5, 0x43, 0xb2,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
505 0xe8, 0xab, 0x2e, 0xb0, 0x60, 0x99, 0xda, 0xa1,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
506 0xd1, 0xe5, 0xdf, 0x47, 0x77, 0x8f, 0x77, 0x87,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
507 0xfa, 0xab, 0x45, 0xcd, 0xf1, 0x2f, 0xe3, 0xa8 } },
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
508 { "abc",
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
509 { 0xbd, 0xdd, 0x81, 0x3c, 0x63, 0x42, 0x39, 0x72,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
510 0x31, 0x71, 0xef, 0x3f, 0xee, 0x98, 0x57, 0x9b,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
511 0x94, 0x96, 0x4e, 0x3b, 0xb1, 0xcb, 0x3e, 0x42,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
512 0x72, 0x62, 0xc8, 0xc0, 0x68, 0xd5, 0x23, 0x19 } },
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
513 { "12345678901234567890123456789012345678901234567890"
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
514 "12345678901234567890123456789012345678901234567890"
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
515 "12345678901234567890123456789012345678901234567890"
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
516 "12345678901234567890123456789012345678901234567890"
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
517 "12345678901234567890123456789012345678901234567890"
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
518 "12345678901234567890123456789012345678901234567890",
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
519 { 0x0f, 0x6e, 0x01, 0x8d, 0x38, 0xd6, 0x3f, 0x08,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
520 0x4d, 0x58, 0xe3, 0x0c, 0x90, 0xfb, 0xa2, 0x41,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
521 0x5f, 0xca, 0x17, 0xfa, 0x66, 0x26, 0x49, 0xf3,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
522 0x8a, 0x30, 0x41, 0x7c, 0x57, 0xcd, 0xa8, 0x14 } },
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
523
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
524 { NULL, { 0 } }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
525 };
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
526
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
527 int i;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
528 unsigned char tmp[32];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
529 hash_state md;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
530
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
531 for (i = 0; tests[i].msg != NULL; i++) {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
532 blake2b_256_init(&md);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
533 blake2b_process(&md, (unsigned char *)tests[i].msg, (unsigned long)strlen(tests[i].msg));
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
534 blake2b_done(&md, tmp);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
535 if (compare_testvector(tmp, sizeof(tmp), tests[i].hash, sizeof(tests[i].hash), "BLAKE2B_256", i)) {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
536 return CRYPT_FAIL_TESTVECTOR;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
537 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
538 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
539 return CRYPT_OK;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
540 #endif
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
541 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
542
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
543 /**
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
544 Self-test the hash
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
545 @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
546 */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
547 int blake2b_160_test(void)
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
548 {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
549 #ifndef LTC_TEST
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
550 return CRYPT_NOP;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
551 #else
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
552 static const struct {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
553 const char *msg;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
554 unsigned char hash[20];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
555 } tests[] = {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
556 { "",
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
557 { 0x33, 0x45, 0x52, 0x4a, 0xbf, 0x6b, 0xbe, 0x18,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
558 0x09, 0x44, 0x92, 0x24, 0xb5, 0x97, 0x2c, 0x41,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
559 0x79, 0x0b, 0x6c, 0xf2 } },
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
560 { "abc",
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
561 { 0x38, 0x42, 0x64, 0xf6, 0x76, 0xf3, 0x95, 0x36,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
562 0x84, 0x05, 0x23, 0xf2, 0x84, 0x92, 0x1c, 0xdc,
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
563 0x68, 0xb6, 0x84, 0x6b } },
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
564
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
565 { NULL, { 0 } }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
566 };
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
567
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
568 int i;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
569 unsigned char tmp[20];
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
570 hash_state md;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
571
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
572 for (i = 0; tests[i].msg != NULL; i++) {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
573 blake2b_160_init(&md);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
574 blake2b_process(&md, (unsigned char *)tests[i].msg, (unsigned long)strlen(tests[i].msg));
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
575 blake2b_done(&md, tmp);
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
576 if (compare_testvector(tmp, sizeof(tmp), tests[i].hash, sizeof(tests[i].hash), "BLAKE2B_160", i)) {
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
577 return CRYPT_FAIL_TESTVECTOR;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
578 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
579 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
580 return CRYPT_OK;
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
581 #endif
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
582 }
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
583
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
584 #endif
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
585
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
586 /* ref: $Format:%D$ */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
587 /* git commit: $Format:%H$ */
6dba84798cd5 Update to libtomcrypt 1.18.1, merged with Dropbear changes
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
588 /* commit time: $Format:%ai$ */