Skip to content

Commit dbb694b

Browse files
committed
update leancrypto support
Signed-off-by: Stephan Mueller <[email protected]>
1 parent 0f5eba1 commit dbb694b

22 files changed

+1599
-295
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ endif
333333

334334
ifeq (leancrypto,$(firstword $(MAKECMDGOALS)))
335335
C_SRCS += backends/backend_leancrypto.c
336+
INCLUDE_DIRS += backend_interfaces/leancrypto/
337+
ifeq ($(uname -m),x86_64)
338+
CFLAGS += -mavx2 -mbmi2 -mpopcnt
339+
endif
336340
LIBRARIES += leancrypto
337341
endif
338342

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (C) 2022, Stephan Mueller <[email protected]>
3+
*
4+
* License: see LICENSE file in root directory
5+
*
6+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
7+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
9+
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
10+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
11+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
12+
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
13+
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
14+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
16+
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
17+
* DAMAGE.
18+
*/
19+
20+
#ifndef SHA3_ARM8_NEON
21+
#define SHA3_ARM8_NEON
22+
23+
#ifdef __cplusplus
24+
extern "C"
25+
{
26+
#endif
27+
28+
extern const struct lc_hash *lc_sha3_224_arm8_neon;
29+
extern const struct lc_hash *lc_sha3_256_arm8_neon;
30+
extern const struct lc_hash *lc_sha3_384_arm8_neon;
31+
extern const struct lc_hash *lc_sha3_512_arm8_neon;
32+
33+
extern const struct lc_hash *lc_shake128_arm8_neon;
34+
extern const struct lc_hash *lc_shake256_arm8_neon;
35+
extern const struct lc_hash *lc_cshake128_arm8_neon;
36+
extern const struct lc_hash *lc_cshake256_arm8_neon;
37+
38+
#ifdef __cplusplus
39+
}
40+
#endif
41+
42+
#endif /* SHA3_ARM8_NEON */
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (C) 2022, Stephan Mueller <[email protected]>
3+
*
4+
* License: see LICENSE file in root directory
5+
*
6+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
7+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
9+
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
10+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
11+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
12+
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
13+
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
14+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
16+
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
17+
* DAMAGE.
18+
*/
19+
20+
#ifndef SHA3_AVX2
21+
#define SHA3_AVX2
22+
23+
#ifdef __cplusplus
24+
extern "C"
25+
{
26+
#endif
27+
28+
extern const struct lc_hash *lc_sha3_224_avx2;
29+
extern const struct lc_hash *lc_sha3_256_avx2;
30+
extern const struct lc_hash *lc_sha3_384_avx2;
31+
extern const struct lc_hash *lc_sha3_512_avx2;
32+
33+
extern const struct lc_hash *lc_shake128_avx2;
34+
extern const struct lc_hash *lc_shake256_avx2;
35+
extern const struct lc_hash *lc_cshake128_avx2;
36+
extern const struct lc_hash *lc_cshake256_avx2;
37+
38+
#ifdef __cplusplus
39+
}
40+
#endif
41+
42+
#endif /* SHA3_AVX2 */
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (C) 2022, Stephan Mueller <[email protected]>
3+
*
4+
* License: see LICENSE file in root directory
5+
*
6+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
7+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
9+
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
10+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
11+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
12+
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
13+
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
14+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
16+
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
17+
* DAMAGE.
18+
*/
19+
20+
#ifndef SHA3_AVX512
21+
#define SHA3_AVX512
22+
23+
#ifdef __cplusplus
24+
extern "C"
25+
{
26+
#endif
27+
28+
extern const struct lc_hash *lc_sha3_224_avx512;
29+
extern const struct lc_hash *lc_sha3_256_avx512;
30+
extern const struct lc_hash *lc_sha3_384_avx512;
31+
extern const struct lc_hash *lc_sha3_512_avx512;
32+
33+
extern const struct lc_hash *lc_shake128_avx512;
34+
extern const struct lc_hash *lc_shake256_avx512;
35+
extern const struct lc_hash *lc_cshake128_avx512;
36+
extern const struct lc_hash *lc_cshake256_avx512;
37+
38+
#ifdef __cplusplus
39+
}
40+
#endif
41+
42+
#endif /* SHA3_AVX512 */
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (C) 2022, Stephan Mueller <[email protected]>
3+
*
4+
* License: see LICENSE file in root directory
5+
*
6+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
7+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
9+
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
10+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
11+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
12+
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
13+
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
14+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
16+
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
17+
* DAMAGE.
18+
*/
19+
20+
#ifndef SHA3_C
21+
#define SHA3_C
22+
23+
#ifdef __cplusplus
24+
extern "C"
25+
{
26+
#endif
27+
28+
extern const struct lc_hash *lc_sha3_224_c;
29+
extern const struct lc_hash *lc_sha3_256_c;
30+
extern const struct lc_hash *lc_sha3_384_c;
31+
extern const struct lc_hash *lc_sha3_512_c;
32+
33+
extern const struct lc_hash *lc_shake128_c;
34+
extern const struct lc_hash *lc_shake256_c;
35+
extern const struct lc_hash *lc_cshake128_c;
36+
extern const struct lc_hash *lc_cshake256_c;
37+
38+
#ifdef __cplusplus
39+
}
40+
#endif
41+
42+
#endif /* SHA3_C */
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (C) 2022, Stephan Mueller <[email protected]>
3+
*
4+
* License: see LICENSE file in root directory
5+
*
6+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
7+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
9+
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
10+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
11+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
12+
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
13+
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
14+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
16+
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
17+
* DAMAGE.
18+
*/
19+
/*
20+
* This code is derived in parts from the code distribution provided with
21+
* https://github.com/pq-crystals/kyber
22+
*
23+
* That code is released under Public Domain
24+
* (https://creativecommons.org/share-your-work/public-domain/cc0/).
25+
*/
26+
27+
#ifndef SHAKE_4X_AVX2_H
28+
#define SHAKE_4X_AVX2_H
29+
30+
#include <stddef.h>
31+
#include <stdint.h>
32+
#include <immintrin.h>
33+
34+
#ifdef __cplusplus
35+
extern "C"
36+
{
37+
#endif
38+
39+
typedef struct {
40+
__m256i s[25];
41+
} keccakx4_state;
42+
43+
void shake128x4_absorb_once(keccakx4_state *state,
44+
const uint8_t *in0,
45+
const uint8_t *in1,
46+
const uint8_t *in2,
47+
const uint8_t *in3,
48+
size_t inlen);
49+
50+
void shake128x4_squeezeblocks(uint8_t *out0,
51+
uint8_t *out1,
52+
uint8_t *out2,
53+
uint8_t *out3,
54+
size_t nblocks,
55+
keccakx4_state *state);
56+
57+
void shake256x4_absorb_once(keccakx4_state *state,
58+
const uint8_t *in0,
59+
const uint8_t *in1,
60+
const uint8_t *in2,
61+
const uint8_t *in3,
62+
size_t inlen);
63+
64+
void shake256x4_squeezeblocks(uint8_t *out0,
65+
uint8_t *out1,
66+
uint8_t *out2,
67+
uint8_t *out3,
68+
size_t nblocks,
69+
keccakx4_state *state);
70+
71+
void shake128x4(uint8_t *out0,
72+
uint8_t *out1,
73+
uint8_t *out2,
74+
uint8_t *out3,
75+
size_t outlen,
76+
const uint8_t *in0,
77+
const uint8_t *in1,
78+
const uint8_t *in2,
79+
const uint8_t *in3,
80+
size_t inlen);
81+
82+
void shake256x4(uint8_t *out0,
83+
uint8_t *out1,
84+
uint8_t *out2,
85+
uint8_t *out3,
86+
size_t outlen,
87+
const uint8_t *in0,
88+
const uint8_t *in1,
89+
const uint8_t *in2,
90+
const uint8_t *in3,
91+
size_t inlen);
92+
93+
#ifdef __cplusplus
94+
}
95+
#endif
96+
97+
#endif /* SHAKE_4X_AVX2_H */

backends/backend_common.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
#include "parser_kdf_108.h"
4646
#include "parser_kdf_srtp.h"
4747
#include "parser_pbkdf.h"
48-
#include "parser_hkdf.h"
48+
#include "parser_kda_hkdf.h"
49+
#include "parser_kda_onestep.h"
50+
#include "parser_kda_twostep.h"
4951
#include "parser_rsa.h"
5052
#include "parser_sha.h"
5153
#include "parser_sym.h"

0 commit comments

Comments
 (0)