xrootd
Loading...
Searching...
No Matches
XrdOucSHA3.hh
Go to the documentation of this file.
1#ifndef XRDOUCSHA3_HH
2#define XRDOUCSHA3_HH
3/******************************************************************************/
4/* */
5/* X r d O u c S H A 3 . h h */
6/* */
7/* The MIT License (MIT) */
8/* */
9/* Copyright (c) 2015 Markku-Juhani O. Saarinen */
10/* Contact: 19-Nov-11 Markku-Juhani O. Saarinen <mjos@iki.fi> */
11/* Reprository: https://github.com/mjosaarinen/tiny_sha3.git */
12/* Original: tiny_sha3/sha3.h */
13/* */
14/* Permission is hereby granted, free of charge, to any person obtaining a */
15/* copy of this software and associated documentation files (the "Software"), */
16/* to deal in the Software without restriction, including without limitation */
17/* the rights to use, copy, modify, merge, publish, distribute, sublicense, */
18/* and/or sell copies of the Software, and to permit persons to whom the */
19/* Software is furnished to do so, subject to the following conditions: */
20/* */
21/* The above copyright notice and this permission notice shall be included */
22/* in all copies or substantial portions of the Software. */
23/* */
24/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
25/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
26/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL */
27/* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
28/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
29/* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */
30/* DEALINGS IN THE SOFTWARE. */
31/******************************************************************************/
32
33#include <stddef.h>
34#include <cstdint>
35
37{
38public:
39
40//-----------------------------------------------------------------------------
42//-----------------------------------------------------------------------------
43
44typedef struct {
45 union {
46 uint8_t b[200];
47 uint64_t q[25];
48 } st;
49 int pt, rsiz, mdlen, xof;
51
52//-----------------------------------------------------------------------------
54//-----------------------------------------------------------------------------
55
56enum MDLen {SHA3_128 = 16,
60 SHA3_512 = 64
61 };
62
63//-----------------------------------------------------------------------------
72//-----------------------------------------------------------------------------
73
74static void *Calc(const void *in, size_t inlen, void *md, MDLen mdlen);
75
76//-----------------------------------------------------------------------------
81//-----------------------------------------------------------------------------
82
83static void Init(sha3_ctx_t *c, MDLen mdlen);
84
85//-----------------------------------------------------------------------------
91//-----------------------------------------------------------------------------
92
93static void Update(sha3_ctx_t *c, const void *data, size_t len);
94
95//-----------------------------------------------------------------------------
100//-----------------------------------------------------------------------------
101
102static void Final(sha3_ctx_t *c, void *md);
103
104//-----------------------------------------------------------------------------
108//-----------------------------------------------------------------------------
109
110static void SHAKE128_Init(sha3_ctx_t *c) {Init(c, SHA3_128);}
111
112//-----------------------------------------------------------------------------
116//-----------------------------------------------------------------------------
117
118static void SHAKE256_Init(sha3_ctx_t *c) {Init(c, SHA3_256);}
119
120//-----------------------------------------------------------------------------
126//-----------------------------------------------------------------------------
127
128static void SHAKE_Update(sha3_ctx_t *c, const void *data, size_t len)
129 {Update(c, data, len);}
130
131//-----------------------------------------------------------------------------
139//-----------------------------------------------------------------------------
140
141static void SHAKE_Out(sha3_ctx_t *c, void *out, size_t len);
142
145
146private:
147
148// Compression function.
149static void shake_xof(sha3_ctx_t *c);
150static void sha3_keccakf(uint64_t st[25]);
151};
152#endif
153
Definition XrdOucSHA3.hh:37
static void Init(sha3_ctx_t *c, MDLen mdlen)
static void sha3_keccakf(uint64_t st[25])
static void SHAKE_Update(sha3_ctx_t *c, const void *data, size_t len)
Definition XrdOucSHA3.hh:128
~XrdOucSHA3()
Definition XrdOucSHA3.hh:144
static void SHAKE_Out(sha3_ctx_t *c, void *out, size_t len)
static void Update(sha3_ctx_t *c, const void *data, size_t len)
MDLen
SHA3 digest lengths (bits to bytes).
Definition XrdOucSHA3.hh:56
@ SHA3_384
Definition XrdOucSHA3.hh:59
@ SHA3_256
Definition XrdOucSHA3.hh:58
@ SHA3_224
Definition XrdOucSHA3.hh:57
@ SHA3_128
Definition XrdOucSHA3.hh:56
@ SHA3_512
Definition XrdOucSHA3.hh:60
XrdOucSHA3()
Definition XrdOucSHA3.hh:143
static void Final(sha3_ctx_t *c, void *md)
static void SHAKE128_Init(sha3_ctx_t *c)
Definition XrdOucSHA3.hh:110
static void shake_xof(sha3_ctx_t *c)
static void SHAKE256_Init(sha3_ctx_t *c)
Definition XrdOucSHA3.hh:118
static void * Calc(const void *in, size_t inlen, void *md, MDLen mdlen)
SHA3 state context used by all methods (OpenSSL - like interface)
Definition XrdOucSHA3.hh:44
int mdlen
Definition XrdOucSHA3.hh:49