xrootd
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 <stdint.h>
35 
37 {
38 public:
39 
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
43 
44 typedef struct {
45  union {
46  uint8_t b[200];
47  uint64_t q[25];
48  } st;
49  int pt, rsiz, mdlen, xof;
50 } sha3_ctx_t;
51 
52 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
55 
56 enum MDLen {SHA3_128 = 16,
57  SHA3_224 = 28,
58  SHA3_256 = 32,
59  SHA3_384 = 48,
60  SHA3_512 = 64
61  };
62 
63 //-----------------------------------------------------------------------------
72 //-----------------------------------------------------------------------------
73 
74 static void *Calc(const void *in, size_t inlen, void *md, MDLen mdlen);
75 
76 //-----------------------------------------------------------------------------
81 //-----------------------------------------------------------------------------
82 
83 static void Init(sha3_ctx_t *c, MDLen mdlen);
84 
85 //-----------------------------------------------------------------------------
91 //-----------------------------------------------------------------------------
92 
93 static void Update(sha3_ctx_t *c, const void *data, size_t len);
94 
95 //-----------------------------------------------------------------------------
100 //-----------------------------------------------------------------------------
101 
102 static void Final(sha3_ctx_t *c, void *md);
103 
104 //-----------------------------------------------------------------------------
108 //-----------------------------------------------------------------------------
109 
110 static void SHAKE128_Init(sha3_ctx_t *c) {Init(c, SHA3_128);}
111 
112 //-----------------------------------------------------------------------------
116 //-----------------------------------------------------------------------------
117 
118 static void SHAKE256_Init(sha3_ctx_t *c) {Init(c, SHA3_256);}
119 
120 //-----------------------------------------------------------------------------
126 //-----------------------------------------------------------------------------
127 
128 static void SHAKE_Update(sha3_ctx_t *c, const void *data, size_t len)
129  {Update(c, data, len);}
130 
131 //-----------------------------------------------------------------------------
139 //-----------------------------------------------------------------------------
140 
141 static void SHAKE_Out(sha3_ctx_t *c, void *out, size_t len);
142 
145 
146 private:
147 
148 // Compression function.
149 static void shake_xof(sha3_ctx_t *c);
150 static void sha3_keccakf(uint64_t st[25]);
151 };
152 #endif
153 
static void SHAKE256_Init(sha3_ctx_t *c)
Definition: XrdOucSHA3.hh:118
Definition: XrdOucSHA3.hh:59
Definition: XrdOucSHA3.hh:58
SHA3 state context used by all methods (OpenSSL - like interface)
Definition: XrdOucSHA3.hh:44
static void Final(sha3_ctx_t *c, void *md)
static void * Calc(const void *in, size_t inlen, void *md, MDLen mdlen)
Definition: XrdOucSHA3.hh:36
static void Update(sha3_ctx_t *c, const void *data, size_t len)
static void shake_xof(sha3_ctx_t *c)
Definition: XrdOucSHA3.hh:60
int xof
these don&#39;t overflow
Definition: XrdOucSHA3.hh:49
static void Init(sha3_ctx_t *c, MDLen mdlen)
static void sha3_keccakf(uint64_t st[25])
Definition: XrdOucSHA3.hh:56
~XrdOucSHA3()
Definition: XrdOucSHA3.hh:144
static void SHAKE_Update(sha3_ctx_t *c, const void *data, size_t len)
Definition: XrdOucSHA3.hh:128
static void SHAKE_Out(sha3_ctx_t *c, void *out, size_t len)
MDLen
SHA3 digest lengths (bits to bytes).
Definition: XrdOucSHA3.hh:56
XrdOucSHA3()
Definition: XrdOucSHA3.hh:143
Definition: XrdOucSHA3.hh:57
static void SHAKE128_Init(sha3_ctx_t *c)
Definition: XrdOucSHA3.hh:110