mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 14:27:37 +08:00
crypto:convert code style form openbsd to nuttx
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
+23
-18
@@ -1,5 +1,7 @@
|
||||
/* $OpenBSD: aes.h,v 1.4 2020/07/22 13:54:30 tobhe Exp $ */
|
||||
/*
|
||||
/****************************************************************************
|
||||
* include/crypto/aes.h
|
||||
* $OpenBSD: aes.h,v 1.4 2020/07/22 13:54:30 tobhe Exp $
|
||||
*
|
||||
* Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
|
||||
* Copyright (c) 2016 Mike Belopuhov
|
||||
*
|
||||
@@ -22,29 +24,32 @@
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _AES_H_
|
||||
#define _AES_H_
|
||||
#ifndef __INCLUDE_CRYPTO_AES_H
|
||||
#define __INCLUDE_CRYPTO_AES_H
|
||||
|
||||
#ifndef AES_MAXROUNDS
|
||||
#define AES_MAXROUNDS (14)
|
||||
# define AES_MAXROUNDS (14)
|
||||
#endif
|
||||
|
||||
typedef struct aes_ctx {
|
||||
uint32_t sk[60];
|
||||
uint32_t sk_exp[120];
|
||||
typedef struct aes_ctx
|
||||
{
|
||||
uint32_t sk[60];
|
||||
uint32_t sk_exp[120];
|
||||
|
||||
unsigned num_rounds;
|
||||
unsigned num_rounds;
|
||||
} AES_CTX;
|
||||
|
||||
int AES_Setkey(AES_CTX *, const uint8_t *, int);
|
||||
void AES_Encrypt(AES_CTX *, const uint8_t *, uint8_t *);
|
||||
void AES_Decrypt(AES_CTX *, const uint8_t *, uint8_t *);
|
||||
void AES_Encrypt_ECB(AES_CTX *, const uint8_t *, uint8_t *, size_t);
|
||||
void AES_Decrypt_ECB(AES_CTX *, const uint8_t *, uint8_t *, size_t);
|
||||
int aes_setkey(FAR AES_CTX *, FAR const uint8_t *, int);
|
||||
void aes_encrypt(FAR AES_CTX *, FAR const uint8_t *, FAR uint8_t *);
|
||||
void aes_decrypt(FAR AES_CTX *, FAR const uint8_t *, FAR uint8_t *);
|
||||
void aes_encrypt_ecb(FAR AES_CTX *, FAR const uint8_t *, FAR uint8_t *,
|
||||
size_t);
|
||||
void aes_decrypt_ecb(FAR AES_CTX *, FAR const uint8_t *, FAR uint8_t *,
|
||||
size_t);
|
||||
|
||||
int AES_KeySetup_Encrypt(uint32_t *, const uint8_t *, int);
|
||||
int AES_KeySetup_Decrypt(uint32_t *, const uint8_t *, int);
|
||||
int aes_keysetup_encrypt(FAR uint32_t *, FAR const uint8_t *, int);
|
||||
int aes_keysetup_decrypt(FAR uint32_t *, FAR const uint8_t *, int);
|
||||
|
||||
#endif /* _AES_H_ */
|
||||
#endif /* __INCLUDE_CRYPTO_AES_H */
|
||||
|
||||
+40
-32
@@ -1,6 +1,7 @@
|
||||
/* $OpenBSD: blf.h,v 1.7 2021/11/29 01:04:45 djm Exp $ */
|
||||
|
||||
/*
|
||||
/****************************************************************************
|
||||
* include/crypto/blf.h
|
||||
* $OpenBSD: blf.h,v 1.7 2021/11/29 01:04:45 djm Exp $
|
||||
*
|
||||
* Blowfish - a fast block cipher designed by Bruce Schneier
|
||||
*
|
||||
* Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
|
||||
@@ -27,10 +28,10 @@
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _BLF_H_
|
||||
#define _BLF_H_
|
||||
#ifndef __INCLUDE_CRYPTO_BLF_H
|
||||
#define __INCLUDE_CRYPTO_BLF_H
|
||||
|
||||
/* Schneier states the maximum key length to be 56 bytes.
|
||||
* The way how the subkeys are initialized by the key up
|
||||
@@ -39,41 +40,48 @@
|
||||
* of the key affect all cipherbits.
|
||||
*/
|
||||
|
||||
#define BLF_N 16 /* Number of Subkeys */
|
||||
#define BLF_MAXKEYLEN ((BLF_N-2)*4) /* 448 bits */
|
||||
#define BLF_MAXUTILIZED ((BLF_N+2)*4) /* 576 bits */
|
||||
#define BLF_N 16 /* Number of Subkeys */
|
||||
#define BLF_MAXKEYLEN ((BLF_N - 2) * 4) /* 448 bits */
|
||||
#define BLF_MAXUTILIZED ((BLF_N + 2) * 4) /* 576 bits */
|
||||
|
||||
/* Blowfish context */
|
||||
typedef struct BlowfishContext {
|
||||
u_int32_t S[4][256]; /* S-Boxes */
|
||||
u_int32_t P[BLF_N + 2]; /* Subkeys */
|
||||
} blf_ctx;
|
||||
|
||||
typedef struct blowfishcontext
|
||||
{
|
||||
uint32_t S[4][256]; /* S-Boxes */
|
||||
uint32_t P[BLF_N + 2]; /* Subkeys */
|
||||
}
|
||||
blf_ctx;
|
||||
|
||||
/* Raw access to customized Blowfish
|
||||
* blf_key is just:
|
||||
* Blowfish_initstate( state )
|
||||
* Blowfish_expand0state( state, key, keylen )
|
||||
* blf_key is just:
|
||||
* Blowfish_initstate( state )
|
||||
* Blowfish_expand0state( state, key, keylen )
|
||||
*/
|
||||
|
||||
void Blowfish_encipher(blf_ctx *, u_int32_t *);
|
||||
void Blowfish_decipher(blf_ctx *, u_int32_t *);
|
||||
void Blowfish_initstate(blf_ctx *);
|
||||
void Blowfish_expand0state(blf_ctx *, const u_int8_t *, u_int16_t);
|
||||
void Blowfish_expandstate(blf_ctx *, const u_int8_t *, u_int16_t, const u_int8_t *, u_int16_t);
|
||||
void blowfish_encipher(FAR blf_ctx *, FAR uint32_t *);
|
||||
void blowfish_decipher(FAR blf_ctx *, FAR uint32_t *);
|
||||
void blowfish_initstate(FAR blf_ctx *);
|
||||
void blowfish_expand0state(FAR blf_ctx *, FAR const uint8_t *, uint16_t);
|
||||
void blowfish_expandstate(FAR blf_ctx *, FAR const uint8_t *,
|
||||
uint16_t, FAR const uint8_t *, uint16_t);
|
||||
|
||||
/* Standard Blowfish */
|
||||
|
||||
void blf_key(blf_ctx *, const u_int8_t *, u_int16_t);
|
||||
void blf_enc(blf_ctx *, u_int32_t *, u_int16_t);
|
||||
void blf_dec(blf_ctx *, u_int32_t *, u_int16_t);
|
||||
void blf_key(FAR blf_ctx *, FAR const uint8_t *, uint16_t);
|
||||
void blf_enc(FAR blf_ctx *, FAR uint32_t *, uint16_t);
|
||||
void blf_dec(FAR blf_ctx *, FAR uint32_t *, uint16_t);
|
||||
|
||||
/* Converts u_int8_t to u_int32_t */
|
||||
u_int32_t Blowfish_stream2word(const u_int8_t *, u_int16_t ,
|
||||
u_int16_t *);
|
||||
/* Converts uint8_t to uint32_t */
|
||||
|
||||
void blf_ecb_encrypt(blf_ctx *, u_int8_t *, u_int32_t);
|
||||
void blf_ecb_decrypt(blf_ctx *, u_int8_t *, u_int32_t);
|
||||
uint32_t blowfish_stream2word(FAR const uint8_t *, uint16_t,
|
||||
FAR uint16_t *);
|
||||
|
||||
void blf_cbc_encrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t);
|
||||
void blf_cbc_decrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t);
|
||||
#endif
|
||||
void blf_ecb_encrypt(FAR blf_ctx *, FAR uint8_t *, uint32_t);
|
||||
void blf_ecb_decrypt(FAR blf_ctx *, FAR uint8_t *, uint32_t);
|
||||
|
||||
void blf_cbc_encrypt(FAR blf_ctx *, FAR uint8_t *, FAR uint8_t *,
|
||||
uint32_t);
|
||||
void blf_cbc_decrypt(FAR blf_ctx *, FAR uint8_t *, FAR uint8_t *,
|
||||
uint32_t);
|
||||
#endif /* __INCLUDE_CRYPTO_BLF_H */
|
||||
|
||||
+23
-17
@@ -1,22 +1,28 @@
|
||||
/* $OpenBSD: cast.h,v 1.2 2002/03/14 01:26:51 millert Exp $ */
|
||||
/****************************************************************************
|
||||
* include/crypto/cast.h
|
||||
* $OpenBSD: cast.h,v 1.2 2002/03/14 01:26:51 millert Exp $
|
||||
*
|
||||
* CAST-128 in C
|
||||
* Written by Steve Reid <sreid@sea-to-sky.net>
|
||||
* 100% Public Domain - no warranty
|
||||
* Released 1997.10.11
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* CAST-128 in C
|
||||
* Written by Steve Reid <sreid@sea-to-sky.net>
|
||||
* 100% Public Domain - no warranty
|
||||
* Released 1997.10.11
|
||||
*/
|
||||
#ifndef __INCLUDE_CRYPTO_CAST_H
|
||||
#define __INCLUDE_CRYPTO_CAST_H
|
||||
|
||||
#ifndef _CAST_H_
|
||||
#define _CAST_H_
|
||||
|
||||
typedef struct {
|
||||
u_int32_t xkey[32]; /* Key, after expansion */
|
||||
int rounds; /* Number of rounds to use, 12 or 16 */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t xkey[32]; /* Key, after expansion */
|
||||
int rounds; /* Number of rounds to use, 12 or 16 */
|
||||
} cast_key;
|
||||
|
||||
void cast_setkey(cast_key * key, u_int8_t * rawkey, int keybytes);
|
||||
void cast_encrypt(cast_key * key, u_int8_t * inblock, u_int8_t * outblock);
|
||||
void cast_decrypt(cast_key * key, u_int8_t * inblock, u_int8_t * outblock);
|
||||
void cast_setkey(FAR cast_key *key, FAR uint8_t *rawkey, int keybytes);
|
||||
void cast_encrypt(FAR cast_key *key,
|
||||
FAR uint8_t *inblock,
|
||||
FAR uint8_t *outblock);
|
||||
void cast_decrypt(FAR cast_key *key,
|
||||
FAR uint8_t *inblock,
|
||||
FAR uint8_t *outblock);
|
||||
|
||||
#endif /* ifndef _CAST_H_ */
|
||||
#endif /* __INCLUDE_CRYPTO_CAST_H */
|
||||
|
||||
+67
-55
@@ -1,5 +1,6 @@
|
||||
/* $OpenBSD: chachapoly.h,v 1.4 2020/07/22 13:54:30 tobhe Exp $ */
|
||||
/*
|
||||
/****************************************************************************
|
||||
* include/crypto/chachapoly.h
|
||||
* $OpenBSD: chachapoly.h,v 1.4 2020/07/22 13:54:30 tobhe Exp $
|
||||
* Copyright (c) 2015 Mike Belopuhov
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
@@ -13,74 +14,85 @@
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _CHACHAPOLY_H_
|
||||
#define _CHACHAPOLY_H_
|
||||
#ifndef __INCLUDE_CRYPTO_CHACHAPOLY_H
|
||||
#define __INCLUDE_CRYPTO_CHACHAPOLY_H
|
||||
|
||||
#define CHACHA20_KEYSIZE 32
|
||||
#define CHACHA20_CTR 4
|
||||
#define CHACHA20_SALT 4
|
||||
#define CHACHA20_NONCE 8
|
||||
#define CHACHA20_BLOCK_LEN 64
|
||||
#define CHACHA20_KEYSIZE 32
|
||||
#define CHACHA20_CTR 4
|
||||
#define CHACHA20_SALT 4
|
||||
#define CHACHA20_NONCE 8
|
||||
#define CHACHA20_BLOCK_LEN 64
|
||||
|
||||
struct chacha20_ctx {
|
||||
uint8_t block[CHACHA20_BLOCK_LEN];
|
||||
uint8_t nonce[CHACHA20_NONCE];
|
||||
struct chacha20_ctx
|
||||
{
|
||||
uint8_t block[CHACHA20_BLOCK_LEN];
|
||||
uint8_t nonce[CHACHA20_NONCE];
|
||||
};
|
||||
|
||||
int chacha20_setkey(void *, u_int8_t *, int);
|
||||
void chacha20_reinit(caddr_t, u_int8_t *);
|
||||
void chacha20_crypt(caddr_t, u_int8_t *);
|
||||
int chacha20_setkey(FAR void *, FAR uint8_t *, int);
|
||||
void chacha20_reinit(caddr_t, FAR uint8_t *);
|
||||
void chacha20_crypt(caddr_t, FAR uint8_t *);
|
||||
|
||||
#define POLY1305_KEYLEN 32
|
||||
#define POLY1305_TAGLEN 16
|
||||
#define POLY1305_BLOCK_LEN 16
|
||||
|
||||
#define POLY1305_KEYLEN 32
|
||||
#define POLY1305_TAGLEN 16
|
||||
#define POLY1305_BLOCK_LEN 16
|
||||
struct poly1305_ctx
|
||||
{
|
||||
/* r, h, pad, leftover */
|
||||
|
||||
struct poly1305_ctx {
|
||||
/* r, h, pad, leftover */
|
||||
unsigned long state[5+5+4];
|
||||
size_t leftover;
|
||||
unsigned char buffer[POLY1305_BLOCK_LEN];
|
||||
unsigned char final;
|
||||
unsigned long state[5 + 5 + 4];
|
||||
size_t leftover;
|
||||
unsigned char buffer[POLY1305_BLOCK_LEN];
|
||||
unsigned char final;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t key[POLY1305_KEYLEN];
|
||||
/* counter, salt */
|
||||
uint8_t nonce[CHACHA20_NONCE];
|
||||
struct chacha20_ctx chacha;
|
||||
struct poly1305_ctx poly;
|
||||
} CHACHA20_POLY1305_CTX;
|
||||
typedef struct
|
||||
{
|
||||
uint8_t key[POLY1305_KEYLEN];
|
||||
|
||||
void Chacha20_Poly1305_Init(void *);
|
||||
void Chacha20_Poly1305_Setkey(void *, const uint8_t *, uint16_t);
|
||||
void Chacha20_Poly1305_Reinit(void *, const uint8_t *, uint16_t);
|
||||
int Chacha20_Poly1305_Update(void *, const uint8_t *, uint16_t);
|
||||
void Chacha20_Poly1305_Final(uint8_t[POLY1305_TAGLEN], void *);
|
||||
/* counter, salt */
|
||||
|
||||
uint8_t nonce[CHACHA20_NONCE];
|
||||
struct chacha20_ctx chacha;
|
||||
struct poly1305_ctx poly;
|
||||
}
|
||||
CHACHA20_POLY1305_CTX;
|
||||
|
||||
void chacha20_poly1305_init(FAR void *);
|
||||
void chacha20_poly1305_setkey(FAR void *, FAR const uint8_t *, uint16_t);
|
||||
void chacha20_poly1305_reinit(FAR void *, FAR const uint8_t *, uint16_t);
|
||||
int chacha20_poly1305_update(FAR void *, FAR const uint8_t *, uint16_t);
|
||||
void chacha20_poly1305_final(FAR uint8_t *, FAR void *);
|
||||
|
||||
/* WireGuard crypto */
|
||||
#define CHACHA20POLY1305_KEY_SIZE CHACHA20_KEYSIZE
|
||||
#define CHACHA20POLY1305_AUTHTAG_SIZE POLY1305_TAGLEN
|
||||
#define XCHACHA20POLY1305_NONCE_SIZE 24
|
||||
|
||||
void chacha20poly1305_encrypt(uint8_t *, const uint8_t *, const size_t,
|
||||
const uint8_t *, const size_t, const uint64_t,
|
||||
const uint8_t[CHACHA20POLY1305_KEY_SIZE]);
|
||||
#define CHACHA20POLY1305_KEY_SIZE CHACHA20_KEYSIZE
|
||||
#define CHACHA20POLY1305_AUTHTAG_SIZE POLY1305_TAGLEN
|
||||
#define XCHACHA20POLY1305_NONCE_SIZE 24
|
||||
|
||||
int chacha20poly1305_decrypt(uint8_t *, const uint8_t *, const size_t,
|
||||
const uint8_t *, const size_t, const uint64_t,
|
||||
const uint8_t[CHACHA20POLY1305_KEY_SIZE]);
|
||||
void chacha20poly1305_encrypt(
|
||||
FAR uint8_t *, FAR const uint8_t *, const size_t,
|
||||
FAR const uint8_t *, const size_t, const uint64_t,
|
||||
FAR const uint8_t *);
|
||||
|
||||
void xchacha20poly1305_encrypt(uint8_t *, const uint8_t *, const size_t,
|
||||
const uint8_t *, const size_t,
|
||||
const uint8_t[XCHACHA20POLY1305_NONCE_SIZE],
|
||||
const uint8_t[CHACHA20POLY1305_KEY_SIZE]);
|
||||
int chacha20poly1305_decrypt(
|
||||
FAR uint8_t *, FAR const uint8_t *, const size_t,
|
||||
FAR const uint8_t *, const size_t, const uint64_t,
|
||||
FAR const uint8_t *);
|
||||
|
||||
int xchacha20poly1305_decrypt(uint8_t *, const uint8_t *, const size_t,
|
||||
const uint8_t *, const size_t,
|
||||
const uint8_t[XCHACHA20POLY1305_NONCE_SIZE],
|
||||
const uint8_t[CHACHA20POLY1305_KEY_SIZE]);
|
||||
void xchacha20poly1305_encrypt(
|
||||
FAR uint8_t *, FAR const uint8_t *, const size_t,
|
||||
FAR const uint8_t *, const size_t,
|
||||
FAR const uint8_t *,
|
||||
FAR const uint8_t *);
|
||||
|
||||
#endif /* _CHACHAPOLY_H_ */
|
||||
int xchacha20poly1305_decrypt(
|
||||
FAR uint8_t *, FAR const uint8_t *, const size_t,
|
||||
FAR const uint8_t *, const size_t,
|
||||
FAR const uint8_t *,
|
||||
FAR const uint8_t *);
|
||||
|
||||
#endif /* __INCLUDE_CRYPTO_CHACHAPOLY_H */
|
||||
|
||||
+19
-20
@@ -1,6 +1,7 @@
|
||||
/* $OpenBSD: cmac.h,v 1.3 2017/05/02 17:07:06 mikeb Exp $ */
|
||||
|
||||
/*-
|
||||
/****************************************************************************
|
||||
* include/crypto/cmac.h
|
||||
* $OpenBSD: cmac.h,v 1.3 2017/05/02 17:07:06 mikeb Exp $
|
||||
*
|
||||
* Copyright (c) 2008 Damien Bergamini <damien.bergamini@free.fr>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
@@ -14,28 +15,26 @@
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _CMAC_H_
|
||||
#define _CMAC_H_
|
||||
#ifndef __INCLUDE_CRYPTO_CMAC_H_
|
||||
#define __INCLUDE_CRYPTO_CMAC_H_
|
||||
|
||||
#define AES_CMAC_KEY_LENGTH 16
|
||||
#define AES_CMAC_DIGEST_LENGTH 16
|
||||
|
||||
typedef struct _AES_CMAC_CTX {
|
||||
AES_CTX aesctx;
|
||||
u_int8_t X[16];
|
||||
u_int8_t M_last[16];
|
||||
u_int M_n;
|
||||
typedef struct _AES_CMAC_CTX
|
||||
{
|
||||
AES_CTX aesctx;
|
||||
u_int8_t X[16];
|
||||
u_int8_t m_last[16];
|
||||
u_int m_n;
|
||||
} AES_CMAC_CTX;
|
||||
|
||||
__BEGIN_DECLS
|
||||
void AES_CMAC_Init(AES_CMAC_CTX *);
|
||||
void AES_CMAC_SetKey(AES_CMAC_CTX *, const u_int8_t [AES_CMAC_KEY_LENGTH]);
|
||||
void AES_CMAC_Update(AES_CMAC_CTX *, const u_int8_t *, u_int)
|
||||
__attribute__((__bounded__(__string__,2,3)));
|
||||
void AES_CMAC_Final(u_int8_t [AES_CMAC_DIGEST_LENGTH], AES_CMAC_CTX *)
|
||||
__attribute__((__bounded__(__minbytes__,1,AES_CMAC_DIGEST_LENGTH)));
|
||||
__END_DECLS
|
||||
void aes_cmac_init(FAR AES_CMAC_CTX *);
|
||||
void aes_cmac_setkey(FAR AES_CMAC_CTX *, FAR const u_int8_t *);
|
||||
void aes_cmac_update(FAR AES_CMAC_CTX *, FAR const u_int8_t *, u_int);
|
||||
void aes_cmac_final(FAR u_int8_t *, FAR AES_CMAC_CTX *);
|
||||
|
||||
#endif /* _CMAC_H_ */
|
||||
#endif /* __INCLUDE_CRYPTO_CMAC_H_ */
|
||||
|
||||
+239
-217
File diff suppressed because it is too large
Load Diff
+61
-45
@@ -1,6 +1,7 @@
|
||||
/* $OpenBSD: cryptosoft.h,v 1.14 2012/12/07 17:03:22 mikeb Exp $ */
|
||||
|
||||
/*
|
||||
/****************************************************************************
|
||||
* include/crypto/cryptosoft.h
|
||||
* $OpenBSD: cryptosoft.h,v 1.14 2012/12/07 17:03:22 mikeb Exp $
|
||||
*
|
||||
* The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
|
||||
*
|
||||
* This code was written by Angelos D. Keromytis in Athens, Greece, in
|
||||
@@ -19,56 +20,71 @@
|
||||
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
|
||||
* MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
|
||||
* PURPOSE.
|
||||
*/
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _CRYPTO_CRYPTOSOFT_H_
|
||||
#define _CRYPTO_CRYPTOSOFT_H_
|
||||
#ifndef __INCLUDE_CRYPTO_CRYPTOSOFT_H
|
||||
#define __INCLUDE_CRYPTO_CRYPTOSOFT_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
/* Software session entry */
|
||||
struct swcr_data {
|
||||
int sw_alg; /* Algorithm */
|
||||
union {
|
||||
struct {
|
||||
u_int8_t *SW_ictx;
|
||||
u_int8_t *SW_octx;
|
||||
u_int32_t SW_klen;
|
||||
const struct auth_hash *SW_axf;
|
||||
} SWCR_AUTH;
|
||||
struct {
|
||||
u_int8_t *SW_kschedule;
|
||||
const struct enc_xform *SW_exf;
|
||||
} SWCR_ENC;
|
||||
struct {
|
||||
u_int32_t SW_size;
|
||||
const struct comp_algo *SW_cxf;
|
||||
} SWCR_COMP;
|
||||
} SWCR_UN;
|
||||
|
||||
#define sw_ictx SWCR_UN.SWCR_AUTH.SW_ictx
|
||||
#define sw_octx SWCR_UN.SWCR_AUTH.SW_octx
|
||||
#define sw_klen SWCR_UN.SWCR_AUTH.SW_klen
|
||||
#define sw_axf SWCR_UN.SWCR_AUTH.SW_axf
|
||||
#define sw_kschedule SWCR_UN.SWCR_ENC.SW_kschedule
|
||||
#define sw_exf SWCR_UN.SWCR_ENC.SW_exf
|
||||
#define sw_size SWCR_UN.SWCR_COMP.SW_size
|
||||
#define sw_cxf SWCR_UN.SWCR_COMP.SW_cxf
|
||||
struct swcr_data
|
||||
{
|
||||
int sw_alg; /* Algorithm */
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
FAR uint8_t *ictx;
|
||||
FAR uint8_t *octx;
|
||||
uint32_t klen;
|
||||
FAR const struct auth_hash *axf;
|
||||
} SWCR_AUTH;
|
||||
|
||||
struct swcr_data *sw_next;
|
||||
struct
|
||||
{
|
||||
FAR uint8_t *kschedule;
|
||||
FAR const struct enc_xform *exf;
|
||||
} SWCR_ENC;
|
||||
|
||||
struct
|
||||
{
|
||||
uint32_t size;
|
||||
FAR const struct comp_algo *cxf;
|
||||
} SWCR_COMP;
|
||||
} SWCR_UN;
|
||||
|
||||
#define sw_ictx SWCR_UN.SWCR_AUTH.ictx
|
||||
#define sw_octx SWCR_UN.SWCR_AUTH.octx
|
||||
#define sw_klen SWCR_UN.SWCR_AUTH.klen
|
||||
#define sw_axf SWCR_UN.SWCR_AUTH.axf
|
||||
#define sw_kschedule SWCR_UN.SWCR_ENC.kschedule
|
||||
#define sw_exf SWCR_UN.SWCR_ENC.exf
|
||||
#define sw_size SWCR_UN.SWCR_COMP.size
|
||||
#define sw_cxf SWCR_UN.SWCR_COMP.cxf
|
||||
|
||||
struct swcr_data *sw_next;
|
||||
};
|
||||
|
||||
#ifdef _KERNEL
|
||||
extern const u_int8_t hmac_ipad_buffer[HMAC_MAX_BLOCK_LEN];
|
||||
extern const u_int8_t hmac_opad_buffer[HMAC_MAX_BLOCK_LEN];
|
||||
extern const uint8_t hmac_ipad_buffer[HMAC_MAX_BLOCK_LEN];
|
||||
extern const uint8_t hmac_opad_buffer[HMAC_MAX_BLOCK_LEN];
|
||||
|
||||
int swcr_encdec(struct cryptodesc *, struct swcr_data *, caddr_t, int);
|
||||
int swcr_authcompute(struct cryptop *, struct cryptodesc *, struct swcr_data *,
|
||||
caddr_t, int);
|
||||
int swcr_authenc(struct cryptop *);
|
||||
int swcr_compdec(struct cryptodesc *, struct swcr_data *, caddr_t, int);
|
||||
int swcr_process(struct cryptop *);
|
||||
int swcr_newsession(u_int32_t *, struct cryptoini *);
|
||||
int swcr_freesession(u_int64_t);
|
||||
void swcr_init(void);
|
||||
int swcr_encdec(FAR struct cryptodesc *,
|
||||
FAR struct swcr_data *, caddr_t, int);
|
||||
int swcr_authcompute(FAR struct cryptop *, FAR struct cryptodesc *,
|
||||
FAR struct swcr_data *, caddr_t, int);
|
||||
int swcr_authenc(FAR struct cryptop *);
|
||||
int swcr_compdec(FAR struct cryptodesc *, FAR struct swcr_data *,
|
||||
caddr_t, int);
|
||||
int swcr_process(FAR struct cryptop *);
|
||||
int swcr_newsession(FAR uint32_t *, FAR struct cryptoini *);
|
||||
int swcr_freesession(uint64_t);
|
||||
void swcr_init(void);
|
||||
#endif /* _KERNEL */
|
||||
|
||||
#endif /* _CRYPTO_CRYPTO_H_ */
|
||||
#endif /* __INCLUDE_CRYPTO_CRYPTOSOFT_H */
|
||||
|
||||
+34
-27
@@ -1,6 +1,7 @@
|
||||
/* $OpenBSD: gmac.h,v 1.6 2017/05/02 11:44:32 mikeb Exp $ */
|
||||
|
||||
/*
|
||||
/****************************************************************************
|
||||
* include/crypto/gmac.h
|
||||
* $OpenBSD: gmac.h,v 1.6 2017/05/02 11:44:32 mikeb Exp $
|
||||
*
|
||||
* Copyright (c) 2010 Mike Belopuhov
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
@@ -14,36 +15,42 @@
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _GMAC_H_
|
||||
#define _GMAC_H_
|
||||
#ifndef __INCLUDE_CRYPTO_GMAC_H
|
||||
#define __INCLUDE_CRYPTO_GMAC_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <crypto/aes.h>
|
||||
|
||||
#define GMAC_BLOCK_LEN 16
|
||||
#define GMAC_DIGEST_LEN 16
|
||||
#define GMAC_BLOCK_LEN 16
|
||||
#define GMAC_DIGEST_LEN 16
|
||||
|
||||
typedef struct _GHASH_CTX {
|
||||
uint8_t H[GMAC_BLOCK_LEN]; /* hash subkey */
|
||||
uint8_t S[GMAC_BLOCK_LEN]; /* state */
|
||||
uint8_t Z[GMAC_BLOCK_LEN]; /* initial state */
|
||||
} GHASH_CTX;
|
||||
typedef struct _GHASH_CTX
|
||||
{
|
||||
uint8_t H[GMAC_BLOCK_LEN]; /* hash subkey */
|
||||
uint8_t S[GMAC_BLOCK_LEN]; /* state */
|
||||
uint8_t Z[GMAC_BLOCK_LEN]; /* initial state */
|
||||
}
|
||||
GHASH_CTX;
|
||||
|
||||
typedef struct _AES_GMAC_CTX {
|
||||
GHASH_CTX ghash;
|
||||
AES_CTX K;
|
||||
uint8_t J[GMAC_BLOCK_LEN]; /* counter block */
|
||||
} AES_GMAC_CTX;
|
||||
typedef struct _AES_GMAC_CTX
|
||||
{
|
||||
GHASH_CTX ghash;
|
||||
AES_CTX K;
|
||||
uint8_t J[GMAC_BLOCK_LEN]; /* counter block */
|
||||
}
|
||||
AES_GMAC_CTX;
|
||||
|
||||
__BEGIN_DECLS
|
||||
extern void (*ghash_update)(GHASH_CTX *, uint8_t *, size_t);
|
||||
extern void (*ghash_update)(FAR GHASH_CTX *, FAR uint8_t *, size_t);
|
||||
|
||||
void AES_GMAC_Init(void *);
|
||||
void AES_GMAC_Setkey(void *, const uint8_t *, uint16_t);
|
||||
void AES_GMAC_Reinit(void *, const uint8_t *, uint16_t);
|
||||
int AES_GMAC_Update(void *, const uint8_t *, uint16_t);
|
||||
void AES_GMAC_Final(uint8_t [GMAC_DIGEST_LEN], void *);
|
||||
__END_DECLS
|
||||
void aes_gmac_init(FAR void *);
|
||||
void aes_gmac_setkey(FAR void *, FAR const uint8_t *, uint16_t);
|
||||
void aes_gmac_reinit(FAR void *, FAR const uint8_t *, uint16_t);
|
||||
int aes_gmac_update(FAR void *, FAR const uint8_t *, uint16_t);
|
||||
void aes_gmac_final(FAR uint8_t *, FAR void *);
|
||||
|
||||
#endif /* _GMAC_H_ */
|
||||
#endif /* __INCLUDE_CRYPTO_GMAC_H */
|
||||
|
||||
+33
-42
@@ -1,6 +1,7 @@
|
||||
/* $OpenBSD: hmac.h,v 1.3 2012/12/05 23:20:15 deraadt Exp $ */
|
||||
|
||||
/*-
|
||||
/****************************************************************************
|
||||
* include/crypto/hmac.h
|
||||
* $OpenBSD: hmac.h,v 1.3 2012/12/05 23:20:15 deraadt Exp $
|
||||
*
|
||||
* Copyright (c) 2008 Damien Bergamini <damien.bergamini@free.fr>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
@@ -14,52 +15,42 @@
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _HMAC_H_
|
||||
#define _HMAC_H_
|
||||
#ifndef __INCLUDE_CRYPTO_HMAC_H_
|
||||
#define __INCLUDE_CRYPTO_HMAC_H_
|
||||
|
||||
typedef struct _HMAC_MD5_CTX {
|
||||
MD5_CTX ctx;
|
||||
u_int8_t key[MD5_BLOCK_LENGTH];
|
||||
u_int key_len;
|
||||
typedef struct _HMAC_MD5_CTX
|
||||
{
|
||||
MD5_CTX ctx;
|
||||
u_int8_t key[MD5_BLOCK_LENGTH];
|
||||
u_int key_len;
|
||||
} HMAC_MD5_CTX;
|
||||
|
||||
typedef struct _HMAC_SHA1_CTX {
|
||||
SHA1_CTX ctx;
|
||||
u_int8_t key[SHA1_BLOCK_LENGTH];
|
||||
u_int key_len;
|
||||
typedef struct _HMAC_SHA1_CTX
|
||||
{
|
||||
SHA1_CTX ctx;
|
||||
u_int8_t key[SHA1_BLOCK_LENGTH];
|
||||
u_int key_len;
|
||||
} HMAC_SHA1_CTX;
|
||||
|
||||
typedef struct _HMAC_SHA256_CTX {
|
||||
SHA2_CTX ctx;
|
||||
u_int8_t key[SHA256_BLOCK_LENGTH];
|
||||
u_int key_len;
|
||||
typedef struct _HMAC_SHA256_CTX
|
||||
{
|
||||
SHA2_CTX ctx;
|
||||
u_int8_t key[SHA256_BLOCK_LENGTH];
|
||||
u_int key_len;
|
||||
} HMAC_SHA256_CTX;
|
||||
|
||||
__BEGIN_DECLS
|
||||
void hmac_md5_init(FAR HMAC_MD5_CTX *, FAR const u_int8_t *, u_int);
|
||||
void hmac_md5_update(FAR HMAC_MD5_CTX *, FAR const u_int8_t *, u_int);
|
||||
void hmac_md5_final(FAR u_int8_t *, FAR HMAC_MD5_CTX *);
|
||||
void hmac_sha1_init(FAR HMAC_SHA1_CTX *, FAR const u_int8_t *, u_int);
|
||||
void hmac_sha1_update(FAR HMAC_SHA1_CTX *, FAR const u_int8_t *, u_int);
|
||||
void hmac_sha1_final(FAR u_int8_t *, FAR HMAC_SHA1_CTX *);
|
||||
|
||||
void HMAC_MD5_Init(HMAC_MD5_CTX *, const u_int8_t *, u_int)
|
||||
__attribute__((__bounded__(__string__,2,3)));
|
||||
void HMAC_MD5_Update(HMAC_MD5_CTX *, const u_int8_t *, u_int)
|
||||
__attribute__((__bounded__(__string__,2,3)));
|
||||
void HMAC_MD5_Final(u_int8_t [MD5_DIGEST_LENGTH], HMAC_MD5_CTX *)
|
||||
__attribute__((__bounded__(__minbytes__,1,MD5_DIGEST_LENGTH)));
|
||||
void hmac_sha256_init(FAR HMAC_SHA256_CTX *, FAR const u_int8_t *, u_int);
|
||||
void hmac_sha256_update(FAR HMAC_SHA256_CTX *, FAR const u_int8_t *, u_int);
|
||||
void hmac_sha256_final(FAR u_int8_t *, FAR HMAC_SHA256_CTX *);
|
||||
|
||||
void HMAC_SHA1_Init(HMAC_SHA1_CTX *, const u_int8_t *, u_int)
|
||||
__attribute__((__bounded__(__string__,2,3)));
|
||||
void HMAC_SHA1_Update(HMAC_SHA1_CTX *, const u_int8_t *, u_int)
|
||||
__attribute__((__bounded__(__string__,2,3)));
|
||||
void HMAC_SHA1_Final(u_int8_t [SHA1_DIGEST_LENGTH], HMAC_SHA1_CTX *)
|
||||
__attribute__((__bounded__(__minbytes__,1,SHA1_DIGEST_LENGTH)));
|
||||
|
||||
void HMAC_SHA256_Init(HMAC_SHA256_CTX *, const u_int8_t *, u_int)
|
||||
__attribute__((__bounded__(__string__,2,3)));
|
||||
void HMAC_SHA256_Update(HMAC_SHA256_CTX *, const u_int8_t *, u_int)
|
||||
__attribute__((__bounded__(__string__,2,3)));
|
||||
void HMAC_SHA256_Final(u_int8_t [SHA256_DIGEST_LENGTH], HMAC_SHA256_CTX *)
|
||||
__attribute__((__bounded__(__minbytes__,1,SHA256_DIGEST_LENGTH)));
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _HMAC_H_ */
|
||||
#endif /* __INCLUDE_CRYPTO_HMAC_H_ */
|
||||
|
||||
+23
-15
@@ -1,5 +1,7 @@
|
||||
/* $OpenBSD: idgen.h,v 1.3 2013/06/05 05:45:54 djm Exp $ */
|
||||
/*
|
||||
/****************************************************************************
|
||||
* include/crypto/idgen.h
|
||||
* $OpenBSD: idgen.h,v 1.3 2013/06/05 05:45:54 djm Exp $
|
||||
*
|
||||
* Copyright (c) 2008 Damien Miller <djm@mindrot.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
@@ -13,21 +15,27 @@
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define IDGEN32_ROUNDS 31
|
||||
#define IDGEN32_KEYLEN 32
|
||||
#define IDGEN32_REKEY_LIMIT 0x60000000
|
||||
#define IDGEN32_REKEY_TIME 600
|
||||
#ifndef __INCLUDE_CRYPTO_IDGEN_H_
|
||||
#define __INCLUDE_CRYPTO_IDGEN_H_
|
||||
|
||||
struct idgen32_ctx {
|
||||
u_int32_t id32_counter;
|
||||
u_int32_t id32_offset;
|
||||
u_int32_t id32_hibit;
|
||||
u_int8_t id32_key[IDGEN32_KEYLEN];
|
||||
time_t id32_rekey_time;
|
||||
#define IDGEN32_ROUNDS 31
|
||||
#define IDGEN32_KEYLEN 32
|
||||
#define IDGEN32_REKEY_LIMIT 0x60000000
|
||||
#define IDGEN32_REKEY_TIME 600
|
||||
|
||||
struct idgen32_ctx
|
||||
{
|
||||
u_int32_t id32_counter;
|
||||
u_int32_t id32_offset;
|
||||
u_int32_t id32_hibit;
|
||||
u_int8_t id32_key[IDGEN32_KEYLEN];
|
||||
time_t id32_rekey_time;
|
||||
};
|
||||
|
||||
void idgen32_init(struct idgen32_ctx *);
|
||||
u_int32_t idgen32(struct idgen32_ctx *);
|
||||
void idgen32_init(FAR struct idgen32_ctx *);
|
||||
u_int32_t idgen32(FAR struct idgen32_ctx *);
|
||||
|
||||
#endif /* __INCLUDE_CRYPTO_IDGEN_H_ */
|
||||
+21
-18
@@ -1,6 +1,6 @@
|
||||
/* $OpenBSD: key_wrap.h,v 1.3 2017/05/02 17:07:06 mikeb Exp $ */
|
||||
|
||||
/*-
|
||||
/****************************************************************************
|
||||
* include/crypto/key_wrap.h
|
||||
*$OpenBSD: key_wrap.h,v 1.3 2017/05/02 17:07:06 mikeb Exp $
|
||||
* Copyright (c) 2008 Damien Bergamini <damien.bergamini@free.fr>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
@@ -14,23 +14,26 @@
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _KEY_WRAP_H_
|
||||
#define _KEY_WRAP_H_
|
||||
#ifndef __INCLUDE_CRYPTO_KEY_WRAP_H_
|
||||
#define __INCLUDE_CRYPTO_KEY_WRAP_H_
|
||||
|
||||
typedef struct _aes_key_wrap_ctx {
|
||||
AES_CTX ctx;
|
||||
typedef struct _aes_key_wrap_ctx
|
||||
{
|
||||
AES_CTX ctx;
|
||||
} aes_key_wrap_ctx;
|
||||
|
||||
__BEGIN_DECLS
|
||||
void aes_key_wrap_set_key(FAR aes_key_wrap_ctx *,
|
||||
FAR const u_int8_t *,
|
||||
size_t);
|
||||
void aes_key_wrap_set_key_wrap_only(FAR aes_key_wrap_ctx *,
|
||||
FAR const u_int8_t *,
|
||||
size_t);
|
||||
void aes_key_wrap(FAR aes_key_wrap_ctx *,
|
||||
FAR const u_int8_t *, size_t, FAR u_int8_t *);
|
||||
int aes_key_unwrap(FAR aes_key_wrap_ctx *,
|
||||
FAR const u_int8_t *, FAR u_int8_t *, size_t);
|
||||
|
||||
void aes_key_wrap_set_key(aes_key_wrap_ctx *, const u_int8_t *, size_t);
|
||||
void aes_key_wrap_set_key_wrap_only(aes_key_wrap_ctx *, const u_int8_t *,
|
||||
size_t);
|
||||
void aes_key_wrap(aes_key_wrap_ctx *, const u_int8_t *, size_t, u_int8_t *);
|
||||
int aes_key_unwrap(aes_key_wrap_ctx *, const u_int8_t *, u_int8_t *,
|
||||
size_t);
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _KEY_WRAP_H_ */
|
||||
#endif /* __INCLUDE_CRYPTO_KEY_WRAP_H_ */
|
||||
|
||||
+21
-23
@@ -1,6 +1,8 @@
|
||||
/* $OpenBSD: md5.h,v 1.3 2014/11/16 17:39:09 tedu Exp $ */
|
||||
|
||||
/*
|
||||
/****************************************************************************
|
||||
* include/crypto/md5.h
|
||||
* $OpenBSD: md5.h,v 1.3 2014/11/16 17:39:09 tedu Exp $
|
||||
*
|
||||
*
|
||||
* This code implements the MD5 message-digest algorithm.
|
||||
* The algorithm is due to Ron Rivest. This code was
|
||||
* written by Colin Plumb in 1993, no copyright is claimed.
|
||||
@@ -10,29 +12,25 @@
|
||||
* This code has been tested against that, and is equivalent,
|
||||
* except that you don't need to include two pages of legalese
|
||||
* with every copy.
|
||||
*/
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _MD5_H_
|
||||
#define _MD5_H_
|
||||
#ifndef __INCLUDE_CRYPTO_MD5_H
|
||||
#define __INCLUDE_CRYPTO_MD5_H
|
||||
|
||||
#define MD5_BLOCK_LENGTH 64
|
||||
#define MD5_DIGEST_LENGTH 16
|
||||
#define MD5_BLOCK_LENGTH 64
|
||||
#define MD5_DIGEST_LENGTH 16
|
||||
|
||||
typedef struct MD5Context {
|
||||
u_int32_t state[4]; /* state */
|
||||
u_int64_t count; /* number of bits, mod 2^64 */
|
||||
u_int8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */
|
||||
typedef struct MD5CONTEXT
|
||||
{
|
||||
uint32_t state[4]; /* state */
|
||||
uint64_t count; /* number of bits, mod 2^64 */
|
||||
uint8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */
|
||||
} MD5_CTX;
|
||||
|
||||
__BEGIN_DECLS
|
||||
void MD5Init(MD5_CTX *);
|
||||
void MD5Update(MD5_CTX *, const void *, size_t)
|
||||
__attribute__((__bounded__(__string__,2,3)));
|
||||
void MD5Final(u_int8_t [MD5_DIGEST_LENGTH], MD5_CTX *)
|
||||
__attribute__((__bounded__(__minbytes__,1,MD5_DIGEST_LENGTH)));
|
||||
void MD5Transform(u_int32_t [4], const u_int8_t [MD5_BLOCK_LENGTH])
|
||||
__attribute__((__bounded__(__minbytes__,1,4)))
|
||||
__attribute__((__bounded__(__minbytes__,2,MD5_BLOCK_LENGTH)));
|
||||
__END_DECLS
|
||||
void md5init(FAR MD5_CTX *);
|
||||
void md5update(FAR MD5_CTX *, FAR const void *, size_t);
|
||||
void md5final(FAR uint8_t *, FAR MD5_CTX *);
|
||||
void md5transform(FAR uint32_t *, FAR const uint8_t *);
|
||||
|
||||
#endif /* _MD5_H_ */
|
||||
#endif /* __INCLUDE_CRYPTO_MD5_H */
|
||||
|
||||
+20
-16
@@ -1,27 +1,31 @@
|
||||
/* $OpenBSD: poly1305.h,v 1.2 2020/07/22 13:54:30 tobhe Exp $ */
|
||||
/*
|
||||
/****************************************************************************
|
||||
* include/crypto/poly1305.h
|
||||
* $OpenBSD: poly1305.h,v 1.2 2020/07/22 13:54:30 tobhe Exp $
|
||||
*
|
||||
* Public Domain poly1305 from Andrew Moon
|
||||
*
|
||||
* poly1305 implementation using 32 bit * 32 bit = 64 bit multiplication
|
||||
* and 64 bit addition from https://github.com/floodyberry/poly1305-donna
|
||||
*/
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _POLY1305_H_
|
||||
#define _POLY1305_H_
|
||||
#ifndef __INCLUDE_CRYPTO_POLY1305_H
|
||||
#define __INCLUDE_CRYPTO_POLY1305_H
|
||||
|
||||
#define poly1305_block_size 16
|
||||
|
||||
typedef struct poly1305_state {
|
||||
unsigned long r[5];
|
||||
unsigned long h[5];
|
||||
unsigned long pad[4];
|
||||
size_t leftover;
|
||||
unsigned char buffer[poly1305_block_size];
|
||||
unsigned char final;
|
||||
typedef struct poly1305_state
|
||||
{
|
||||
unsigned long r[5];
|
||||
unsigned long h[5];
|
||||
unsigned long pad[4];
|
||||
size_t leftover;
|
||||
unsigned char buffer[poly1305_block_size];
|
||||
unsigned char final;
|
||||
} poly1305_state;
|
||||
|
||||
void poly1305_init(poly1305_state *, const unsigned char[32]);
|
||||
void poly1305_update(poly1305_state *, const unsigned char *, size_t);
|
||||
void poly1305_finish(poly1305_state *, unsigned char[16]);
|
||||
void poly1305_init(FAR poly1305_state *, FAR const unsigned char *);
|
||||
void poly1305_update(FAR poly1305_state *,
|
||||
FAR const unsigned char *, size_t);
|
||||
void poly1305_finish(FAR poly1305_state *, FAR unsigned char *);
|
||||
|
||||
#endif /* _POLY1305_H_ */
|
||||
#endif /* __INCLUDE_CRYPTO_POLY1305_H */
|
||||
|
||||
+34
-26
@@ -1,6 +1,7 @@
|
||||
/* $OpenBSD: rijndael.h,v 1.13 2008/06/09 07:49:45 djm Exp $ */
|
||||
|
||||
/**
|
||||
/****************************************************************************
|
||||
* include/crypto/rijndael.h
|
||||
* $OpenBSD: rijndael.h,v 1.13 2008/06/09 07:49:45 djm Exp $
|
||||
*
|
||||
* rijndael-alg-fst.h
|
||||
*
|
||||
* @version 3.0 (December 2000)
|
||||
@@ -24,35 +25,42 @@
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef __RIJNDAEL_H
|
||||
#define __RIJNDAEL_H
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_CRYPTO_RIJNDAEL_H
|
||||
#define __INCLUDE_CRYPTO_RIJNDAEL_H
|
||||
|
||||
#define AES_MAXKEYBITS (256)
|
||||
#define AES_MAXKEYBYTES (AES_MAXKEYBITS / 8)
|
||||
|
||||
#define AES_MAXKEYBITS (256)
|
||||
#define AES_MAXKEYBYTES (AES_MAXKEYBITS/8)
|
||||
/* for 256-bit keys, fewer for less */
|
||||
#define AES_MAXROUNDS 14
|
||||
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
#define AES_MAXROUNDS 14
|
||||
|
||||
/* The structure for key information */
|
||||
typedef struct {
|
||||
int enc_only; /* context contains only encrypt schedule */
|
||||
int Nr; /* key-length-dependent number of rounds */
|
||||
u32 ek[4*(AES_MAXROUNDS + 1)]; /* encrypt key schedule */
|
||||
u32 dk[4*(AES_MAXROUNDS + 1)]; /* decrypt key schedule */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int enc_only; /* context contains only encrypt schedule */
|
||||
int nr; /* key-length-dependent number of rounds */
|
||||
uint32_t ek[4 * (AES_MAXROUNDS + 1)]; /* encrypt key schedule */
|
||||
uint32_t dk[4 * (AES_MAXROUNDS + 1)]; /* decrypt key schedule */
|
||||
} rijndael_ctx;
|
||||
|
||||
int rijndael_set_key(rijndael_ctx *, const u_char *, int);
|
||||
int rijndael_set_key_enc_only(rijndael_ctx *, const u_char *, int);
|
||||
void rijndael_decrypt(rijndael_ctx *, const u_char *, u_char *);
|
||||
void rijndael_encrypt(rijndael_ctx *, const u_char *, u_char *);
|
||||
int rijndael_set_key(FAR rijndael_ctx *, FAR const u_char *, int);
|
||||
int rijndael_set_key_enc_only(FAR rijndael_ctx *, FAR const u_char *, int);
|
||||
void rijndael_decrypt(FAR rijndael_ctx *, FAR const u_char *, FAR u_char *);
|
||||
void rijndael_encrypt(FAR rijndael_ctx *, FAR const u_char *, FAR u_char *);
|
||||
|
||||
int rijndaelKeySetupEnc(unsigned int [], const unsigned char [], int);
|
||||
int rijndaelKeySetupDec(unsigned int [], const unsigned char [], int);
|
||||
void rijndaelEncrypt(const unsigned int [], int, const unsigned char [],
|
||||
unsigned char []);
|
||||
int rijndael_keysetupenc(unsigned int [],
|
||||
const unsigned char [],
|
||||
int);
|
||||
int rijndael_keysetupdec(unsigned int [],
|
||||
const unsigned char [],
|
||||
int);
|
||||
void rijndael_encrypt1(const unsigned int [],
|
||||
int,
|
||||
const unsigned char [],
|
||||
unsigned char []);
|
||||
|
||||
#endif /* __RIJNDAEL_H */
|
||||
#endif /* __INCLUDE_CRYPTO_RIJNDAEL_H */
|
||||
|
||||
+22
-22
@@ -1,5 +1,7 @@
|
||||
/* $OpenBSD: rmd160.h,v 1.5 2009/07/05 19:33:46 millert Exp $ */
|
||||
/*
|
||||
/****************************************************************************
|
||||
* include/crypto/rmd160.h
|
||||
* $OpenBSD: rmd160.h,v 1.5 2009/07/05 19:33:46 millert Exp $
|
||||
*
|
||||
* Copyright (c) 2001 Markus Friedl. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -21,29 +23,27 @@
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _RMD160_H
|
||||
#define _RMD160_H
|
||||
****************************************************************************/
|
||||
|
||||
#define RMD160_BLOCK_LENGTH 64
|
||||
#define RMD160_DIGEST_LENGTH 20
|
||||
#ifndef __INCLUDE_CRYPTO_RMD160_H
|
||||
#define __INCLUDE_CRYPTO_RMD160_H
|
||||
|
||||
#define RMD160_BLOCK_LENGTH 64
|
||||
#define RMD160_DIGEST_LENGTH 20
|
||||
|
||||
/* RMD160 context. */
|
||||
typedef struct RMD160Context {
|
||||
u_int32_t state[5]; /* state */
|
||||
u_int64_t count; /* number of bits, mod 2^64 */
|
||||
u_char buffer[RMD160_BLOCK_LENGTH]; /* input buffer */
|
||||
|
||||
typedef struct RMD160CONTEXT
|
||||
{
|
||||
uint32_t state[5]; /* state */
|
||||
uint64_t count; /* number of bits, mod 2^64 */
|
||||
u_char buffer[RMD160_BLOCK_LENGTH]; /* input buffer */
|
||||
} RMD160_CTX;
|
||||
|
||||
__BEGIN_DECLS
|
||||
void RMD160Init(RMD160_CTX *);
|
||||
void RMD160Transform(u_int32_t [5], const u_char [RMD160_BLOCK_LENGTH])
|
||||
__attribute__((__bounded__(__minbytes__,1,5)))
|
||||
__attribute__((__bounded__(__minbytes__,2,RMD160_BLOCK_LENGTH)));
|
||||
void RMD160Update(RMD160_CTX *, const u_char *, u_int32_t)
|
||||
__attribute__((__bounded__(__string__,2,3)));
|
||||
void RMD160Final(u_char [RMD160_DIGEST_LENGTH], RMD160_CTX *)
|
||||
__attribute__((__bounded__(__minbytes__,1,RMD160_DIGEST_LENGTH)));
|
||||
__END_DECLS
|
||||
void rmd160init(FAR RMD160_CTX *);
|
||||
void rmd160transform(FAR uint32_t *,
|
||||
FAR const u_char *);
|
||||
void rmd160update(FAR RMD160_CTX *, FAR const u_char *, uint32_t);
|
||||
void rmd160final(FAR u_char *, FAR RMD160_CTX *);
|
||||
|
||||
#endif /* _RMD160_H */
|
||||
#endif /* __INCLUDE_CRYPTO_RMD160_H */
|
||||
|
||||
+23
-18
@@ -1,26 +1,31 @@
|
||||
/* $OpenBSD: sha1.h,v 1.6 2014/11/16 17:39:09 tedu Exp $ */
|
||||
|
||||
/*
|
||||
/****************************************************************************
|
||||
* include/crypto/sha1.h
|
||||
* $OpenBSD: sha1.h,v 1.6 2014/11/16 17:39:09 tedu Exp $
|
||||
* SHA-1 in C
|
||||
* By Steve Reid <steve@edmweb.com>
|
||||
* 100% Public Domain
|
||||
*/
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _SHA1_H_
|
||||
#define _SHA1_H_
|
||||
#ifndef __INCLUDE_CRYPTO_SHA1_H
|
||||
#define __INCLUDE_CRYPTO_SHA1_H
|
||||
|
||||
#define SHA1_BLOCK_LENGTH 64
|
||||
#define SHA1_DIGEST_LENGTH 20
|
||||
#define SHA1_BLOCK_LENGTH 64
|
||||
#define SHA1_DIGEST_LENGTH 20
|
||||
|
||||
typedef struct {
|
||||
u_int32_t state[5];
|
||||
u_int64_t count;
|
||||
unsigned char buffer[SHA1_BLOCK_LENGTH];
|
||||
typedef struct
|
||||
{
|
||||
uint32_t state[5];
|
||||
uint64_t count;
|
||||
unsigned char buffer[SHA1_BLOCK_LENGTH];
|
||||
} SHA1_CTX;
|
||||
|
||||
void SHA1Init(SHA1_CTX * context);
|
||||
void SHA1Transform(u_int32_t state[5], const unsigned char buffer[SHA1_BLOCK_LENGTH]);
|
||||
void SHA1Update(SHA1_CTX *context, const void *data, unsigned int len);
|
||||
void SHA1Final(unsigned char digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context);
|
||||
|
||||
#endif /* _SHA1_H_ */
|
||||
void sha1init(FAR SHA1_CTX * context);
|
||||
void sha1transform(FAR uint32_t *state,
|
||||
FAR const unsigned char *buffer);
|
||||
void sha1update(FAR SHA1_CTX *context,
|
||||
FAR const void *data,
|
||||
unsigned int len);
|
||||
void sha1final(FAR unsigned char *digest,
|
||||
FAR SHA1_CTX *context);
|
||||
|
||||
#endif /* __INCLUDE_CRYPTO_SHA1_H */
|
||||
|
||||
+41
-46
@@ -1,9 +1,10 @@
|
||||
/* $OpenBSD: sha2.h,v 1.5 2014/11/16 17:39:09 tedu Exp $ */
|
||||
|
||||
/*
|
||||
* FILE: sha2.h
|
||||
* AUTHOR: Aaron D. Gifford <me@aarongifford.com>
|
||||
*
|
||||
/****************************************************************************
|
||||
* include/crypto/sha2.h
|
||||
* $OpenBSD: sha2.h,v 1.5 2014/11/16 17:39:09 tedu Exp $
|
||||
*
|
||||
* FILE: sha2.h
|
||||
* AUTHOR: Aaron D. Gifford <me@aarongifford.com>
|
||||
*
|
||||
* Copyright (c) 2000-2001, Aaron D. Gifford
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -18,7 +19,7 @@
|
||||
* 3. Neither the name of the copyright holder nor the names of contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
@@ -32,52 +33,46 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $From: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $
|
||||
*/
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _SHA2_H
|
||||
#define _SHA2_H
|
||||
#ifndef __INCLUDE_CRYPTO_SHA2_H
|
||||
#define __INCLUDE_CRYPTO_SHA2_H
|
||||
|
||||
/* SHA-256/384/512 Various Length Definitions */
|
||||
|
||||
/*** SHA-256/384/512 Various Length Definitions ***********************/
|
||||
#define SHA256_BLOCK_LENGTH 64
|
||||
#define SHA256_DIGEST_LENGTH 32
|
||||
#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
|
||||
#define SHA384_BLOCK_LENGTH 128
|
||||
#define SHA384_DIGEST_LENGTH 48
|
||||
#define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
|
||||
#define SHA512_BLOCK_LENGTH 128
|
||||
#define SHA512_DIGEST_LENGTH 64
|
||||
#define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
|
||||
#define SHA256_BLOCK_LENGTH 64
|
||||
#define SHA256_DIGEST_LENGTH 32
|
||||
#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
|
||||
#define SHA384_BLOCK_LENGTH 128
|
||||
#define SHA384_DIGEST_LENGTH 48
|
||||
#define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
|
||||
#define SHA512_BLOCK_LENGTH 128
|
||||
#define SHA512_DIGEST_LENGTH 64
|
||||
#define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
|
||||
|
||||
/* SHA-256/384/512 Context Structure */
|
||||
|
||||
/*** SHA-256/384/512 Context Structure *******************************/
|
||||
typedef struct _SHA2_CTX {
|
||||
union {
|
||||
u_int32_t st32[8];
|
||||
u_int64_t st64[8];
|
||||
} state;
|
||||
u_int64_t bitcount[2];
|
||||
u_int8_t buffer[SHA512_BLOCK_LENGTH];
|
||||
typedef struct _SHA2_CTX
|
||||
{
|
||||
union
|
||||
{
|
||||
uint32_t st32[8];
|
||||
uint64_t st64[8];
|
||||
} state;
|
||||
uint64_t bitcount[2];
|
||||
uint8_t buffer[SHA512_BLOCK_LENGTH];
|
||||
} SHA2_CTX;
|
||||
|
||||
__BEGIN_DECLS
|
||||
void SHA256Init(SHA2_CTX *);
|
||||
void SHA256Update(SHA2_CTX *, const void *, size_t)
|
||||
__attribute__((__bounded__(__string__,2,3)));
|
||||
void SHA256Final(u_int8_t[SHA256_DIGEST_LENGTH], SHA2_CTX *)
|
||||
__attribute__((__bounded__(__minbytes__,1,SHA256_DIGEST_LENGTH)));
|
||||
void sha256init(FAR SHA2_CTX *);
|
||||
void sha256update(FAR SHA2_CTX *, FAR const void *, size_t);
|
||||
void sha256final(FAR uint8_t *, FAR SHA2_CTX *);
|
||||
|
||||
void SHA384Init(SHA2_CTX *);
|
||||
void SHA384Update(SHA2_CTX *, const void *, size_t)
|
||||
__attribute__((__bounded__(__string__,2,3)));
|
||||
void SHA384Final(u_int8_t[SHA384_DIGEST_LENGTH], SHA2_CTX *)
|
||||
__attribute__((__bounded__(__minbytes__,1,SHA384_DIGEST_LENGTH)));
|
||||
void sha384init(FAR SHA2_CTX *);
|
||||
void sha384update(FAR SHA2_CTX *, FAR const void *, size_t);
|
||||
void sha384final(FAR uint8_t *, FAR SHA2_CTX *);
|
||||
|
||||
void SHA512Init(SHA2_CTX *);
|
||||
void SHA512Update(SHA2_CTX *, const void *, size_t)
|
||||
__attribute__((__bounded__(__string__,2,3)));
|
||||
void SHA512Final(u_int8_t[SHA512_DIGEST_LENGTH], SHA2_CTX *)
|
||||
__attribute__((__bounded__(__minbytes__,1,SHA512_DIGEST_LENGTH)));
|
||||
__END_DECLS
|
||||
void sha512init(FAR SHA2_CTX *);
|
||||
void sha512update(FAR SHA2_CTX *, FAR const void *, size_t);
|
||||
void sha512final(FAR uint8_t *, FAR SHA2_CTX *);
|
||||
|
||||
#endif /* _SHA2_H */
|
||||
#endif /* __INCLUDE_CRYPTO_SHA2_H */
|
||||
|
||||
+44
-41
@@ -1,5 +1,7 @@
|
||||
/* $OpenBSD: siphash.h,v 1.5 2015/02/20 11:51:03 tedu Exp $ */
|
||||
/*-
|
||||
/****************************************************************************
|
||||
* include/crypto/siphash.h
|
||||
* $OpenBSD: siphash.h,v 1.5 2015/02/20 11:51:03 tedu Exp $
|
||||
*
|
||||
* Copyright (c) 2013 Andre Oppermann <andre@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -28,60 +30,61 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* SipHash is a family of pseudorandom functions (a.k.a. keyed hash functions)
|
||||
/* SipHash is a family of pseudorandom functions
|
||||
* (a.k.a. keyed hash functions)
|
||||
* optimized for speed on short messages returning a 64bit hash/digest value.
|
||||
*
|
||||
* The number of rounds is defined during the initialization:
|
||||
* SipHash24_Init() for the fast and resonable strong version
|
||||
* SipHash48_Init() for the strong version (half as fast)
|
||||
* siphash24_init() for the fast and resonable strong version
|
||||
* siphash48_init() for the strong version (half as fast)
|
||||
*
|
||||
* struct SIPHASH_CTX ctx;
|
||||
* SipHash24_Init(&ctx);
|
||||
* SipHash_SetKey(&ctx, "16bytes long key");
|
||||
* SipHash_Update(&ctx, pointer_to_string, length_of_string);
|
||||
* SipHash_Final(output, &ctx);
|
||||
* siphash24_init(&ctx);
|
||||
* siphash_setkey(&ctx, "16bytes long key");
|
||||
* siphash_update(&ctx, pointer_to_string, length_of_string);
|
||||
* siphash_final(output, &ctx);
|
||||
*/
|
||||
|
||||
#ifndef _SIPHASH_H_
|
||||
#define _SIPHASH_H_
|
||||
#ifndef __INCLUDE_CRYPTO_SIPHASH_H_
|
||||
#define __INCLUDE_CRYPTO_SIPHASH_H_
|
||||
|
||||
#define SIPHASH_BLOCK_LENGTH 8
|
||||
#define SIPHASH_KEY_LENGTH 16
|
||||
#define SIPHASH_DIGEST_LENGTH 8
|
||||
#define SIPHASH_BLOCK_LENGTH 8
|
||||
#define SIPHASH_KEY_LENGTH 16
|
||||
#define SIPHASH_DIGEST_LENGTH 8
|
||||
|
||||
typedef struct _SIPHASH_CTX {
|
||||
uint64_t v[4];
|
||||
uint8_t buf[SIPHASH_BLOCK_LENGTH];
|
||||
uint32_t bytes;
|
||||
typedef struct _SIPHASH_CTX
|
||||
{
|
||||
uint64_t v[4];
|
||||
uint8_t buf[SIPHASH_BLOCK_LENGTH];
|
||||
uint32_t bytes;
|
||||
} SIPHASH_CTX;
|
||||
|
||||
typedef struct {
|
||||
uint64_t k0;
|
||||
uint64_t k1;
|
||||
typedef struct
|
||||
{
|
||||
uint64_t k0;
|
||||
uint64_t k1;
|
||||
} SIPHASH_KEY;
|
||||
|
||||
void SipHash_Init(SIPHASH_CTX *, const SIPHASH_KEY *);
|
||||
void SipHash_Update(SIPHASH_CTX *, int, int, const void *, size_t)
|
||||
__bounded((__buffer__, 4, 5));
|
||||
uint64_t SipHash_End(SIPHASH_CTX *, int, int);
|
||||
void SipHash_Final(void *, SIPHASH_CTX *, int, int)
|
||||
__bounded((__minbytes__, 1, SIPHASH_DIGEST_LENGTH));
|
||||
uint64_t SipHash(const SIPHASH_KEY *, int, int, const void *, size_t)
|
||||
__bounded((__buffer__, 4, 5));
|
||||
void siphash_init(FAR SIPHASH_CTX *, FAR const SIPHASH_KEY *);
|
||||
void siphash_update(FAR SIPHASH_CTX *, int, int, FAR const void *, size_t);
|
||||
uint64_t siphash_end(FAR SIPHASH_CTX *, int, int);
|
||||
void siphash_final(FAR void *, FAR SIPHASH_CTX *, int, int);
|
||||
uint64_t siphash(FAR const SIPHASH_KEY *,
|
||||
int, int, FAR const void *, size_t);
|
||||
|
||||
#define SipHash24_Init(_c, _k) SipHash_Init((_c), (_k))
|
||||
#define SipHash24_Update(_c, _p, _l) SipHash_Update((_c), 2, 4, (_p), (_l))
|
||||
#define SipHash24_End(_d) SipHash_End((_d), 2, 4)
|
||||
#define SipHash24_Final(_d, _c) SipHash_Final((_d), (_c), 2, 4)
|
||||
#define SipHash24(_k, _p, _l) SipHash((_k), 2, 4, (_p), (_l))
|
||||
#define SipHash24_Init(_c, _k) siphash_init((_c), (_k))
|
||||
#define SipHash24_Update(_c, _p, _l) siphash_update((_c), 2, 4, (_p), (_l))
|
||||
#define SipHash24_End(_d) siphash_end((_d), 2, 4)
|
||||
#define SipHash24_Final(_d, _c) siphash_final((_d), (_c), 2, 4)
|
||||
#define SipHash24(_k, _p, _l) siphash((_k), 2, 4, (_p), (_l))
|
||||
|
||||
#define SipHash48_Init(_c, _k) SipHash_Init((_c), (_k))
|
||||
#define SipHash48_Update(_c, _p, _l) SipHash_Update((_c), 4, 8, (_p), (_l))
|
||||
#define SipHash48_End(_d) SipHash_End((_d), 4, 8)
|
||||
#define SipHash48_Final(_d, _c) SipHash_Final((_d), (_c), 4, 8)
|
||||
#define SipHash48(_k, _p, _l) SipHash((_k), 4, 8, (_p), (_l))
|
||||
#define SipHash48_Init(_c, _k) siphash_init((_c), (_k))
|
||||
#define SipHash48_Update(_c, _p, _l) siphash_update((_c), 4, 8, (_p), (_l))
|
||||
#define SipHash48_End(_d) siphash_end((_d), 4, 8)
|
||||
#define SipHash48_Final(_d, _c) siphash_final((_d), (_c), 4, 8)
|
||||
#define SipHash48(_k, _p, _l) siphash((_k), 4, 8, (_p), (_l))
|
||||
|
||||
#endif /* _SIPHASH_H_ */
|
||||
|
||||
+60
-50
@@ -1,6 +1,7 @@
|
||||
/* $OpenBSD: xform.h,v 1.32 2021/10/22 12:30:53 bluhm Exp $ */
|
||||
|
||||
/*
|
||||
/****************************************************************************
|
||||
* include/crypto/xform.h
|
||||
* $OpenBSD: xform.h,v 1.32 2021/10/22 12:30:53 bluhm Exp $
|
||||
*
|
||||
* The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
|
||||
*
|
||||
* This code was written by Angelos D. Keromytis in Athens, Greece, in
|
||||
@@ -19,10 +20,14 @@
|
||||
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
|
||||
* MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
|
||||
* PURPOSE.
|
||||
*/
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _CRYPTO_XFORM_H_
|
||||
#define _CRYPTO_XFORM_H_
|
||||
#ifndef __INCLUDE_CRYPTO_XFORM_H
|
||||
#define __INCLUDE_CRYPTO_XFORM_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <crypto/md5.h>
|
||||
#include <crypto/sha1.h>
|
||||
@@ -30,58 +35,63 @@
|
||||
#include <crypto/sha2.h>
|
||||
#include <crypto/gmac.h>
|
||||
|
||||
#define AESCTR_NONCESIZE 4
|
||||
#define AESCTR_IVSIZE 8
|
||||
#define AESCTR_BLOCKSIZE 16
|
||||
#define AESCTR_NONCESIZE 4
|
||||
#define AESCTR_IVSIZE 8
|
||||
#define AESCTR_BLOCKSIZE 16
|
||||
|
||||
#define AES_XTS_BLOCKSIZE 16
|
||||
#define AES_XTS_IVSIZE 8
|
||||
#define AES_XTS_ALPHA 0x87 /* GF(2^128) generator polynomial */
|
||||
#define AES_XTS_BLOCKSIZE 16
|
||||
#define AES_XTS_IVSIZE 8
|
||||
#define AES_XTS_ALPHA 0x87 /* GF(2^128) generator polynomial */
|
||||
|
||||
/* Declarations */
|
||||
struct auth_hash {
|
||||
int type;
|
||||
char *name;
|
||||
u_int16_t keysize;
|
||||
u_int16_t hashsize;
|
||||
u_int16_t authsize;
|
||||
u_int16_t ctxsize;
|
||||
u_int16_t blocksize;
|
||||
void (*Init) (void *);
|
||||
void (*Setkey) (void *, const u_int8_t *, u_int16_t);
|
||||
void (*Reinit) (void *, const u_int8_t *, u_int16_t);
|
||||
int (*Update) (void *, const u_int8_t *, u_int16_t);
|
||||
void (*Final) (u_int8_t *, void *);
|
||||
|
||||
struct auth_hash
|
||||
{
|
||||
int type;
|
||||
FAR char *name;
|
||||
uint16_t keysize;
|
||||
uint16_t hashsize;
|
||||
uint16_t authsize;
|
||||
uint16_t ctxsize;
|
||||
uint16_t blocksize;
|
||||
CODE void (*init) (FAR void *);
|
||||
CODE void (*setkey) (FAR void *, FAR const uint8_t *, uint16_t);
|
||||
CODE void (*reinit) (FAR void *, FAR const uint8_t *, uint16_t);
|
||||
CODE int (*update) (FAR void *, FAR const uint8_t *, uint16_t);
|
||||
CODE void (*final) (FAR uint8_t *, FAR void *);
|
||||
};
|
||||
|
||||
struct enc_xform {
|
||||
int type;
|
||||
char *name;
|
||||
u_int16_t blocksize;
|
||||
u_int16_t ivsize;
|
||||
u_int16_t minkey;
|
||||
u_int16_t maxkey;
|
||||
u_int16_t ctxsize;
|
||||
void (*encrypt) (caddr_t, u_int8_t *);
|
||||
void (*decrypt) (caddr_t, u_int8_t *);
|
||||
int (*setkey) (void *, u_int8_t *, int len);
|
||||
void (*reinit) (caddr_t, u_int8_t *);
|
||||
struct enc_xform
|
||||
{
|
||||
int type;
|
||||
FAR char *name;
|
||||
uint16_t blocksize;
|
||||
uint16_t ivsize;
|
||||
uint16_t minkey;
|
||||
uint16_t maxkey;
|
||||
uint16_t ctxsize;
|
||||
CODE void (*encrypt) (caddr_t, FAR uint8_t *);
|
||||
CODE void (*decrypt) (caddr_t, FAR uint8_t *);
|
||||
CODE int (*setkey) (void *, FAR uint8_t *, int len);
|
||||
CODE void (*reinit) (caddr_t, FAR uint8_t *);
|
||||
};
|
||||
|
||||
struct comp_algo {
|
||||
int type;
|
||||
char *name;
|
||||
size_t minlen;
|
||||
u_int32_t (*compress) (u_int8_t *, u_int32_t, u_int8_t **);
|
||||
u_int32_t (*decompress) (u_int8_t *, u_int32_t, u_int8_t **);
|
||||
struct comp_algo
|
||||
{
|
||||
int type;
|
||||
FAR char *name;
|
||||
size_t minlen;
|
||||
CODE uint32_t (*compress) (FAR uint8_t *, uint32_t, FAR uint8_t **);
|
||||
CODE uint32_t (*decompress) (FAR uint8_t *, uint32_t, FAR uint8_t **);
|
||||
};
|
||||
|
||||
union authctx {
|
||||
MD5_CTX md5ctx;
|
||||
SHA1_CTX sha1ctx;
|
||||
RMD160_CTX rmd160ctx;
|
||||
SHA2_CTX sha2_ctx;
|
||||
AES_GMAC_CTX aes_gmac_ctx;
|
||||
union authctx
|
||||
{
|
||||
MD5_CTX md5ctx;
|
||||
SHA1_CTX sha1ctx;
|
||||
RMD160_CTX rmd160ctx;
|
||||
SHA2_CTX sha2_ctx;
|
||||
AES_GMAC_CTX aes_gmac_ctx;
|
||||
};
|
||||
|
||||
extern const struct enc_xform enc_xform_3des;
|
||||
@@ -108,4 +118,4 @@ extern const struct auth_hash auth_hash_chacha20_poly1305;
|
||||
|
||||
extern const struct comp_algo comp_algo_deflate;
|
||||
|
||||
#endif /* _CRYPTO_XFORM_H_ */
|
||||
#endif /* __INCLUDE_CRYPTO_XFORM_H */
|
||||
|
||||
Reference in New Issue
Block a user