1 /* This file is in the public domain. */
6 #include <contrib/libb2/blake2.h>
7 #include <opencrypto/xform_auth.h>
9 extern int blake2b_init_ref(blake2b_state *S, size_t outlen);
10 extern int blake2b_init_param_ref(blake2b_state *S, const blake2b_param *P);
11 extern int blake2b_init_key_ref(blake2b_state *S, size_t outlen,
12 const void *key, size_t keylen);
13 extern int blake2b_update_ref(blake2b_state *S, const uint8_t *in,
15 extern int blake2b_final_ref(blake2b_state *S, uint8_t *out, size_t outlen);
16 extern int blake2b_ref(uint8_t *out, const void *in, const void *key,
17 size_t outlen, size_t inlen, size_t keylen);
19 extern int blake2s_init_ref(blake2s_state *S, size_t outlen);
20 extern int blake2s_init_param_ref(blake2s_state *S, const blake2s_param *P);
21 extern int blake2s_init_key_ref(blake2s_state *S, size_t outlen,
22 const void *key, size_t keylen);
23 extern int blake2s_update_ref(blake2s_state *S, const uint8_t *in,
25 extern int blake2s_final_ref(blake2s_state *S, uint8_t *out, size_t outlen);
26 extern int blake2s_ref(uint8_t *out, const void *in, const void *key,
27 size_t outlen, size_t inlen, size_t keylen);
29 struct blake2b_xform_ctx {
32 CTASSERT(sizeof(union authctx) >= sizeof(struct blake2b_xform_ctx));
35 blake2b_xform_init(void *vctx)
37 struct blake2b_xform_ctx *ctx = vctx;
40 rc = blake2b_init_ref(&ctx->state, BLAKE2B_OUTBYTES);
42 panic("blake2b_init: invalid arguments");
46 blake2b_xform_setkey(void *vctx, const uint8_t *key, u_int klen)
48 struct blake2b_xform_ctx *ctx = vctx;
51 rc = blake2b_init_key_ref(&ctx->state, BLAKE2B_OUTBYTES, key,
54 panic("blake2b_init_key: invalid arguments");
58 blake2b_xform_update(void *vctx, const void *data, u_int len)
60 struct blake2b_xform_ctx *ctx = vctx;
63 rc = blake2b_update_ref(&ctx->state, data, len);
70 blake2b_xform_final(uint8_t *out, void *vctx)
72 struct blake2b_xform_ctx *ctx = vctx;
75 rc = blake2b_final_ref(&ctx->state, out, BLAKE2B_OUTBYTES);
77 panic("blake2b_final: invalid");
80 const struct auth_hash auth_hash_blake2b = {
81 .type = CRYPTO_BLAKE2B,
83 .keysize = BLAKE2B_KEYBYTES,
84 .hashsize = BLAKE2B_OUTBYTES,
85 .ctxsize = sizeof(struct blake2b_xform_ctx),
86 .Setkey = blake2b_xform_setkey,
87 .Init = blake2b_xform_init,
88 .Update = blake2b_xform_update,
89 .Final = blake2b_xform_final,
92 struct blake2s_xform_ctx {
95 CTASSERT(sizeof(union authctx) >= sizeof(struct blake2s_xform_ctx));
98 blake2s_xform_init(void *vctx)
100 struct blake2s_xform_ctx *ctx = vctx;
103 rc = blake2s_init_ref(&ctx->state, BLAKE2S_OUTBYTES);
105 panic("blake2s_init: invalid arguments");
109 blake2s_xform_setkey(void *vctx, const uint8_t *key, u_int klen)
111 struct blake2s_xform_ctx *ctx = vctx;
114 rc = blake2s_init_key_ref(&ctx->state, BLAKE2S_OUTBYTES, key,
117 panic("blake2s_init_key: invalid arguments");
121 blake2s_xform_update(void *vctx, const void *data, u_int len)
123 struct blake2s_xform_ctx *ctx = vctx;
126 rc = blake2s_update_ref(&ctx->state, data, len);
133 blake2s_xform_final(uint8_t *out, void *vctx)
135 struct blake2s_xform_ctx *ctx = vctx;
138 rc = blake2s_final_ref(&ctx->state, out, BLAKE2S_OUTBYTES);
140 panic("blake2s_final: invalid");
143 const struct auth_hash auth_hash_blake2s = {
144 .type = CRYPTO_BLAKE2S,
146 .keysize = BLAKE2S_KEYBYTES,
147 .hashsize = BLAKE2S_OUTBYTES,
148 .ctxsize = sizeof(struct blake2s_xform_ctx),
149 .Setkey = blake2s_xform_setkey,
150 .Init = blake2s_xform_init,
151 .Update = blake2s_xform_update,
152 .Final = blake2s_xform_final,