mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-22 21:23:07 +03:00
git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@116 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
130 lines
3.8 KiB
C
130 lines
3.8 KiB
C
/*
|
|
* Copyright(C) 2006 Cameron Rich
|
|
*
|
|
* This library is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
/**
|
|
* @file crypto.h
|
|
*/
|
|
|
|
#ifndef HEADER_CRYPTO_H
|
|
#define HEADER_CRYPTO_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include "os_port.h"
|
|
|
|
/**************************************************************************
|
|
* AES declarations
|
|
**************************************************************************/
|
|
|
|
#define AES_MAXROUNDS 14
|
|
#define AES_BLOCKSIZE 16
|
|
#define AES_IV_SIZE 16
|
|
|
|
typedef struct aes_key_st
|
|
{
|
|
uint16_t rounds;
|
|
uint16_t key_size;
|
|
uint32_t ks[(AES_MAXROUNDS+1)*8];
|
|
uint8_t iv[AES_IV_SIZE];
|
|
} AES_CTX;
|
|
|
|
typedef enum
|
|
{
|
|
AES_MODE_128,
|
|
AES_MODE_256
|
|
} AES_MODE;
|
|
|
|
void AES_set_key(AES_CTX *ctx, const uint8_t *key,
|
|
const uint8_t *iv, AES_MODE mode);
|
|
void AES_cbc_encrypt(AES_CTX *ctx, const uint8_t *msg,
|
|
uint8_t *out, int length);
|
|
void AES_cbc_decrypt(AES_CTX *ks, const uint8_t *in, uint8_t *out, int length);
|
|
void AES_convert_key(AES_CTX *ctx);
|
|
|
|
/**************************************************************************
|
|
* RC4 declarations
|
|
**************************************************************************/
|
|
|
|
typedef struct
|
|
{
|
|
uint8_t x, y, m[256];
|
|
} RC4_CTX;
|
|
|
|
void RC4_setup(RC4_CTX *s, const uint8_t *key, int length);
|
|
void RC4_crypt(RC4_CTX *s, const uint8_t *msg, uint8_t *data, int length);
|
|
|
|
/**************************************************************************
|
|
* SHA1 declarations
|
|
**************************************************************************/
|
|
|
|
#define SHA1_SIZE 20
|
|
|
|
/*
|
|
* This structure will hold context information for the SHA-1
|
|
* hashing operation
|
|
*/
|
|
typedef struct
|
|
{
|
|
uint32_t Intermediate_Hash[SHA1_SIZE/4]; /* Message Digest */
|
|
uint32_t Length_Low; /* Message length in bits */
|
|
uint32_t Length_High; /* Message length in bits */
|
|
uint16_t Message_Block_Index; /* Index into message block array */
|
|
uint8_t Message_Block[64]; /* 512-bit message blocks */
|
|
} SHA1_CTX;
|
|
|
|
void SHA1_Init(SHA1_CTX *);
|
|
void SHA1_Update(SHA1_CTX *, const uint8_t * msg, int len);
|
|
void SHA1_Final(uint8_t *digest, SHA1_CTX *);
|
|
|
|
/**************************************************************************
|
|
* MD5 declarations
|
|
**************************************************************************/
|
|
|
|
/* MD5 context. */
|
|
|
|
#define MD5_SIZE 16
|
|
|
|
typedef struct
|
|
{
|
|
uint32_t state[4]; /* state (ABCD) */
|
|
uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */
|
|
uint8_t buffer[64]; /* input buffer */
|
|
} MD5_CTX;
|
|
|
|
EXP_FUNC void STDCALL MD5_Init(MD5_CTX *);
|
|
EXP_FUNC void STDCALL MD5_Update(MD5_CTX *, const uint8_t *msg, int len);
|
|
EXP_FUNC void STDCALL MD5_Final(uint8_t *digest, MD5_CTX *);
|
|
|
|
/**************************************************************************
|
|
* HMAC declarations
|
|
**************************************************************************/
|
|
void hmac_md5(const uint8_t *msg, int length, const uint8_t *key,
|
|
int key_len, uint8_t *digest);
|
|
void hmac_sha1(const uint8_t *msg, int length, const uint8_t *key,
|
|
int key_len, uint8_t *digest);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|