mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-15 10:33:42 +08:00
67 lines
2.1 KiB
C
67 lines
2.1 KiB
C
/*
|
|
* Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#ifndef GMSSL_SM4_LCL_H
|
|
#define GMSSL_SM4_LCL_H
|
|
|
|
#include <gmssl/sm4.h>
|
|
|
|
extern const uint8_t SM4_S[256];
|
|
extern const uint32_t SM4_T[256];
|
|
extern const uint32_t SM4_D[65536];
|
|
|
|
#define S32(A) \
|
|
((SM4_S[((A) >> 24) ] << 24) ^ \
|
|
(SM4_S[((A) >> 16) & 0xff] << 16) ^ \
|
|
(SM4_S[((A) >> 8) & 0xff] << 8) ^ \
|
|
(SM4_S[((A)) & 0xff]))
|
|
|
|
#define ROUNDS(x0, x1, x2, x3, x4) \
|
|
ROUND(x0, x1, x2, x3, x4, 0); \
|
|
ROUND(x1, x2, x3, x4, x0, 1); \
|
|
ROUND(x2, x3, x4, x0, x1, 2); \
|
|
ROUND(x3, x4, x0, x1, x2, 3); \
|
|
ROUND(x4, x0, x1, x2, x3, 4); \
|
|
ROUND(x0, x1, x2, x3, x4, 5); \
|
|
ROUND(x1, x2, x3, x4, x0, 6); \
|
|
ROUND(x2, x3, x4, x0, x1, 7); \
|
|
ROUND(x3, x4, x0, x1, x2, 8); \
|
|
ROUND(x4, x0, x1, x2, x3, 9); \
|
|
ROUND(x0, x1, x2, x3, x4, 10); \
|
|
ROUND(x1, x2, x3, x4, x0, 11); \
|
|
ROUND(x2, x3, x4, x0, x1, 12); \
|
|
ROUND(x3, x4, x0, x1, x2, 13); \
|
|
ROUND(x4, x0, x1, x2, x3, 14); \
|
|
ROUND(x0, x1, x2, x3, x4, 15); \
|
|
ROUND(x1, x2, x3, x4, x0, 16); \
|
|
ROUND(x2, x3, x4, x0, x1, 17); \
|
|
ROUND(x3, x4, x0, x1, x2, 18); \
|
|
ROUND(x4, x0, x1, x2, x3, 19); \
|
|
ROUND(x0, x1, x2, x3, x4, 20); \
|
|
ROUND(x1, x2, x3, x4, x0, 21); \
|
|
ROUND(x2, x3, x4, x0, x1, 22); \
|
|
ROUND(x3, x4, x0, x1, x2, 23); \
|
|
ROUND(x4, x0, x1, x2, x3, 24); \
|
|
ROUND(x0, x1, x2, x3, x4, 25); \
|
|
ROUND(x1, x2, x3, x4, x0, 26); \
|
|
ROUND(x2, x3, x4, x0, x1, 27); \
|
|
ROUND(x3, x4, x0, x1, x2, 28); \
|
|
ROUND(x4, x0, x1, x2, x3, 29); \
|
|
ROUND(x0, x1, x2, x3, x4, 30); \
|
|
ROUND(x1, x2, x3, x4, x0, 31)
|
|
|
|
#endif
|