MOD: refactoring continued as I moved the wolfssl-lib to more consistent directory
This commit is contained in:
parent
3199f30006
commit
ea3948164d
|
@ -9,4 +9,4 @@ libwebp
|
||||||
.DS_Store
|
.DS_Store
|
||||||
wolfssl-git
|
wolfssl-git
|
||||||
var/
|
var/
|
||||||
dist/
|
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
# this CMake file is the root, and is used to create the bin folder
|
|
||||||
cmake_minimum_required(VERSION 3.4.1)
|
|
||||||
|
|
||||||
set(CMAKE_VERBOSE_MAKEFILE on)
|
|
||||||
|
|
||||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/main/cpp/wolfssl-oem)
|
|
||||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/main/cpp/wolfcrypt)
|
|
|
@ -1,34 +1,20 @@
|
||||||
DEVELOPER README
|
DEVELOPER README
|
||||||
================
|
================
|
||||||
|
|
||||||
* Generates a shared library (libwolfssl.so)
|
Generates a shared library (libwolfssl-jni.so)
|
||||||
|
|
||||||
|
|
||||||
Requirements
|
|
||||||
------------
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
How To Build
|
How To Build
|
||||||
------------
|
------------
|
||||||
|
|
||||||
WOLFSSL
|
* $ ./build.sh
|
||||||
|
|
||||||
1. $ ./get_wolfssl_src.sh
|
|
||||||
2. $ gradle build
|
|
||||||
3. prepare for distribution
|
|
||||||
- copy files from output directory to ./dist
|
|
||||||
- bulld/intermediates/cmake/release/obj/x86_64/libwolfssl.so
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OUPUT
|
OUPUT
|
||||||
-----
|
-----
|
||||||
|
|
||||||
bulld/intermediates/cmake/release/obj/x86_64/libwolfssl.so
|
* dist/wolfssl-jni_DATE.../
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
BIN
wolfssl-jni/dist/wolfssl-jni_20190207_151003742/debug/arm64-v8a/libwolfssl-jni.so
vendored
Executable file
BIN
wolfssl-jni/dist/wolfssl-jni_20190207_151003742/debug/arm64-v8a/libwolfssl-jni.so
vendored
Executable file
Binary file not shown.
BIN
wolfssl-jni/dist/wolfssl-jni_20190207_151003742/debug/armeabi-v7a/libwolfssl-jni.so
vendored
Executable file
BIN
wolfssl-jni/dist/wolfssl-jni_20190207_151003742/debug/armeabi-v7a/libwolfssl-jni.so
vendored
Executable file
Binary file not shown.
BIN
wolfssl-jni/dist/wolfssl-jni_20190207_151003742/debug/x86/libwolfssl-jni.so
vendored
Executable file
BIN
wolfssl-jni/dist/wolfssl-jni_20190207_151003742/debug/x86/libwolfssl-jni.so
vendored
Executable file
Binary file not shown.
BIN
wolfssl-jni/dist/wolfssl-jni_20190207_151003742/debug/x86_64/libwolfssl-jni.so
vendored
Executable file
BIN
wolfssl-jni/dist/wolfssl-jni_20190207_151003742/debug/x86_64/libwolfssl-jni.so
vendored
Executable file
Binary file not shown.
BIN
wolfssl-jni/dist/wolfssl-jni_20190207_151003742/release/arm64-v8a/libwolfssl-jni.so
vendored
Executable file
BIN
wolfssl-jni/dist/wolfssl-jni_20190207_151003742/release/arm64-v8a/libwolfssl-jni.so
vendored
Executable file
Binary file not shown.
BIN
wolfssl-jni/dist/wolfssl-jni_20190207_151003742/release/armeabi-v7a/libwolfssl-jni.so
vendored
Executable file
BIN
wolfssl-jni/dist/wolfssl-jni_20190207_151003742/release/armeabi-v7a/libwolfssl-jni.so
vendored
Executable file
Binary file not shown.
BIN
wolfssl-jni/dist/wolfssl-jni_20190207_151003742/release/x86/libwolfssl-jni.so
vendored
Executable file
BIN
wolfssl-jni/dist/wolfssl-jni_20190207_151003742/release/x86/libwolfssl-jni.so
vendored
Executable file
Binary file not shown.
BIN
wolfssl-jni/dist/wolfssl-jni_20190207_151003742/release/x86_64/libwolfssl-jni.so
vendored
Executable file
BIN
wolfssl-jni/dist/wolfssl-jni_20190207_151003742/release/x86_64/libwolfssl-jni.so
vendored
Executable file
Binary file not shown.
|
@ -1,42 +0,0 @@
|
||||||
ROOT_PATH := $(call my-dir)
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := libwolfssl
|
|
||||||
LOCAL_PATH := ../../src/.libs
|
|
||||||
LOCAL_SRC_FILES := libwolfssl.a
|
|
||||||
|
|
||||||
include $(PREBUILT_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := libwolfcrypt-jni
|
|
||||||
LOCAL_PATH := $(ROOT_PATH)
|
|
||||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include ../../../wolfssl
|
|
||||||
LOCAL_SRC_FILES := jni_fips.c \
|
|
||||||
jni_native_struct.c \
|
|
||||||
jni_aes.c \
|
|
||||||
jni_des3.c \
|
|
||||||
jni_md5.c \
|
|
||||||
jni_sha.c \
|
|
||||||
jni_hmac.c \
|
|
||||||
jni_rng.c \
|
|
||||||
jni_rsa.c \
|
|
||||||
jni_dh.c \
|
|
||||||
jni_ecc.c \
|
|
||||||
jni_asn.c \
|
|
||||||
jni_logging.c
|
|
||||||
|
|
||||||
LOCAL_CFLAGS := -DHAVE_CONFIG_H -Wall -Wno-unused
|
|
||||||
LOCAL_LDLIBS := -llog
|
|
||||||
|
|
||||||
LOCAL_STATIC_LIBRARIES := libwolfssl
|
|
||||||
|
|
||||||
include $(BUILD_SHARED_LIBRARY)
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
|
|
|
@ -1,100 +0,0 @@
|
||||||
TOP_PATH := $(call my-dir)/..
|
|
||||||
|
|
||||||
WOLFSSL_DIR := wolfssl
|
|
||||||
|
|
||||||
# Build wolfSSL shared library
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
LOCAL_PATH := $(TOP_PATH)/$(WOLFSSL_DIR)
|
|
||||||
LOCAL_MODULE := libwolfssl
|
|
||||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
|
|
||||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)
|
|
||||||
LOCAL_CFLAGS := -DOPENSSL_EXTRA -DWOLFSSL_DTLS -D_POSIX_THREADS -DNDEBUG \
|
|
||||||
-DPERSIST_SESSION_CACHE -DPERSIST_CERT_CACHE -DATOMIC_USER \
|
|
||||||
-DHAVE_PK_CALLBACKS -DNO_DSA -DHAVE_ECC -DTFM_ECC256 \
|
|
||||||
-DECC_SHAMIR -DNO_MD4 -DNO_HC128 -DNO_RABBIT \
|
|
||||||
-DHAVE_OCSP -DHAVE_CRL -DWOLFSSL_JNI -DHAVE_DH \
|
|
||||||
-Wall
|
|
||||||
LOCAL_SRC_FILES := src/crl.c \
|
|
||||||
src/internal.c \
|
|
||||||
src/io.c \
|
|
||||||
src/keys.c \
|
|
||||||
src/ocsp.c \
|
|
||||||
src/sniffer.c \
|
|
||||||
src/ssl.c \
|
|
||||||
src/tls.c \
|
|
||||||
wolfcrypt/src/aes.c \
|
|
||||||
wolfcrypt/src/arc4.c \
|
|
||||||
wolfcrypt/src/asm.c \
|
|
||||||
wolfcrypt/src/asn.c \
|
|
||||||
wolfcrypt/src/blake2b.c \
|
|
||||||
wolfcrypt/src/camellia.c \
|
|
||||||
wolfcrypt/src/chacha.c \
|
|
||||||
wolfcrypt/src/chacha20_poly1305.c \
|
|
||||||
wolfcrypt/src/coding.c \
|
|
||||||
wolfcrypt/src/compress.c \
|
|
||||||
wolfcrypt/src/curve25519.c \
|
|
||||||
wolfcrypt/src/des3.c \
|
|
||||||
wolfcrypt/src/dh.c \
|
|
||||||
wolfcrypt/src/dsa.c \
|
|
||||||
wolfcrypt/src/ecc.c \
|
|
||||||
wolfcrypt/src/ecc_fp.c \
|
|
||||||
wolfcrypt/src/ed25519.c \
|
|
||||||
wolfcrypt/src/error.c \
|
|
||||||
wolfcrypt/src/fe_low_mem.c \
|
|
||||||
wolfcrypt/src/fe_operations.c \
|
|
||||||
wolfcrypt/src/ge_low_mem.c \
|
|
||||||
wolfcrypt/src/ge_operations.c \
|
|
||||||
wolfcrypt/src/hash.c \
|
|
||||||
wolfcrypt/src/hc128.c \
|
|
||||||
wolfcrypt/src/hmac.c \
|
|
||||||
wolfcrypt/src/idea.c \
|
|
||||||
wolfcrypt/src/integer.c \
|
|
||||||
wolfcrypt/src/logging.c \
|
|
||||||
wolfcrypt/src/md2.c \
|
|
||||||
wolfcrypt/src/md4.c \
|
|
||||||
wolfcrypt/src/md5.c \
|
|
||||||
wolfcrypt/src/memory.c \
|
|
||||||
wolfcrypt/src/misc.c \
|
|
||||||
wolfcrypt/src/pkcs7.c \
|
|
||||||
wolfcrypt/src/pkcs12.c \
|
|
||||||
wolfcrypt/src/poly1305.c \
|
|
||||||
wolfcrypt/src/pwdbased.c \
|
|
||||||
wolfcrypt/src/rabbit.c \
|
|
||||||
wolfcrypt/src/random.c \
|
|
||||||
wolfcrypt/src/ripemd.c \
|
|
||||||
wolfcrypt/src/rsa.c \
|
|
||||||
wolfcrypt/src/sha.c \
|
|
||||||
wolfcrypt/src/sha256.c \
|
|
||||||
wolfcrypt/src/sha512.c \
|
|
||||||
wolfcrypt/src/srp.c \
|
|
||||||
wolfcrypt/src/tfm.c \
|
|
||||||
wolfcrypt/src/wc_encrypt.c \
|
|
||||||
wolfcrypt/src/wc_port.c
|
|
||||||
include $(BUILD_SHARED_LIBRARY)
|
|
||||||
|
|
||||||
|
|
||||||
## Build wolfSSL JNI library
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
LOCAL_PATH := $(TOP_PATH)/wolfssljni
|
|
||||||
LOCAL_MODULE := libwolfssljni
|
|
||||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/native
|
|
||||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/native
|
|
||||||
LOCAL_SRC_FILES := native/com_wolfssl_WolfSSL.c \
|
|
||||||
native/com_wolfssl_WolfSSLContext.c \
|
|
||||||
native/com_wolfssl_WolfSSLSession.c \
|
|
||||||
native/com_wolfssl_wolfcrypt_ECC.c \
|
|
||||||
native/com_wolfssl_wolfcrypt_RSA.c
|
|
||||||
LOCAL_CFLAGS := -Wall -Os -DWOLFSSL_DTLS -DHAVE_ECC
|
|
||||||
LOCAL_SHARED_LIBRARIES := libwolfssl
|
|
||||||
include $(BUILD_SHARED_LIBRARY)
|
|
||||||
|
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
LOCAL_PATH := $(TOP_PATH)/jni
|
|
||||||
LOCAL_MODULE := libjnitest
|
|
||||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)
|
|
||||||
LOCAL_SRC_FILES := jnitest.c
|
|
||||||
LOCAL_CFLAGS := -Wall
|
|
||||||
LOCAL_SHARED_LIBRARIES := libwolfssl
|
|
||||||
include $(BUILD_SHARED_LIBRARY)
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
#
|
|
||||||
APP_ABI := all
|
|
||||||
#APP_ABI := armeabi armeabi-v7a x86 x86_64
|
|
||||||
#APP_ABI := mips mips64 arm64-v8a
|
|
||||||
#APP_ABI := arm64-v8a
|
|
|
@ -1,20 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# from src/main/cpp/
|
|
||||||
#
|
|
||||||
if [[ -z $1 ]]; then
|
|
||||||
echo "ERROR: missing parameter: branch to checkout required"
|
|
||||||
echo
|
|
||||||
echo "Known working branches:"
|
|
||||||
echo " v3.10.0-stable"
|
|
||||||
echo
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
CD=`pwd`
|
|
||||||
cd src/main/cpp/wolfssl-oem
|
|
||||||
git clone https://github.com/wolfSSL/wolfssl.git wolfssl-git
|
|
||||||
cd wolfssl-git
|
|
||||||
git checkout $1
|
|
||||||
git checkout -b building
|
|
||||||
cd $CD
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,83 @@
|
||||||
|
/* callbacks.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_CALLBACKS_H
|
||||||
|
#define WOLFSSL_CALLBACKS_H
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
enum { /* CALLBACK CONTSTANTS */
|
||||||
|
MAX_PACKETNAME_SZ = 24,
|
||||||
|
MAX_CIPHERNAME_SZ = 24,
|
||||||
|
MAX_TIMEOUT_NAME_SZ = 24,
|
||||||
|
MAX_PACKETS_HANDSHAKE = 14, /* 12 for client auth plus 2 alerts */
|
||||||
|
MAX_VALUE_SZ = 128, /* all handshake packets but Cert should
|
||||||
|
fit here */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct WOLFSSL;
|
||||||
|
|
||||||
|
typedef struct handShakeInfo_st {
|
||||||
|
struct WOLFSSL* ssl;
|
||||||
|
char cipherName[MAX_CIPHERNAME_SZ + 1]; /* negotiated cipher */
|
||||||
|
char packetNames[MAX_PACKETS_HANDSHAKE][MAX_PACKETNAME_SZ + 1];
|
||||||
|
/* SSL packet names */
|
||||||
|
int numberPackets; /* actual # of packets */
|
||||||
|
int negotiationError; /* cipher/parameter err */
|
||||||
|
} HandShakeInfo;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct timeval Timeval;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct packetInfo_st {
|
||||||
|
char packetName[MAX_PACKETNAME_SZ + 1]; /* SSL packet name */
|
||||||
|
Timeval timestamp; /* when it occurred */
|
||||||
|
unsigned char value[MAX_VALUE_SZ]; /* if fits, it's here */
|
||||||
|
unsigned char* bufferValue; /* otherwise here (non 0) */
|
||||||
|
int valueSz; /* sz of value or buffer */
|
||||||
|
} PacketInfo;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct timeoutInfo_st {
|
||||||
|
char timeoutName[MAX_TIMEOUT_NAME_SZ + 1]; /* timeout Name */
|
||||||
|
int flags; /* for future use */
|
||||||
|
int numberPackets; /* actual # of packets */
|
||||||
|
PacketInfo packets[MAX_PACKETS_HANDSHAKE]; /* list of all packets */
|
||||||
|
Timeval timeoutValue; /* timer that caused it */
|
||||||
|
} TimeoutInfo;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* WOLFSSL_CALLBACKS_H */
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,52 @@
|
||||||
|
/* crl.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_CRL_H
|
||||||
|
#define WOLFSSL_CRL_H
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_CRL
|
||||||
|
|
||||||
|
#include <wolfssl/ssl.h>
|
||||||
|
#include <wolfssl/wolfcrypt/asn.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct WOLFSSL_CRL WOLFSSL_CRL;
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL int InitCRL(WOLFSSL_CRL*, WOLFSSL_CERT_MANAGER*);
|
||||||
|
WOLFSSL_LOCAL void FreeCRL(WOLFSSL_CRL*, int dynamic);
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL int LoadCRL(WOLFSSL_CRL* crl, const char* path, int type, int mon);
|
||||||
|
WOLFSSL_LOCAL int BufferLoadCRL(WOLFSSL_CRL*, const byte*, long, int);
|
||||||
|
WOLFSSL_LOCAL int CheckCertCRL(WOLFSSL_CRL*, DecodedCert*);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAVE_CRL */
|
||||||
|
#endif /* WOLFSSL_CRL_H */
|
|
@ -0,0 +1,185 @@
|
||||||
|
/* error-ssl.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_ERROR_H
|
||||||
|
#define WOLFSSL_ERROR_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/error-crypt.h> /* pull in wolfCrypt errors */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum wolfSSL_ErrorCodes {
|
||||||
|
INPUT_CASE_ERROR = -301, /* process input state error */
|
||||||
|
PREFIX_ERROR = -302, /* bad index to key rounds */
|
||||||
|
MEMORY_ERROR = -303, /* out of memory */
|
||||||
|
VERIFY_FINISHED_ERROR = -304, /* verify problem on finished */
|
||||||
|
VERIFY_MAC_ERROR = -305, /* verify mac problem */
|
||||||
|
PARSE_ERROR = -306, /* parse error on header */
|
||||||
|
UNKNOWN_HANDSHAKE_TYPE = -307, /* weird handshake type */
|
||||||
|
SOCKET_ERROR_E = -308, /* error state on socket */
|
||||||
|
SOCKET_NODATA = -309, /* expected data, not there */
|
||||||
|
INCOMPLETE_DATA = -310, /* don't have enough data to
|
||||||
|
complete task */
|
||||||
|
UNKNOWN_RECORD_TYPE = -311, /* unknown type in record hdr */
|
||||||
|
DECRYPT_ERROR = -312, /* error during decryption */
|
||||||
|
FATAL_ERROR = -313, /* recvd alert fatal error */
|
||||||
|
ENCRYPT_ERROR = -314, /* error during encryption */
|
||||||
|
FREAD_ERROR = -315, /* fread problem */
|
||||||
|
NO_PEER_KEY = -316, /* need peer's key */
|
||||||
|
NO_PRIVATE_KEY = -317, /* need the private key */
|
||||||
|
RSA_PRIVATE_ERROR = -318, /* error during rsa priv op */
|
||||||
|
NO_DH_PARAMS = -319, /* server missing DH params */
|
||||||
|
BUILD_MSG_ERROR = -320, /* build message failure */
|
||||||
|
|
||||||
|
BAD_HELLO = -321, /* client hello malformed */
|
||||||
|
DOMAIN_NAME_MISMATCH = -322, /* peer subject name mismatch */
|
||||||
|
WANT_READ = -323, /* want read, call again */
|
||||||
|
NOT_READY_ERROR = -324, /* handshake layer not ready */
|
||||||
|
PMS_VERSION_ERROR = -325, /* pre m secret version error */
|
||||||
|
VERSION_ERROR = -326, /* record layer version error */
|
||||||
|
WANT_WRITE = -327, /* want write, call again */
|
||||||
|
BUFFER_ERROR = -328, /* malformed buffer input */
|
||||||
|
VERIFY_CERT_ERROR = -329, /* verify cert error */
|
||||||
|
VERIFY_SIGN_ERROR = -330, /* verify sign error */
|
||||||
|
CLIENT_ID_ERROR = -331, /* psk client identity error */
|
||||||
|
SERVER_HINT_ERROR = -332, /* psk server hint error */
|
||||||
|
PSK_KEY_ERROR = -333, /* psk key error */
|
||||||
|
ZLIB_INIT_ERROR = -334, /* zlib init error */
|
||||||
|
ZLIB_COMPRESS_ERROR = -335, /* zlib compression error */
|
||||||
|
ZLIB_DECOMPRESS_ERROR = -336, /* zlib decompression error */
|
||||||
|
|
||||||
|
GETTIME_ERROR = -337, /* gettimeofday failed ??? */
|
||||||
|
GETITIMER_ERROR = -338, /* getitimer failed ??? */
|
||||||
|
SIGACT_ERROR = -339, /* sigaction failed ??? */
|
||||||
|
SETITIMER_ERROR = -340, /* setitimer failed ??? */
|
||||||
|
LENGTH_ERROR = -341, /* record layer length error */
|
||||||
|
PEER_KEY_ERROR = -342, /* can't decode peer key */
|
||||||
|
ZERO_RETURN = -343, /* peer sent close notify */
|
||||||
|
SIDE_ERROR = -344, /* wrong client/server type */
|
||||||
|
NO_PEER_CERT = -345, /* peer didn't send key */
|
||||||
|
NTRU_KEY_ERROR = -346, /* NTRU key error */
|
||||||
|
NTRU_DRBG_ERROR = -347, /* NTRU drbg error */
|
||||||
|
NTRU_ENCRYPT_ERROR = -348, /* NTRU encrypt error */
|
||||||
|
NTRU_DECRYPT_ERROR = -349, /* NTRU decrypt error */
|
||||||
|
ECC_CURVETYPE_ERROR = -350, /* Bad ECC Curve Type */
|
||||||
|
ECC_CURVE_ERROR = -351, /* Bad ECC Curve */
|
||||||
|
ECC_PEERKEY_ERROR = -352, /* Bad Peer ECC Key */
|
||||||
|
ECC_MAKEKEY_ERROR = -353, /* Bad Make ECC Key */
|
||||||
|
ECC_EXPORT_ERROR = -354, /* Bad ECC Export Key */
|
||||||
|
ECC_SHARED_ERROR = -355, /* Bad ECC Shared Secret */
|
||||||
|
NOT_CA_ERROR = -357, /* Not a CA cert error */
|
||||||
|
BAD_PATH_ERROR = -358, /* Bad path for opendir */
|
||||||
|
BAD_CERT_MANAGER_ERROR = -359, /* Bad Cert Manager */
|
||||||
|
OCSP_CERT_REVOKED = -360, /* OCSP Certificate revoked */
|
||||||
|
CRL_CERT_REVOKED = -361, /* CRL Certificate revoked */
|
||||||
|
CRL_MISSING = -362, /* CRL Not loaded */
|
||||||
|
MONITOR_SETUP_E = -363, /* CRL Monitor setup error */
|
||||||
|
THREAD_CREATE_E = -364, /* Thread Create Error */
|
||||||
|
OCSP_NEED_URL = -365, /* OCSP need an URL for lookup */
|
||||||
|
OCSP_CERT_UNKNOWN = -366, /* OCSP responder doesn't know */
|
||||||
|
OCSP_LOOKUP_FAIL = -367, /* OCSP lookup not successful */
|
||||||
|
MAX_CHAIN_ERROR = -368, /* max chain depth exceeded */
|
||||||
|
COOKIE_ERROR = -369, /* dtls cookie error */
|
||||||
|
SEQUENCE_ERROR = -370, /* dtls sequence error */
|
||||||
|
SUITES_ERROR = -371, /* suites pointer error */
|
||||||
|
SSL_NO_PEM_HEADER = -372, /* no PEM header found */
|
||||||
|
OUT_OF_ORDER_E = -373, /* out of order message */
|
||||||
|
BAD_KEA_TYPE_E = -374, /* bad KEA type found */
|
||||||
|
SANITY_CIPHER_E = -375, /* sanity check on cipher error */
|
||||||
|
RECV_OVERFLOW_E = -376, /* RXCB returned more than rqed */
|
||||||
|
GEN_COOKIE_E = -377, /* Generate Cookie Error */
|
||||||
|
NO_PEER_VERIFY = -378, /* Need peer cert verify Error */
|
||||||
|
FWRITE_ERROR = -379, /* fwrite problem */
|
||||||
|
CACHE_MATCH_ERROR = -380, /* chache hdr match error */
|
||||||
|
UNKNOWN_SNI_HOST_NAME_E = -381, /* Unrecognized host name Error */
|
||||||
|
UNKNOWN_MAX_FRAG_LEN_E = -382, /* Unrecognized max frag len Error */
|
||||||
|
KEYUSE_SIGNATURE_E = -383, /* KeyUse digSignature error */
|
||||||
|
KEYUSE_ENCIPHER_E = -385, /* KeyUse keyEncipher error */
|
||||||
|
EXTKEYUSE_AUTH_E = -386, /* ExtKeyUse server|client_auth */
|
||||||
|
SEND_OOB_READ_E = -387, /* Send Cb out of bounds read */
|
||||||
|
SECURE_RENEGOTIATION_E = -388, /* Invalid Renegotiation Info */
|
||||||
|
SESSION_TICKET_LEN_E = -389, /* Session Ticket too large */
|
||||||
|
SESSION_TICKET_EXPECT_E = -390, /* Session Ticket missing */
|
||||||
|
SCR_DIFFERENT_CERT_E = -391, /* SCR Different cert error */
|
||||||
|
SESSION_SECRET_CB_E = -392, /* Session secret Cb fcn failure */
|
||||||
|
NO_CHANGE_CIPHER_E = -393, /* Finished before change cipher */
|
||||||
|
SANITY_MSG_E = -394, /* Sanity check on msg order error */
|
||||||
|
DUPLICATE_MSG_E = -395, /* Duplicate message error */
|
||||||
|
SNI_UNSUPPORTED = -396, /* SSL 3.0 does not support SNI */
|
||||||
|
SOCKET_PEER_CLOSED_E = -397, /* Underlying transport closed */
|
||||||
|
|
||||||
|
BAD_TICKET_KEY_CB_SZ = -398, /* Bad session ticket key cb size */
|
||||||
|
BAD_TICKET_MSG_SZ = -399, /* Bad session ticket msg size */
|
||||||
|
BAD_TICKET_ENCRYPT = -400, /* Bad user ticket encrypt */
|
||||||
|
|
||||||
|
DH_KEY_SIZE_E = -401, /* DH Key too small */
|
||||||
|
SNI_ABSENT_ERROR = -402, /* No SNI request. */
|
||||||
|
RSA_SIGN_FAULT = -403, /* RSA Sign fault */
|
||||||
|
HANDSHAKE_SIZE_ERROR = -404, /* Handshake message too large */
|
||||||
|
|
||||||
|
UNKNOWN_ALPN_PROTOCOL_NAME_E = -405, /* Unrecognized protocol name Error*/
|
||||||
|
BAD_CERTIFICATE_STATUS_ERROR = -406, /* Bad certificate status message */
|
||||||
|
OCSP_INVALID_STATUS = -407, /* Invalid OCSP Status */
|
||||||
|
|
||||||
|
RSA_KEY_SIZE_E = -409, /* RSA key too small */
|
||||||
|
ECC_KEY_SIZE_E = -410, /* ECC key too small */
|
||||||
|
|
||||||
|
DTLS_EXPORT_VER_E = -411, /* export version error */
|
||||||
|
INPUT_SIZE_E = -412, /* input size too big error */
|
||||||
|
CTX_INIT_MUTEX_E = -413, /* initialize ctx mutex error */
|
||||||
|
EXT_MASTER_SECRET_NEEDED_E = -414, /* need EMS enabled to resume */
|
||||||
|
DTLS_POOL_SZ_E = -415, /* exceeded DTLS pool size */
|
||||||
|
DECODE_E = -416, /* decode handshake message error */
|
||||||
|
/* add strings to wolfSSL_ERR_reason_error_string in internal.c !!!!! */
|
||||||
|
|
||||||
|
/* begin negotiation parameter errors */
|
||||||
|
UNSUPPORTED_SUITE = -500, /* unsupported cipher suite */
|
||||||
|
MATCH_SUITE_ERROR = -501, /* can't match cipher suite */
|
||||||
|
COMPRESSION_ERROR = -502 /* compression mismatch */
|
||||||
|
/* end negotiation parameter errors only 10 for now */
|
||||||
|
/* add strings to wolfSSL_ERR_reason_error_string in internal.c !!!!! */
|
||||||
|
|
||||||
|
/* no error stings go down here, add above negotiation errors !!!! */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_CALLBACKS
|
||||||
|
enum {
|
||||||
|
MIN_PARAM_ERR = UNSUPPORTED_SUITE,
|
||||||
|
MAX_PARAM_ERR = MIN_PARAM_ERR - 10
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL
|
||||||
|
void SetErrorString(int err, char* buff);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* wolfSSL_ERROR_H */
|
|
@ -0,0 +1,31 @@
|
||||||
|
# vim:ft=automake
|
||||||
|
# All paths should be given relative to the root
|
||||||
|
#
|
||||||
|
|
||||||
|
include wolfssl/wolfcrypt/include.am
|
||||||
|
include wolfssl/openssl/include.am
|
||||||
|
|
||||||
|
EXTRA_DIST+= wolfssl/sniffer_error.rc
|
||||||
|
|
||||||
|
nobase_include_HEADERS+= \
|
||||||
|
wolfssl/error-ssl.h \
|
||||||
|
wolfssl/ssl.h \
|
||||||
|
wolfssl/sniffer_error.h \
|
||||||
|
wolfssl/sniffer.h \
|
||||||
|
wolfssl/callbacks.h \
|
||||||
|
wolfssl/certs_test.h \
|
||||||
|
wolfssl/test.h \
|
||||||
|
wolfssl/version.h \
|
||||||
|
wolfssl/ocsp.h \
|
||||||
|
wolfssl/crl.h
|
||||||
|
|
||||||
|
noinst_HEADERS+= \
|
||||||
|
wolfssl/internal.h
|
||||||
|
|
||||||
|
# For distro build don't install options.h.
|
||||||
|
# It depends on the architecture and conflicts with Multi-Arch.
|
||||||
|
if BUILD_DISTRO
|
||||||
|
noinst_HEADERS+= wolfssl/options.h
|
||||||
|
else
|
||||||
|
nobase_include_HEADERS+= wolfssl/options.h
|
||||||
|
endif
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,56 @@
|
||||||
|
/* ocsp.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* wolfSSL OCSP API */
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_OCSP_H
|
||||||
|
#define WOLFSSL_OCSP_H
|
||||||
|
|
||||||
|
#ifdef HAVE_OCSP
|
||||||
|
|
||||||
|
#include <wolfssl/ssl.h>
|
||||||
|
#include <wolfssl/wolfcrypt/asn.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct WOLFSSL_OCSP WOLFSSL_OCSP;
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL int InitOCSP(WOLFSSL_OCSP*, WOLFSSL_CERT_MANAGER*);
|
||||||
|
WOLFSSL_LOCAL void FreeOCSP(WOLFSSL_OCSP*, int dynamic);
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL int CheckCertOCSP(WOLFSSL_OCSP*, DecodedCert*,
|
||||||
|
WOLFSSL_BUFFER_INFO* responseBuffer);
|
||||||
|
WOLFSSL_LOCAL int CheckOcspRequest(WOLFSSL_OCSP* ocsp,
|
||||||
|
OcspRequest* ocspRequest, WOLFSSL_BUFFER_INFO* responseBuffer);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* HAVE_OCSP */
|
||||||
|
#endif /* WOLFSSL_OCSP_H */
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,101 @@
|
||||||
|
/* sniffer.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_SNIFFER_H
|
||||||
|
#define WOLFSSL_SNIFFER_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/settings.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#ifdef SSL_SNIFFER_EXPORTS
|
||||||
|
#define SSL_SNIFFER_API __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define SSL_SNIFFER_API __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define SSL_SNIFFER_API
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* @param typeK: (formerly keyType) was shadowing a global declaration in
|
||||||
|
* wolfssl/wolfcrypt/asn.h line 175
|
||||||
|
*/
|
||||||
|
WOLFSSL_API
|
||||||
|
SSL_SNIFFER_API int ssl_SetPrivateKey(const char* address, int port,
|
||||||
|
const char* keyFile, int typeK,
|
||||||
|
const char* password, char* error);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
SSL_SNIFFER_API int ssl_SetNamedPrivateKey(const char* name,
|
||||||
|
const char* address, int port,
|
||||||
|
const char* keyFile, int typeK,
|
||||||
|
const char* password, char* error);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
SSL_SNIFFER_API int ssl_DecodePacket(const unsigned char* packet, int length,
|
||||||
|
unsigned char** data, char* error);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
SSL_SNIFFER_API int ssl_FreeDecodeBuffer(unsigned char** data, char* error);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
SSL_SNIFFER_API int ssl_FreeZeroDecodeBuffer(unsigned char** data, int sz,
|
||||||
|
char* error);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
SSL_SNIFFER_API int ssl_Trace(const char* traceFile, char* error);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
SSL_SNIFFER_API int ssl_EnableRecovery(int onOff, int maxMemory, char* error);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
SSL_SNIFFER_API int ssl_GetSessionStats(unsigned int* active,
|
||||||
|
unsigned int* total,
|
||||||
|
unsigned int* peak,
|
||||||
|
unsigned int* maxSessions,
|
||||||
|
unsigned int* missedData,
|
||||||
|
unsigned int* reassemblyMemory,
|
||||||
|
char* error);
|
||||||
|
|
||||||
|
WOLFSSL_API void ssl_InitSniffer(void);
|
||||||
|
|
||||||
|
WOLFSSL_API void ssl_FreeSniffer(void);
|
||||||
|
|
||||||
|
|
||||||
|
/* ssl_SetPrivateKey typeKs */
|
||||||
|
enum {
|
||||||
|
FILETYPE_PEM = 1,
|
||||||
|
FILETYPE_DER = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* wolfSSL_SNIFFER_H */
|
||||||
|
|
|
@ -0,0 +1,125 @@
|
||||||
|
/* sniffer_error.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_SNIFFER_ERROR_H
|
||||||
|
#define WOLFSSL_SNIFFER_ERROR_H
|
||||||
|
|
||||||
|
/* need to have errors as #defines since .rc files can't handle enums */
|
||||||
|
/* need to start at 1 and go in order for same reason */
|
||||||
|
|
||||||
|
#define MEMORY_STR 1
|
||||||
|
#define NEW_SERVER_STR 2
|
||||||
|
#define IP_CHECK_STR 3
|
||||||
|
#define SERVER_NOT_REG_STR 4
|
||||||
|
#define TCP_CHECK_STR 5
|
||||||
|
#define SERVER_PORT_NOT_REG_STR 6
|
||||||
|
#define RSA_DECRYPT_STR 7
|
||||||
|
#define RSA_DECODE_STR 8
|
||||||
|
#define BAD_CIPHER_SPEC_STR 9
|
||||||
|
#define SERVER_HELLO_INPUT_STR 10
|
||||||
|
|
||||||
|
#define BAD_SESSION_RESUME_STR 11
|
||||||
|
#define SERVER_DID_RESUMPTION_STR 12
|
||||||
|
#define CLIENT_HELLO_INPUT_STR 13
|
||||||
|
#define CLIENT_RESUME_TRY_STR 14
|
||||||
|
#define HANDSHAKE_INPUT_STR 15
|
||||||
|
#define GOT_HELLO_VERIFY_STR 16
|
||||||
|
#define GOT_SERVER_HELLO_STR 17
|
||||||
|
#define GOT_CERT_REQ_STR 18
|
||||||
|
#define GOT_SERVER_KEY_EX_STR 19
|
||||||
|
#define GOT_CERT_STR 20
|
||||||
|
|
||||||
|
#define GOT_SERVER_HELLO_DONE_STR 21
|
||||||
|
#define GOT_FINISHED_STR 22
|
||||||
|
#define GOT_CLIENT_HELLO_STR 23
|
||||||
|
#define GOT_CLIENT_KEY_EX_STR 24
|
||||||
|
#define GOT_CERT_VER_STR 25
|
||||||
|
#define GOT_UNKNOWN_HANDSHAKE_STR 26
|
||||||
|
#define NEW_SESSION_STR 27
|
||||||
|
#define BAD_NEW_SSL_STR 28
|
||||||
|
#define GOT_PACKET_STR 29
|
||||||
|
#define NO_DATA_STR 30
|
||||||
|
|
||||||
|
#define BAD_SESSION_STR 31
|
||||||
|
#define GOT_OLD_CLIENT_HELLO_STR 32
|
||||||
|
#define OLD_CLIENT_INPUT_STR 33
|
||||||
|
#define OLD_CLIENT_OK_STR 34
|
||||||
|
#define BAD_OLD_CLIENT_STR 35
|
||||||
|
#define BAD_RECORD_HDR_STR 36
|
||||||
|
#define RECORD_INPUT_STR 37
|
||||||
|
#define GOT_HANDSHAKE_STR 38
|
||||||
|
#define BAD_HANDSHAKE_STR 39
|
||||||
|
#define GOT_CHANGE_CIPHER_STR 40
|
||||||
|
|
||||||
|
#define GOT_APP_DATA_STR 41
|
||||||
|
#define BAD_APP_DATA_STR 42
|
||||||
|
#define GOT_ALERT_STR 43
|
||||||
|
#define ANOTHER_MSG_STR 44
|
||||||
|
#define REMOVE_SESSION_STR 45
|
||||||
|
#define KEY_FILE_STR 46
|
||||||
|
#define BAD_IPVER_STR 47
|
||||||
|
#define BAD_PROTO_STR 48
|
||||||
|
#define PACKET_HDR_SHORT_STR 49
|
||||||
|
#define GOT_UNKNOWN_RECORD_STR 50
|
||||||
|
|
||||||
|
#define BAD_TRACE_FILE_STR 51
|
||||||
|
#define FATAL_ERROR_STR 52
|
||||||
|
#define PARTIAL_INPUT_STR 53
|
||||||
|
#define BUFFER_ERROR_STR 54
|
||||||
|
#define PARTIAL_ADD_STR 55
|
||||||
|
#define DUPLICATE_STR 56
|
||||||
|
#define OUT_OF_ORDER_STR 57
|
||||||
|
#define OVERLAP_DUPLICATE_STR 58
|
||||||
|
#define OVERLAP_REASSEMBLY_BEGIN_STR 59
|
||||||
|
#define OVERLAP_REASSEMBLY_END_STR 60
|
||||||
|
|
||||||
|
#define MISSED_CLIENT_HELLO_STR 61
|
||||||
|
#define GOT_HELLO_REQUEST_STR 62
|
||||||
|
#define GOT_SESSION_TICKET_STR 63
|
||||||
|
#define BAD_INPUT_STR 64
|
||||||
|
#define BAD_DECRYPT_TYPE 65
|
||||||
|
#define BAD_FINISHED_MSG 66
|
||||||
|
#define BAD_COMPRESSION_STR 67
|
||||||
|
#define BAD_DERIVE_STR 68
|
||||||
|
#define ACK_MISSED_STR 69
|
||||||
|
#define BAD_DECRYPT 70
|
||||||
|
|
||||||
|
#define DECRYPT_KEYS_NOT_SETUP 71
|
||||||
|
#define CLIENT_HELLO_LATE_KEY_STR 72
|
||||||
|
#define GOT_CERT_STATUS_STR 73
|
||||||
|
#define RSA_KEY_MISSING_STR 74
|
||||||
|
#define NO_SECURE_RENEGOTIATION 75
|
||||||
|
|
||||||
|
#define BAD_SESSION_STATS 76
|
||||||
|
#define REASSEMBLY_MAX_STR 77
|
||||||
|
#define DROPPING_LOST_FRAG_STR 78
|
||||||
|
#define DROPPING_PARTIAL_RECORD 79
|
||||||
|
#define CLEAR_ACK_FAULT 80
|
||||||
|
|
||||||
|
#define BAD_DECRYPT_SIZE 81
|
||||||
|
#define EXTENDED_MASTER_HASH_STR 82
|
||||||
|
/* !!!! also add to msgTable in sniffer.c and .rc file !!!! */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* wolfSSL_SNIFFER_ERROR_H */
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
|
||||||
|
STRINGTABLE
|
||||||
|
{
|
||||||
|
1, "Out of Memory"
|
||||||
|
2, "New SSL Sniffer Server Registered"
|
||||||
|
3, "Checking IP Header"
|
||||||
|
4, "SSL Sniffer Server Not Registered"
|
||||||
|
5, "Checking TCP Header"
|
||||||
|
|
||||||
|
6, "SSL Sniffer Server Port Not Registered"
|
||||||
|
7, "RSA Private Decrypt Error"
|
||||||
|
8, "RSA Private Decode Error"
|
||||||
|
9, "Set Cipher Spec Error"
|
||||||
|
10, "Server Hello Input Malformed"
|
||||||
|
|
||||||
|
11, "Couldn't Resume Session Error"
|
||||||
|
12, "Server Did Resumption"
|
||||||
|
13, "Client Hello Input Malformed"
|
||||||
|
14, "Client Trying to Resume"
|
||||||
|
15, "Handshake Input Malformed"
|
||||||
|
|
||||||
|
16, "Got Hello Verify msg"
|
||||||
|
17, "Got Server Hello msg"
|
||||||
|
18, "Got Cert Request msg"
|
||||||
|
19, "Got Server Key Exchange msg"
|
||||||
|
20, "Got Cert msg"
|
||||||
|
|
||||||
|
21, "Got Server Hello Done msg"
|
||||||
|
22, "Got Finished msg"
|
||||||
|
23, "Got Client Hello msg"
|
||||||
|
24, "Got Client Key Exchange msg"
|
||||||
|
25, "Got Cert Verify msg"
|
||||||
|
|
||||||
|
26, "Got Unknown Handshake msg"
|
||||||
|
27, "New SSL Sniffer Session created"
|
||||||
|
28, "Couldn't create new SSL"
|
||||||
|
29, "Got a Packet to decode"
|
||||||
|
30, "No data present"
|
||||||
|
|
||||||
|
31, "Session Not Found"
|
||||||
|
32, "Got an Old Client Hello msg"
|
||||||
|
33, "Old Client Hello Input Malformed"
|
||||||
|
34, "Old Client Hello OK"
|
||||||
|
35, "Bad Old Client Hello"
|
||||||
|
|
||||||
|
36, "Bad Record Header"
|
||||||
|
37, "Record Header Input Malformed"
|
||||||
|
38, "Got a HandShake msg"
|
||||||
|
39, "Bad HandShake msg"
|
||||||
|
40, "Got a Change Cipher Spec msg"
|
||||||
|
|
||||||
|
41, "Got Application Data msg"
|
||||||
|
42, "Bad Application Data"
|
||||||
|
43, "Got an Alert msg"
|
||||||
|
44, "Another msg to Process"
|
||||||
|
45, "Removing Session From Table"
|
||||||
|
|
||||||
|
46, "Bad Key File"
|
||||||
|
47, "Wrong IP Version"
|
||||||
|
48, "Wrong Protocol type"
|
||||||
|
49, "Packet Short for header processing"
|
||||||
|
50, "Got Unknown Record Type"
|
||||||
|
|
||||||
|
51, "Can't Open Trace File"
|
||||||
|
52, "Session in Fatal Error State"
|
||||||
|
53, "Partial SSL record received"
|
||||||
|
54, "Buffer Error, malformed input"
|
||||||
|
55, "Added to Partial Input"
|
||||||
|
|
||||||
|
56, "Received a Duplicate Packet"
|
||||||
|
57, "Received an Out of Order Packet"
|
||||||
|
58, "Received an Overlap Duplicate Packet"
|
||||||
|
59, "Received an Overlap Reassembly Begin Duplicate Packet"
|
||||||
|
60, "Received an Overlap Reassembly End Duplicate Packet"
|
||||||
|
|
||||||
|
61, "Missed the Client Hello Entirely"
|
||||||
|
62, "Got Hello Request msg"
|
||||||
|
63, "Got Session Ticket msg"
|
||||||
|
64, "Bad Input"
|
||||||
|
65, "Bad Decrypt Type"
|
||||||
|
|
||||||
|
66, "Bad Finished Message Processing"
|
||||||
|
67, "Bad Compression Type"
|
||||||
|
68, "Bad DeriveKeys Error"
|
||||||
|
69, "Saw ACK for Missing Packet Error"
|
||||||
|
70, "Bad Decrypt Operation"
|
||||||
|
|
||||||
|
71, "Decrypt Keys Not Set Up"
|
||||||
|
72, "Late Key Load Error"
|
||||||
|
73, "Got Certificate Status msg"
|
||||||
|
74, "RSA Key Missing Error"
|
||||||
|
75, "Secure Renegotiation Not Supported"
|
||||||
|
|
||||||
|
76, "Get Session Stats Failure"
|
||||||
|
77, "Reassembly Buffer Size Exceeded"
|
||||||
|
78, "Dropping Lost Fragment"
|
||||||
|
79, "Dropping Partial Record"
|
||||||
|
80, "Clear ACK Fault"
|
||||||
|
|
||||||
|
81, "Bad Decrypt Size"
|
||||||
|
82, "Extended Master Secret Hash Error"
|
||||||
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,40 @@
|
||||||
|
/* wolfssl_version.h.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_VERSION_H
|
||||||
|
#define WOLFSSL_VERSION_H
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define LIBWOLFSSL_VERSION_STRING "3.10.0"
|
||||||
|
#define LIBWOLFSSL_VERSION_HEX 0x03010000
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* WOLFSSL_VERSION_H */
|
||||||
|
|
|
@ -0,0 +1,195 @@
|
||||||
|
/* aes.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_AES_H
|
||||||
|
#define WOLF_CRYPT_AES_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifndef NO_AES
|
||||||
|
|
||||||
|
/* included for fips @wc_fips */
|
||||||
|
#ifdef HAVE_FIPS
|
||||||
|
#include <cyassl/ctaocrypt/aes.h>
|
||||||
|
#if defined(CYASSL_AES_COUNTER) && !defined(WOLFSSL_AES_COUNTER)
|
||||||
|
#define WOLFSSL_AES_COUNTER
|
||||||
|
#endif
|
||||||
|
#if !defined(WOLFSSL_AES_DIRECT) && defined(CYASSL_AES_DIRECT)
|
||||||
|
#define WOLFSSL_AES_DIRECT
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_FIPS /* to avoid redefinition of macros */
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_AESNI
|
||||||
|
|
||||||
|
#include <wmmintrin.h>
|
||||||
|
#include <emmintrin.h>
|
||||||
|
#include <smmintrin.h>
|
||||||
|
|
||||||
|
#endif /* WOLFSSL_AESNI */
|
||||||
|
|
||||||
|
#endif /* HAVE_FIPS */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_FIPS /* to avoid redefinition of structures */
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
#include <wolfssl/wolfcrypt/async.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum {
|
||||||
|
AES_ENC_TYPE = 1, /* cipher unique type */
|
||||||
|
AES_ENCRYPTION = 0,
|
||||||
|
AES_DECRYPTION = 1,
|
||||||
|
KEYWRAP_BLOCK_SIZE = 8,
|
||||||
|
AES_BLOCK_SIZE = 16
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct Aes {
|
||||||
|
/* AESNI needs key first, rounds 2nd, not sure why yet */
|
||||||
|
ALIGN16 word32 key[60];
|
||||||
|
word32 rounds;
|
||||||
|
|
||||||
|
ALIGN16 word32 reg[AES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
|
||||||
|
ALIGN16 word32 tmp[AES_BLOCK_SIZE / sizeof(word32)]; /* same */
|
||||||
|
|
||||||
|
#ifdef HAVE_AESGCM
|
||||||
|
ALIGN16 byte H[AES_BLOCK_SIZE];
|
||||||
|
#ifdef GCM_TABLE
|
||||||
|
/* key-based fast multiplication table. */
|
||||||
|
ALIGN16 byte M0[256][AES_BLOCK_SIZE];
|
||||||
|
#endif /* GCM_TABLE */
|
||||||
|
#endif /* HAVE_AESGCM */
|
||||||
|
#ifdef WOLFSSL_AESNI
|
||||||
|
byte use_aesni;
|
||||||
|
#endif /* WOLFSSL_AESNI */
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
AsyncCryptDev asyncDev;
|
||||||
|
#ifdef HAVE_CAVIUM
|
||||||
|
AesType type; /* aes key type */
|
||||||
|
#endif
|
||||||
|
#endif /* WOLFSSL_ASYNC_CRYPT */
|
||||||
|
#ifdef WOLFSSL_AES_COUNTER
|
||||||
|
word32 left; /* unused bytes left from last call */
|
||||||
|
#endif
|
||||||
|
#ifdef WOLFSSL_PIC32MZ_CRYPT
|
||||||
|
word32 key_ce[AES_BLOCK_SIZE*2/sizeof(word32)] ;
|
||||||
|
word32 iv_ce [AES_BLOCK_SIZE /sizeof(word32)] ;
|
||||||
|
int keylen ;
|
||||||
|
#endif
|
||||||
|
#ifdef WOLFSSL_TI_CRYPT
|
||||||
|
int keylen ;
|
||||||
|
#endif
|
||||||
|
void* heap; /* memory hint to use */
|
||||||
|
} Aes;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_AESGCM
|
||||||
|
typedef struct Gmac {
|
||||||
|
Aes aes;
|
||||||
|
} Gmac;
|
||||||
|
#endif /* HAVE_AESGCM */
|
||||||
|
#endif /* HAVE_FIPS */
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL int wc_InitAes_h(Aes* aes, void* h);
|
||||||
|
WOLFSSL_API int wc_AesSetKey(Aes* aes, const byte* key, word32 len,
|
||||||
|
const byte* iv, int dir);
|
||||||
|
WOLFSSL_API int wc_AesSetIV(Aes* aes, const byte* iv);
|
||||||
|
WOLFSSL_API int wc_AesCbcEncrypt(Aes* aes, byte* out,
|
||||||
|
const byte* in, word32 sz);
|
||||||
|
WOLFSSL_API int wc_AesCbcDecrypt(Aes* aes, byte* out,
|
||||||
|
const byte* in, word32 sz);
|
||||||
|
|
||||||
|
/* AES-CTR */
|
||||||
|
#ifdef WOLFSSL_AES_COUNTER
|
||||||
|
WOLFSSL_API void wc_AesCtrEncrypt(Aes* aes, byte* out,
|
||||||
|
const byte* in, word32 sz);
|
||||||
|
#endif
|
||||||
|
/* AES-DIRECT */
|
||||||
|
#if defined(WOLFSSL_AES_DIRECT)
|
||||||
|
WOLFSSL_API void wc_AesEncryptDirect(Aes* aes, byte* out, const byte* in);
|
||||||
|
WOLFSSL_API void wc_AesDecryptDirect(Aes* aes, byte* out, const byte* in);
|
||||||
|
WOLFSSL_API int wc_AesSetKeyDirect(Aes* aes, const byte* key, word32 len,
|
||||||
|
const byte* iv, int dir);
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_AESGCM
|
||||||
|
WOLFSSL_API int wc_AesGcmSetKey(Aes* aes, const byte* key, word32 len);
|
||||||
|
WOLFSSL_API int wc_AesGcmEncrypt(Aes* aes, byte* out,
|
||||||
|
const byte* in, word32 sz,
|
||||||
|
const byte* iv, word32 ivSz,
|
||||||
|
byte* authTag, word32 authTagSz,
|
||||||
|
const byte* authIn, word32 authInSz);
|
||||||
|
WOLFSSL_API int wc_AesGcmDecrypt(Aes* aes, byte* out,
|
||||||
|
const byte* in, word32 sz,
|
||||||
|
const byte* iv, word32 ivSz,
|
||||||
|
const byte* authTag, word32 authTagSz,
|
||||||
|
const byte* authIn, word32 authInSz);
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_GmacSetKey(Gmac* gmac, const byte* key, word32 len);
|
||||||
|
WOLFSSL_API int wc_GmacUpdate(Gmac* gmac, const byte* iv, word32 ivSz,
|
||||||
|
const byte* authIn, word32 authInSz,
|
||||||
|
byte* authTag, word32 authTagSz);
|
||||||
|
#endif /* HAVE_AESGCM */
|
||||||
|
#ifdef HAVE_AESCCM
|
||||||
|
WOLFSSL_API int wc_AesCcmSetKey(Aes* aes, const byte* key, word32 keySz);
|
||||||
|
WOLFSSL_API int wc_AesCcmEncrypt(Aes* aes, byte* out,
|
||||||
|
const byte* in, word32 inSz,
|
||||||
|
const byte* nonce, word32 nonceSz,
|
||||||
|
byte* authTag, word32 authTagSz,
|
||||||
|
const byte* authIn, word32 authInSz);
|
||||||
|
WOLFSSL_API int wc_AesCcmDecrypt(Aes* aes, byte* out,
|
||||||
|
const byte* in, word32 inSz,
|
||||||
|
const byte* nonce, word32 nonceSz,
|
||||||
|
const byte* authTag, word32 authTagSz,
|
||||||
|
const byte* authIn, word32 authInSz);
|
||||||
|
#endif /* HAVE_AESCCM */
|
||||||
|
#ifdef HAVE_AES_KEYWRAP
|
||||||
|
WOLFSSL_API int wc_AesKeyWrap(const byte* key, word32 keySz,
|
||||||
|
const byte* in, word32 inSz,
|
||||||
|
byte* out, word32 outSz,
|
||||||
|
const byte* iv);
|
||||||
|
WOLFSSL_API int wc_AesKeyUnWrap(const byte* key, word32 keySz,
|
||||||
|
const byte* in, word32 inSz,
|
||||||
|
byte* out, word32 outSz,
|
||||||
|
const byte* iv);
|
||||||
|
#endif /* HAVE_AES_KEYWRAP */
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_AesGetKeySize(Aes* aes, word32* keySize);
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
WOLFSSL_API int wc_AesAsyncInit(Aes*, int);
|
||||||
|
WOLFSSL_API void wc_AesAsyncFree(Aes*);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* NO_AES */
|
||||||
|
#endif /* WOLF_CRYPT_AES_H */
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
/* arc4.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_ARC4_H
|
||||||
|
#define WOLF_CRYPT_ARC4_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
#include <wolfssl/wolfcrypt/async.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum {
|
||||||
|
ARC4_ENC_TYPE = 4, /* cipher unique type */
|
||||||
|
ARC4_STATE_SIZE = 256
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ARC4 encryption and decryption */
|
||||||
|
typedef struct Arc4 {
|
||||||
|
byte x;
|
||||||
|
byte y;
|
||||||
|
byte state[ARC4_STATE_SIZE];
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
AsyncCryptDev asyncDev;
|
||||||
|
#endif
|
||||||
|
} Arc4;
|
||||||
|
|
||||||
|
WOLFSSL_API void wc_Arc4Process(Arc4*, byte*, const byte*, word32);
|
||||||
|
WOLFSSL_API void wc_Arc4SetKey(Arc4*, const byte*, word32);
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
WOLFSSL_API int wc_Arc4AsyncInit(Arc4*, int);
|
||||||
|
WOLFSSL_API void wc_Arc4AsyncFree(Arc4*);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* WOLF_CRYPT_ARC4_H */
|
||||||
|
|
|
@ -0,0 +1,895 @@
|
||||||
|
/* asn.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_ASN_H
|
||||||
|
#define WOLF_CRYPT_ASN_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifndef NO_ASN
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/integer.h>
|
||||||
|
#ifndef NO_RSA
|
||||||
|
#include <wolfssl/wolfcrypt/rsa.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* fips declare of RsaPrivateKeyDecode @wc_fips */
|
||||||
|
#if defined(HAVE_FIPS) && !defined(NO_RSA)
|
||||||
|
#include <cyassl/ctaocrypt/rsa.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NO_DH
|
||||||
|
#include <wolfssl/wolfcrypt/dh.h>
|
||||||
|
#endif
|
||||||
|
#ifndef NO_DSA
|
||||||
|
#include <wolfssl/wolfcrypt/dsa.h>
|
||||||
|
#endif
|
||||||
|
#ifndef NO_SHA
|
||||||
|
#include <wolfssl/wolfcrypt/sha.h>
|
||||||
|
#endif
|
||||||
|
#ifndef NO_MD5
|
||||||
|
#include <wolfssl/wolfcrypt/md5.h>
|
||||||
|
#endif
|
||||||
|
#include <wolfssl/wolfcrypt/sha256.h>
|
||||||
|
#include <wolfssl/wolfcrypt/asn_public.h> /* public interface */
|
||||||
|
#ifdef HAVE_ECC
|
||||||
|
#include <wolfssl/wolfcrypt/ecc.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum {
|
||||||
|
ISSUER = 0,
|
||||||
|
SUBJECT = 1,
|
||||||
|
|
||||||
|
EXTERNAL_SERIAL_SIZE = 32,
|
||||||
|
|
||||||
|
BEFORE = 0,
|
||||||
|
AFTER = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ASN Tags */
|
||||||
|
enum ASN_Tags {
|
||||||
|
ASN_BOOLEAN = 0x01,
|
||||||
|
ASN_INTEGER = 0x02,
|
||||||
|
ASN_BIT_STRING = 0x03,
|
||||||
|
ASN_OCTET_STRING = 0x04,
|
||||||
|
ASN_TAG_NULL = 0x05,
|
||||||
|
ASN_OBJECT_ID = 0x06,
|
||||||
|
ASN_ENUMERATED = 0x0a,
|
||||||
|
ASN_UTF8STRING = 0x0c,
|
||||||
|
ASN_SEQUENCE = 0x10,
|
||||||
|
ASN_SET = 0x11,
|
||||||
|
ASN_UTC_TIME = 0x17,
|
||||||
|
ASN_OTHER_TYPE = 0x00,
|
||||||
|
ASN_RFC822_TYPE = 0x01,
|
||||||
|
ASN_DNS_TYPE = 0x02,
|
||||||
|
ASN_DIR_TYPE = 0x04,
|
||||||
|
ASN_GENERALIZED_TIME = 0x18,
|
||||||
|
CRL_EXTENSIONS = 0xa0,
|
||||||
|
ASN_EXTENSIONS = 0xa3,
|
||||||
|
ASN_LONG_LENGTH = 0x80
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ASN_Flags{
|
||||||
|
ASN_CONSTRUCTED = 0x20,
|
||||||
|
ASN_CONTEXT_SPECIFIC = 0x80
|
||||||
|
};
|
||||||
|
|
||||||
|
enum DN_Tags {
|
||||||
|
ASN_COMMON_NAME = 0x03, /* CN */
|
||||||
|
ASN_SUR_NAME = 0x04, /* SN */
|
||||||
|
ASN_SERIAL_NUMBER = 0x05, /* serialNumber */
|
||||||
|
ASN_COUNTRY_NAME = 0x06, /* C */
|
||||||
|
ASN_LOCALITY_NAME = 0x07, /* L */
|
||||||
|
ASN_STATE_NAME = 0x08, /* ST */
|
||||||
|
ASN_ORG_NAME = 0x0a, /* O */
|
||||||
|
ASN_ORGUNIT_NAME = 0x0b /* OU */
|
||||||
|
};
|
||||||
|
|
||||||
|
enum PBES {
|
||||||
|
PBE_MD5_DES = 0,
|
||||||
|
PBE_SHA1_DES = 1,
|
||||||
|
PBE_SHA1_DES3 = 2,
|
||||||
|
PBE_SHA1_RC4_128 = 3,
|
||||||
|
PBES2 = 13 /* algo ID */
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ENCRYPTION_TYPES {
|
||||||
|
DES_TYPE = 0,
|
||||||
|
DES3_TYPE = 1,
|
||||||
|
RC4_TYPE = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ECC_TYPES {
|
||||||
|
ECC_PREFIX_0 = 160,
|
||||||
|
ECC_PREFIX_1 = 161
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Misc_ASN {
|
||||||
|
ASN_NAME_MAX = 256,
|
||||||
|
MAX_SALT_SIZE = 64, /* MAX PKCS Salt length */
|
||||||
|
MAX_IV_SIZE = 64, /* MAX PKCS Iv length */
|
||||||
|
MAX_KEY_SIZE = 64, /* MAX PKCS Key length */
|
||||||
|
PKCS5 = 5, /* PKCS oid tag */
|
||||||
|
PKCS5v2 = 6, /* PKCS #5 v2.0 */
|
||||||
|
PKCS12 = 12, /* PKCS #12 */
|
||||||
|
MAX_UNICODE_SZ = 256,
|
||||||
|
ASN_BOOL_SIZE = 2, /* including type */
|
||||||
|
ASN_ECC_HEADER_SZ = 2, /* String type + 1 byte len */
|
||||||
|
ASN_ECC_CONTEXT_SZ = 2, /* Content specific type + 1 byte len */
|
||||||
|
#ifdef NO_SHA
|
||||||
|
KEYID_SIZE = SHA256_DIGEST_SIZE,
|
||||||
|
#else
|
||||||
|
KEYID_SIZE = SHA_DIGEST_SIZE,
|
||||||
|
#endif
|
||||||
|
RSA_INTS = 8, /* RSA ints in private key */
|
||||||
|
DSA_INTS = 5, /* DSA ints in private key */
|
||||||
|
MIN_DATE_SIZE = 13,
|
||||||
|
MAX_DATE_SIZE = 32,
|
||||||
|
ASN_GEN_TIME_SZ = 15, /* 7 numbers * 2 + Zulu tag */
|
||||||
|
MAX_ENCODED_SIG_SZ = 512,
|
||||||
|
MAX_SIG_SZ = 256,
|
||||||
|
MAX_ALGO_SZ = 20,
|
||||||
|
MAX_SEQ_SZ = 5, /* enum(seq | con) + length(4) */
|
||||||
|
MAX_SET_SZ = 5, /* enum(set | con) + length(4) */
|
||||||
|
MAX_OCTET_STR_SZ = 5, /* enum(set | con) + length(4) */
|
||||||
|
MAX_EXP_SZ = 5, /* enum(contextspec|con|exp) + length(4) */
|
||||||
|
MAX_PRSTR_SZ = 5, /* enum(prstr) + length(4) */
|
||||||
|
MAX_VERSION_SZ = 5, /* enum + id + version(byte) + (header(2))*/
|
||||||
|
MAX_ENCODED_DIG_SZ = 73, /* sha512 + enum(bit or octet) + length(4) */
|
||||||
|
MAX_RSA_INT_SZ = 517, /* RSA raw sz 4096 for bits + tag + len(4) */
|
||||||
|
MAX_NTRU_KEY_SZ = 610, /* NTRU 112 bit public key */
|
||||||
|
MAX_NTRU_ENC_SZ = 628, /* NTRU 112 bit DER public encoding */
|
||||||
|
MAX_LENGTH_SZ = 4, /* Max length size for DER encoding */
|
||||||
|
MAX_RSA_E_SZ = 16, /* Max RSA public e size */
|
||||||
|
MAX_CA_SZ = 32, /* Max encoded CA basic constraint length */
|
||||||
|
MAX_SN_SZ = 35, /* Max encoded serial number (INT) length */
|
||||||
|
MAX_DER_DIGEST_SZ = MAX_ENCODED_DIG_SZ + MAX_ALGO_SZ + MAX_SEQ_SZ, /* Maximum DER digest size */
|
||||||
|
#ifdef WOLFSSL_CERT_GEN
|
||||||
|
#ifdef WOLFSSL_CERT_REQ
|
||||||
|
/* Max encoded cert req attributes length */
|
||||||
|
MAX_ATTRIB_SZ = MAX_SEQ_SZ * 3 + (11 + MAX_SEQ_SZ) * 2 +
|
||||||
|
MAX_PRSTR_SZ + CTC_NAME_SIZE, /* 11 is the OID size */
|
||||||
|
#endif
|
||||||
|
#if defined(WOLFSSL_ALT_NAMES) || defined(WOLFSSL_CERT_EXT)
|
||||||
|
MAX_EXTENSIONS_SZ = 1 + MAX_LENGTH_SZ + CTC_MAX_ALT_SIZE,
|
||||||
|
#else
|
||||||
|
MAX_EXTENSIONS_SZ = 1 + MAX_LENGTH_SZ + MAX_CA_SZ,
|
||||||
|
#endif
|
||||||
|
/* Max total extensions, id + len + others */
|
||||||
|
#endif
|
||||||
|
#ifdef WOLFSSL_CERT_EXT
|
||||||
|
MAX_KID_SZ = 45, /* Max encoded KID length (SHA-256 case) */
|
||||||
|
MAX_KEYUSAGE_SZ = 18, /* Max encoded Key Usage length */
|
||||||
|
MAX_OID_SZ = 32, /* Max DER length of OID*/
|
||||||
|
MAX_OID_STRING_SZ = 64, /* Max string length representation of OID*/
|
||||||
|
MAX_CERTPOL_NB = CTC_MAX_CERTPOL_NB,/* Max number of Cert Policy */
|
||||||
|
MAX_CERTPOL_SZ = CTC_MAX_CERTPOL_SZ,
|
||||||
|
#endif
|
||||||
|
OCSP_NONCE_EXT_SZ = 37, /* OCSP Nonce Extension size */
|
||||||
|
MAX_OCSP_EXT_SZ = 58, /* Max OCSP Extension length */
|
||||||
|
MAX_OCSP_NONCE_SZ = 16, /* OCSP Nonce size */
|
||||||
|
EIGHTK_BUF = 8192, /* Tmp buffer size */
|
||||||
|
MAX_PUBLIC_KEY_SZ = MAX_NTRU_ENC_SZ + MAX_ALGO_SZ + MAX_SEQ_SZ * 2,
|
||||||
|
/* use bigger NTRU size */
|
||||||
|
HEADER_ENCRYPTED_KEY_SIZE = 88,/* Extra header size for encrypted key */
|
||||||
|
TRAILING_ZERO = 1, /* Used for size of zero pad */
|
||||||
|
MIN_VERSION_SZ = 3 /* Min bytes needed for GetMyVersion */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum Oid_Types {
|
||||||
|
oidHashType = 0,
|
||||||
|
oidSigType = 1,
|
||||||
|
oidKeyType = 2,
|
||||||
|
oidCurveType = 3,
|
||||||
|
oidBlkType = 4,
|
||||||
|
oidOcspType = 5,
|
||||||
|
oidCertExtType = 6,
|
||||||
|
oidCertAuthInfoType = 7,
|
||||||
|
oidCertPolicyType = 8,
|
||||||
|
oidCertAltNameType = 9,
|
||||||
|
oidCertKeyUseType = 10,
|
||||||
|
oidKdfType = 11,
|
||||||
|
oidKeyWrapType = 12,
|
||||||
|
oidCmsKeyAgreeType = 13,
|
||||||
|
oidIgnoreType
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum Hash_Sum {
|
||||||
|
MD2h = 646,
|
||||||
|
MD5h = 649,
|
||||||
|
SHAh = 88,
|
||||||
|
SHA224h = 417,
|
||||||
|
SHA256h = 414,
|
||||||
|
SHA384h = 415,
|
||||||
|
SHA512h = 416
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum Block_Sum {
|
||||||
|
AES128CBCb = 414,
|
||||||
|
AES192CBCb = 434,
|
||||||
|
AES256CBCb = 454,
|
||||||
|
DESb = 69,
|
||||||
|
DES3b = 652
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum Key_Sum {
|
||||||
|
DSAk = 515,
|
||||||
|
RSAk = 645,
|
||||||
|
NTRUk = 274,
|
||||||
|
ECDSAk = 518
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum KeyWrap_Sum {
|
||||||
|
AES128_WRAP = 417,
|
||||||
|
AES192_WRAP = 437,
|
||||||
|
AES256_WRAP = 457
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum Key_Agree {
|
||||||
|
dhSinglePass_stdDH_sha1kdf_scheme = 464,
|
||||||
|
dhSinglePass_stdDH_sha224kdf_scheme = 188,
|
||||||
|
dhSinglePass_stdDH_sha256kdf_scheme = 189,
|
||||||
|
dhSinglePass_stdDH_sha384kdf_scheme = 190,
|
||||||
|
dhSinglePass_stdDH_sha512kdf_scheme = 191,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum Ecc_Sum {
|
||||||
|
ECC_SECP112R1_OID = 182,
|
||||||
|
ECC_SECP112R2_OID = 183,
|
||||||
|
ECC_SECP128R1_OID = 204,
|
||||||
|
ECC_SECP128R2_OID = 205,
|
||||||
|
ECC_SECP160R1_OID = 184,
|
||||||
|
ECC_SECP160R2_OID = 206,
|
||||||
|
ECC_SECP160K1_OID = 185,
|
||||||
|
ECC_BRAINPOOLP160R1_OID = 98,
|
||||||
|
ECC_SECP192R1_OID = 520,
|
||||||
|
ECC_PRIME192V2_OID = 521,
|
||||||
|
ECC_PRIME192V3_OID = 522,
|
||||||
|
ECC_SECP192K1_OID = 207,
|
||||||
|
ECC_BRAINPOOLP192R1_OID = 100,
|
||||||
|
ECC_SECP224R1_OID = 209,
|
||||||
|
ECC_SECP224K1_OID = 208,
|
||||||
|
ECC_BRAINPOOLP224R1_OID = 102,
|
||||||
|
ECC_PRIME239V1_OID = 523,
|
||||||
|
ECC_PRIME239V2_OID = 524,
|
||||||
|
ECC_PRIME239V3_OID = 525,
|
||||||
|
ECC_SECP256R1_OID = 526,
|
||||||
|
ECC_SECP256K1_OID = 186,
|
||||||
|
ECC_BRAINPOOLP256R1_OID = 104,
|
||||||
|
ECC_BRAINPOOLP320R1_OID = 106,
|
||||||
|
ECC_SECP384R1_OID = 210,
|
||||||
|
ECC_BRAINPOOLP384R1_OID = 108,
|
||||||
|
ECC_BRAINPOOLP512R1_OID = 110,
|
||||||
|
ECC_SECP521R1_OID = 211,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum KDF_Sum {
|
||||||
|
PBKDF2_OID = 660
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum Extensions_Sum {
|
||||||
|
BASIC_CA_OID = 133,
|
||||||
|
ALT_NAMES_OID = 131,
|
||||||
|
CRL_DIST_OID = 145,
|
||||||
|
AUTH_INFO_OID = 69,
|
||||||
|
AUTH_KEY_OID = 149,
|
||||||
|
SUBJ_KEY_OID = 128,
|
||||||
|
CERT_POLICY_OID = 146,
|
||||||
|
KEY_USAGE_OID = 129, /* 2.5.29.15 */
|
||||||
|
INHIBIT_ANY_OID = 168, /* 2.5.29.54 */
|
||||||
|
EXT_KEY_USAGE_OID = 151, /* 2.5.29.37 */
|
||||||
|
NAME_CONS_OID = 144 /* 2.5.29.30 */
|
||||||
|
};
|
||||||
|
|
||||||
|
enum CertificatePolicy_Sum {
|
||||||
|
CP_ANY_OID = 146 /* id-ce 32 0 */
|
||||||
|
};
|
||||||
|
|
||||||
|
enum SepHardwareName_Sum {
|
||||||
|
HW_NAME_OID = 79 /* 1.3.6.1.5.5.7.8.4 from RFC 4108*/
|
||||||
|
};
|
||||||
|
|
||||||
|
enum AuthInfo_Sum {
|
||||||
|
AIA_OCSP_OID = 116, /* 1.3.6.1.5.5.7.48.1 */
|
||||||
|
AIA_CA_ISSUER_OID = 117 /* 1.3.6.1.5.5.7.48.2 */
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ExtKeyUsage_Sum { /* From RFC 5280 */
|
||||||
|
EKU_ANY_OID = 151, /* 2.5.29.37.0, anyExtendedKeyUsage */
|
||||||
|
EKU_SERVER_AUTH_OID = 71, /* 1.3.6.1.5.5.7.3.1, id-kp-serverAuth */
|
||||||
|
EKU_CLIENT_AUTH_OID = 72, /* 1.3.6.1.5.5.7.3.2, id-kp-clientAuth */
|
||||||
|
EKU_OCSP_SIGN_OID = 79 /* 1.3.6.1.5.5.7.3.9, OCSPSigning */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum VerifyType {
|
||||||
|
NO_VERIFY = 0,
|
||||||
|
VERIFY = 1,
|
||||||
|
VERIFY_CRL = 2,
|
||||||
|
VERIFY_OCSP = 3
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_CERT_EXT
|
||||||
|
enum KeyIdType {
|
||||||
|
SKID_TYPE = 0,
|
||||||
|
AKID_TYPE = 1
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Key usage extension bits */
|
||||||
|
#define KEYUSE_DIGITAL_SIG 0x0080
|
||||||
|
#define KEYUSE_CONTENT_COMMIT 0x0040
|
||||||
|
#define KEYUSE_KEY_ENCIPHER 0x0020
|
||||||
|
#define KEYUSE_DATA_ENCIPHER 0x0010
|
||||||
|
#define KEYUSE_KEY_AGREE 0x0008
|
||||||
|
#define KEYUSE_KEY_CERT_SIGN 0x0004
|
||||||
|
#define KEYUSE_CRL_SIGN 0x0002
|
||||||
|
#define KEYUSE_ENCIPHER_ONLY 0x0001
|
||||||
|
#define KEYUSE_DECIPHER_ONLY 0x8000
|
||||||
|
|
||||||
|
#define EXTKEYUSE_ANY 0x08
|
||||||
|
#define EXTKEYUSE_OCSP_SIGN 0x04
|
||||||
|
#define EXTKEYUSE_CLIENT_AUTH 0x02
|
||||||
|
#define EXTKEYUSE_SERVER_AUTH 0x01
|
||||||
|
|
||||||
|
typedef struct DNS_entry DNS_entry;
|
||||||
|
|
||||||
|
struct DNS_entry {
|
||||||
|
DNS_entry* next; /* next on DNS list */
|
||||||
|
char* name; /* actual DNS name */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct Base_entry Base_entry;
|
||||||
|
|
||||||
|
struct Base_entry {
|
||||||
|
Base_entry* next; /* next on name base list */
|
||||||
|
char* name; /* actual name base */
|
||||||
|
int nameSz; /* name length */
|
||||||
|
byte type; /* Name base type (DNS or RFC822) */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct DecodedName {
|
||||||
|
char* fullName;
|
||||||
|
int fullNameLen;
|
||||||
|
int entryCount;
|
||||||
|
int cnIdx;
|
||||||
|
int cnLen;
|
||||||
|
int snIdx;
|
||||||
|
int snLen;
|
||||||
|
int cIdx;
|
||||||
|
int cLen;
|
||||||
|
int lIdx;
|
||||||
|
int lLen;
|
||||||
|
int stIdx;
|
||||||
|
int stLen;
|
||||||
|
int oIdx;
|
||||||
|
int oLen;
|
||||||
|
int ouIdx;
|
||||||
|
int ouLen;
|
||||||
|
int emailIdx;
|
||||||
|
int emailLen;
|
||||||
|
int uidIdx;
|
||||||
|
int uidLen;
|
||||||
|
int serialIdx;
|
||||||
|
int serialLen;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct DecodedCert DecodedCert;
|
||||||
|
typedef struct DecodedName DecodedName;
|
||||||
|
typedef struct Signer Signer;
|
||||||
|
#ifdef WOLFSSL_TRUST_PEER_CERT
|
||||||
|
typedef struct TrustedPeerCert TrustedPeerCert;
|
||||||
|
#endif /* WOLFSSL_TRUST_PEER_CERT */
|
||||||
|
|
||||||
|
|
||||||
|
struct DecodedCert {
|
||||||
|
byte* publicKey;
|
||||||
|
word32 pubKeySize;
|
||||||
|
int pubKeyStored;
|
||||||
|
word32 certBegin; /* offset to start of cert */
|
||||||
|
word32 sigIndex; /* offset to start of signature */
|
||||||
|
word32 sigLength; /* length of signature */
|
||||||
|
word32 signatureOID; /* sum of algorithm object id */
|
||||||
|
word32 keyOID; /* sum of key algo object id */
|
||||||
|
int version; /* cert version, 1 or 3 */
|
||||||
|
DNS_entry* altNames; /* alt names list of dns entries */
|
||||||
|
#ifndef IGNORE_NAME_CONSTRAINTS
|
||||||
|
DNS_entry* altEmailNames; /* alt names list of RFC822 entries */
|
||||||
|
Base_entry* permittedNames; /* Permitted name bases */
|
||||||
|
Base_entry* excludedNames; /* Excluded name bases */
|
||||||
|
#endif /* IGNORE_NAME_CONSTRAINTS */
|
||||||
|
byte subjectHash[KEYID_SIZE]; /* hash of all Names */
|
||||||
|
byte issuerHash[KEYID_SIZE]; /* hash of all Names */
|
||||||
|
#ifdef HAVE_OCSP
|
||||||
|
byte issuerKeyHash[KEYID_SIZE]; /* hash of the public Key */
|
||||||
|
#endif /* HAVE_OCSP */
|
||||||
|
byte* signature; /* not owned, points into raw cert */
|
||||||
|
char* subjectCN; /* CommonName */
|
||||||
|
int subjectCNLen; /* CommonName Length */
|
||||||
|
char subjectCNEnc; /* CommonName Encoding */
|
||||||
|
int subjectCNStored; /* have we saved a copy we own */
|
||||||
|
char issuer[ASN_NAME_MAX]; /* full name including common name */
|
||||||
|
char subject[ASN_NAME_MAX]; /* full name including common name */
|
||||||
|
int verify; /* Default to yes, but could be off */
|
||||||
|
byte* source; /* byte buffer holder cert, NOT owner */
|
||||||
|
word32 srcIdx; /* current offset into buffer */
|
||||||
|
word32 maxIdx; /* max offset based on init size */
|
||||||
|
void* heap; /* for user memory overrides */
|
||||||
|
byte serial[EXTERNAL_SERIAL_SIZE]; /* raw serial number */
|
||||||
|
int serialSz; /* raw serial bytes stored */
|
||||||
|
byte* extensions; /* not owned, points into raw cert */
|
||||||
|
int extensionsSz; /* length of cert extensions */
|
||||||
|
word32 extensionsIdx; /* if want to go back and parse later */
|
||||||
|
byte* extAuthInfo; /* Authority Information Access URI */
|
||||||
|
int extAuthInfoSz; /* length of the URI */
|
||||||
|
byte* extCrlInfo; /* CRL Distribution Points */
|
||||||
|
int extCrlInfoSz; /* length of the URI */
|
||||||
|
byte extSubjKeyId[KEYID_SIZE]; /* Subject Key ID */
|
||||||
|
byte extSubjKeyIdSet; /* Set when the SKID was read from cert */
|
||||||
|
byte extAuthKeyId[KEYID_SIZE]; /* Authority Key ID */
|
||||||
|
byte extAuthKeyIdSet; /* Set when the AKID was read from cert */
|
||||||
|
#ifndef IGNORE_NAME_CONSTRAINTS
|
||||||
|
byte extNameConstraintSet;
|
||||||
|
#endif /* IGNORE_NAME_CONSTRAINTS */
|
||||||
|
byte isCA; /* CA basic constraint true */
|
||||||
|
byte pathLengthSet; /* CA basic const path length set */
|
||||||
|
byte pathLength; /* CA basic constraint path length */
|
||||||
|
byte weOwnAltNames; /* altNames haven't been given to copy */
|
||||||
|
byte extKeyUsageSet;
|
||||||
|
word16 extKeyUsage; /* Key usage bitfield */
|
||||||
|
byte extExtKeyUsageSet; /* Extended Key Usage */
|
||||||
|
byte extExtKeyUsage; /* Extended Key usage bitfield */
|
||||||
|
#ifdef OPENSSL_EXTRA
|
||||||
|
byte extBasicConstSet;
|
||||||
|
byte extBasicConstCrit;
|
||||||
|
byte extSubjAltNameSet;
|
||||||
|
byte extSubjAltNameCrit;
|
||||||
|
byte extAuthKeyIdCrit;
|
||||||
|
#ifndef IGNORE_NAME_CONSTRAINTS
|
||||||
|
byte extNameConstraintCrit;
|
||||||
|
#endif /* IGNORE_NAME_CONSTRAINTS */
|
||||||
|
byte extSubjKeyIdCrit;
|
||||||
|
byte extKeyUsageCrit;
|
||||||
|
byte extExtKeyUsageCrit;
|
||||||
|
byte* extExtKeyUsageSrc;
|
||||||
|
word32 extExtKeyUsageSz;
|
||||||
|
word32 extExtKeyUsageCount;
|
||||||
|
byte* extAuthKeyIdSrc;
|
||||||
|
word32 extAuthKeyIdSz;
|
||||||
|
byte* extSubjKeyIdSrc;
|
||||||
|
word32 extSubjKeyIdSz;
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_ECC
|
||||||
|
word32 pkCurveOID; /* Public Key's curve OID */
|
||||||
|
#endif /* HAVE_ECC */
|
||||||
|
byte* beforeDate;
|
||||||
|
int beforeDateLen;
|
||||||
|
byte* afterDate;
|
||||||
|
int afterDateLen;
|
||||||
|
#ifdef HAVE_PKCS7
|
||||||
|
byte* issuerRaw; /* pointer to issuer inside source */
|
||||||
|
int issuerRawLen;
|
||||||
|
#endif
|
||||||
|
#ifndef IGNORE_NAME_CONSTRAINT
|
||||||
|
byte* subjectRaw; /* pointer to subject inside source */
|
||||||
|
int subjectRawLen;
|
||||||
|
#endif
|
||||||
|
#if defined(WOLFSSL_CERT_GEN)
|
||||||
|
/* easy access to subject info for other sign */
|
||||||
|
char* subjectSN;
|
||||||
|
int subjectSNLen;
|
||||||
|
char subjectSNEnc;
|
||||||
|
char* subjectC;
|
||||||
|
int subjectCLen;
|
||||||
|
char subjectCEnc;
|
||||||
|
char* subjectL;
|
||||||
|
int subjectLLen;
|
||||||
|
char subjectLEnc;
|
||||||
|
char* subjectST;
|
||||||
|
int subjectSTLen;
|
||||||
|
char subjectSTEnc;
|
||||||
|
char* subjectO;
|
||||||
|
int subjectOLen;
|
||||||
|
char subjectOEnc;
|
||||||
|
char* subjectOU;
|
||||||
|
int subjectOULen;
|
||||||
|
char subjectOUEnc;
|
||||||
|
char* subjectEmail;
|
||||||
|
int subjectEmailLen;
|
||||||
|
#endif /* WOLFSSL_CERT_GEN */
|
||||||
|
#ifdef OPENSSL_EXTRA
|
||||||
|
DecodedName issuerName;
|
||||||
|
DecodedName subjectName;
|
||||||
|
#endif /* OPENSSL_EXTRA */
|
||||||
|
#ifdef WOLFSSL_SEP
|
||||||
|
int deviceTypeSz;
|
||||||
|
byte* deviceType;
|
||||||
|
int hwTypeSz;
|
||||||
|
byte* hwType;
|
||||||
|
int hwSerialNumSz;
|
||||||
|
byte* hwSerialNum;
|
||||||
|
#ifdef OPENSSL_EXTRA
|
||||||
|
byte extCertPolicySet;
|
||||||
|
byte extCertPolicyCrit;
|
||||||
|
#endif /* OPENSSL_EXTRA */
|
||||||
|
#endif /* WOLFSSL_SEP */
|
||||||
|
#ifdef WOLFSSL_CERT_EXT
|
||||||
|
char extCertPolicies[MAX_CERTPOL_NB][MAX_CERTPOL_SZ];
|
||||||
|
int extCertPoliciesNb;
|
||||||
|
#endif /* WOLFSSL_CERT_EXT */
|
||||||
|
};
|
||||||
|
|
||||||
|
extern const char* BEGIN_CERT;
|
||||||
|
extern const char* END_CERT;
|
||||||
|
extern const char* BEGIN_CERT_REQ;
|
||||||
|
extern const char* END_CERT_REQ;
|
||||||
|
extern const char* BEGIN_DH_PARAM;
|
||||||
|
extern const char* END_DH_PARAM;
|
||||||
|
extern const char* BEGIN_X509_CRL;
|
||||||
|
extern const char* END_X509_CRL;
|
||||||
|
extern const char* BEGIN_RSA_PRIV;
|
||||||
|
extern const char* END_RSA_PRIV;
|
||||||
|
extern const char* BEGIN_PRIV_KEY;
|
||||||
|
extern const char* END_PRIV_KEY;
|
||||||
|
extern const char* BEGIN_ENC_PRIV_KEY;
|
||||||
|
extern const char* END_ENC_PRIV_KEY;
|
||||||
|
extern const char* BEGIN_EC_PRIV;
|
||||||
|
extern const char* END_EC_PRIV;
|
||||||
|
extern const char* BEGIN_DSA_PRIV;
|
||||||
|
extern const char* END_DSA_PRIV;
|
||||||
|
extern const char* BEGIN_PUB_KEY;
|
||||||
|
extern const char* END_PUB_KEY;
|
||||||
|
|
||||||
|
#ifdef NO_SHA
|
||||||
|
#define SIGNER_DIGEST_SIZE SHA256_DIGEST_SIZE
|
||||||
|
#else
|
||||||
|
#define SIGNER_DIGEST_SIZE SHA_DIGEST_SIZE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* CA Signers */
|
||||||
|
/* if change layout change PERSIST_CERT_CACHE functions too */
|
||||||
|
struct Signer {
|
||||||
|
word32 pubKeySize;
|
||||||
|
word32 keyOID; /* key type */
|
||||||
|
word16 keyUsage;
|
||||||
|
byte pathLength;
|
||||||
|
byte pathLengthSet;
|
||||||
|
byte* publicKey;
|
||||||
|
int nameLen;
|
||||||
|
char* name; /* common name */
|
||||||
|
#ifndef IGNORE_NAME_CONSTRAINTS
|
||||||
|
Base_entry* permittedNames;
|
||||||
|
Base_entry* excludedNames;
|
||||||
|
#endif /* IGNORE_NAME_CONSTRAINTS */
|
||||||
|
byte subjectNameHash[SIGNER_DIGEST_SIZE];
|
||||||
|
/* sha hash of names in certificate */
|
||||||
|
#ifndef NO_SKID
|
||||||
|
byte subjectKeyIdHash[SIGNER_DIGEST_SIZE];
|
||||||
|
/* sha hash of names in certificate */
|
||||||
|
#endif
|
||||||
|
Signer* next;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_TRUST_PEER_CERT
|
||||||
|
/* used for having trusted peer certs rather then CA */
|
||||||
|
struct TrustedPeerCert {
|
||||||
|
int nameLen;
|
||||||
|
char* name; /* common name */
|
||||||
|
#ifndef IGNORE_NAME_CONSTRAINTS
|
||||||
|
Base_entry* permittedNames;
|
||||||
|
Base_entry* excludedNames;
|
||||||
|
#endif /* IGNORE_NAME_CONSTRAINTS */
|
||||||
|
byte subjectNameHash[SIGNER_DIGEST_SIZE];
|
||||||
|
/* sha hash of names in certificate */
|
||||||
|
#ifndef NO_SKID
|
||||||
|
byte subjectKeyIdHash[SIGNER_DIGEST_SIZE];
|
||||||
|
/* sha hash of names in certificate */
|
||||||
|
#endif
|
||||||
|
word32 sigLen;
|
||||||
|
byte* sig;
|
||||||
|
struct TrustedPeerCert* next;
|
||||||
|
};
|
||||||
|
#endif /* WOLFSSL_TRUST_PEER_CERT */
|
||||||
|
|
||||||
|
|
||||||
|
/* for testing or custom openssl wrappers */
|
||||||
|
#if defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA)
|
||||||
|
#define WOLFSSL_ASN_API WOLFSSL_API
|
||||||
|
#else
|
||||||
|
#define WOLFSSL_ASN_API WOLFSSL_LOCAL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WOLFSSL_ASN_API void FreeAltNames(DNS_entry*, void*);
|
||||||
|
#ifndef IGNORE_NAME_CONSTRAINTS
|
||||||
|
WOLFSSL_ASN_API void FreeNameSubtrees(Base_entry*, void*);
|
||||||
|
#endif /* IGNORE_NAME_CONSTRAINTS */
|
||||||
|
WOLFSSL_ASN_API void InitDecodedCert(DecodedCert*, byte*, word32, void*);
|
||||||
|
WOLFSSL_ASN_API void FreeDecodedCert(DecodedCert*);
|
||||||
|
WOLFSSL_ASN_API int ParseCert(DecodedCert*, int type, int verify, void* cm);
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL int ParseCertRelative(DecodedCert*,int type,int verify,void* cm);
|
||||||
|
WOLFSSL_LOCAL int DecodeToKey(DecodedCert*, int verify);
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL Signer* MakeSigner(void*);
|
||||||
|
WOLFSSL_LOCAL void FreeSigner(Signer*, void*);
|
||||||
|
WOLFSSL_LOCAL void FreeSignerTable(Signer**, int, void*);
|
||||||
|
#ifdef WOLFSSL_TRUST_PEER_CERT
|
||||||
|
WOLFSSL_LOCAL void FreeTrustedPeer(TrustedPeerCert*, void*);
|
||||||
|
WOLFSSL_LOCAL void FreeTrustedPeerTable(TrustedPeerCert**, int, void*);
|
||||||
|
#endif /* WOLFSSL_TRUST_PEER_CERT */
|
||||||
|
|
||||||
|
WOLFSSL_ASN_API int ToTraditional(byte* buffer, word32 length);
|
||||||
|
WOLFSSL_LOCAL int ToTraditionalEnc(byte* buffer, word32 length,const char*,int);
|
||||||
|
WOLFSSL_LOCAL int DecryptContent(byte* input, word32 sz,const char* psw,int pswSz);
|
||||||
|
|
||||||
|
typedef struct tm wolfssl_tm;
|
||||||
|
#if defined(WOLFSSL_MYSQL_COMPATIBLE)
|
||||||
|
WOLFSSL_LOCAL int GetTimeString(byte* date, int format, char* buf, int len);
|
||||||
|
#endif
|
||||||
|
WOLFSSL_LOCAL int ExtractDate(const unsigned char* date, unsigned char format,
|
||||||
|
wolfssl_tm* certTime, int* idx);
|
||||||
|
WOLFSSL_LOCAL int ValidateDate(const byte* date, byte format, int dateType);
|
||||||
|
|
||||||
|
/* ASN.1 helper functions */
|
||||||
|
#ifdef WOLFSSL_CERT_GEN
|
||||||
|
WOLFSSL_ASN_API int SetName(byte* output, word32 outputSz, CertName* name);
|
||||||
|
#endif
|
||||||
|
WOLFSSL_LOCAL int GetShortInt(const byte* input, word32* inOutIdx, int* number,
|
||||||
|
word32 maxIdx);
|
||||||
|
WOLFSSL_LOCAL int GetLength(const byte* input, word32* inOutIdx, int* len,
|
||||||
|
word32 maxIdx);
|
||||||
|
WOLFSSL_LOCAL int GetSequence(const byte* input, word32* inOutIdx, int* len,
|
||||||
|
word32 maxIdx);
|
||||||
|
WOLFSSL_LOCAL int GetSet(const byte* input, word32* inOutIdx, int* len,
|
||||||
|
word32 maxIdx);
|
||||||
|
WOLFSSL_LOCAL int GetMyVersion(const byte* input, word32* inOutIdx,
|
||||||
|
int* version, word32 maxIdx);
|
||||||
|
WOLFSSL_LOCAL int GetInt(mp_int* mpi, const byte* input, word32* inOutIdx,
|
||||||
|
word32 maxIdx);
|
||||||
|
#ifdef HAVE_OID_ENCODING
|
||||||
|
WOLFSSL_LOCAL int EncodeObjectId(const word16* in, word32 inSz,
|
||||||
|
byte* out, word32* outSz);
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_OID_DECODING
|
||||||
|
WOLFSSL_LOCAL int DecodeObjectId(const byte* in, word32 inSz,
|
||||||
|
word16* out, word32* outSz);
|
||||||
|
#endif
|
||||||
|
WOLFSSL_LOCAL int GetObjectId(const byte* input, word32* inOutIdx, word32* oid,
|
||||||
|
word32 oidType, word32 maxIdx);
|
||||||
|
WOLFSSL_LOCAL int GetAlgoId(const byte* input, word32* inOutIdx, word32* oid,
|
||||||
|
word32 oidType, word32 maxIdx);
|
||||||
|
WOLFSSL_LOCAL word32 SetLength(word32 length, byte* output);
|
||||||
|
WOLFSSL_LOCAL word32 SetSequence(word32 len, byte* output);
|
||||||
|
WOLFSSL_LOCAL word32 SetOctetString(word32 len, byte* output);
|
||||||
|
WOLFSSL_LOCAL word32 SetImplicit(byte tag,byte number,word32 len,byte* output);
|
||||||
|
WOLFSSL_LOCAL word32 SetExplicit(byte number, word32 len, byte* output);
|
||||||
|
WOLFSSL_LOCAL word32 SetSet(word32 len, byte* output);
|
||||||
|
WOLFSSL_LOCAL word32 SetAlgoID(int algoOID,byte* output,int type,int curveSz);
|
||||||
|
WOLFSSL_LOCAL int SetMyVersion(word32 version, byte* output, int header);
|
||||||
|
WOLFSSL_LOCAL int SetSerialNumber(const byte* sn, word32 snSz, byte* output);
|
||||||
|
WOLFSSL_LOCAL int GetSerialNumber(const byte* input, word32* inOutIdx,
|
||||||
|
byte* serial, int* serialSz, word32 maxIdx);
|
||||||
|
WOLFSSL_LOCAL int GetNameHash(const byte* source, word32* idx, byte* hash,
|
||||||
|
int maxIdx);
|
||||||
|
WOLFSSL_LOCAL int wc_CheckPrivateKey(byte* key, word32 keySz, DecodedCert* der);
|
||||||
|
|
||||||
|
#ifdef HAVE_ECC
|
||||||
|
/* ASN sig helpers */
|
||||||
|
WOLFSSL_LOCAL int StoreECC_DSA_Sig(byte* out, word32* outLen, mp_int* r,
|
||||||
|
mp_int* s);
|
||||||
|
WOLFSSL_LOCAL int DecodeECC_DSA_Sig(const byte* sig, word32 sigLen,
|
||||||
|
mp_int* r, mp_int* s);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_CERT_GEN
|
||||||
|
|
||||||
|
enum cert_enums {
|
||||||
|
NAME_ENTRIES = 8,
|
||||||
|
JOINT_LEN = 2,
|
||||||
|
EMAIL_JOINT_LEN = 9,
|
||||||
|
RSA_KEY = 10,
|
||||||
|
NTRU_KEY = 11,
|
||||||
|
ECC_KEY = 12
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_PEMCERT_TODER_DEFINED
|
||||||
|
#ifndef NO_FILESYSTEM
|
||||||
|
/* forward from wolfSSL */
|
||||||
|
WOLFSSL_API
|
||||||
|
int wolfSSL_PemCertToDer(const char* fileName,unsigned char* derBuf,int derSz);
|
||||||
|
#define WOLFSSL_PEMCERT_TODER_DEFINED
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLFSSL_CERT_GEN */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* for pointer use */
|
||||||
|
typedef struct CertStatus CertStatus;
|
||||||
|
|
||||||
|
#ifdef HAVE_OCSP
|
||||||
|
|
||||||
|
enum Ocsp_Response_Status {
|
||||||
|
OCSP_SUCCESSFUL = 0, /* Response has valid confirmations */
|
||||||
|
OCSP_MALFORMED_REQUEST = 1, /* Illegal confirmation request */
|
||||||
|
OCSP_INTERNAL_ERROR = 2, /* Internal error in issuer */
|
||||||
|
OCSP_TRY_LATER = 3, /* Try again later */
|
||||||
|
OCSP_SIG_REQUIRED = 5, /* Must sign the request (4 is skipped) */
|
||||||
|
OCSP_UNAUTHROIZED = 6 /* Request unauthorized */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum Ocsp_Cert_Status {
|
||||||
|
CERT_GOOD = 0,
|
||||||
|
CERT_REVOKED = 1,
|
||||||
|
CERT_UNKNOWN = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum Ocsp_Sums {
|
||||||
|
OCSP_BASIC_OID = 117,
|
||||||
|
OCSP_NONCE_OID = 118
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct OcspRequest OcspRequest;
|
||||||
|
typedef struct OcspResponse OcspResponse;
|
||||||
|
|
||||||
|
|
||||||
|
struct CertStatus {
|
||||||
|
CertStatus* next;
|
||||||
|
|
||||||
|
byte serial[EXTERNAL_SERIAL_SIZE];
|
||||||
|
int serialSz;
|
||||||
|
|
||||||
|
int status;
|
||||||
|
|
||||||
|
byte thisDate[MAX_DATE_SIZE];
|
||||||
|
byte nextDate[MAX_DATE_SIZE];
|
||||||
|
byte thisDateFormat;
|
||||||
|
byte nextDateFormat;
|
||||||
|
|
||||||
|
byte* rawOcspResponse;
|
||||||
|
word32 rawOcspResponseSz;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct OcspResponse {
|
||||||
|
int responseStatus; /* return code from Responder */
|
||||||
|
|
||||||
|
byte* response; /* Pointer to beginning of OCSP Response */
|
||||||
|
word32 responseSz; /* length of the OCSP Response */
|
||||||
|
|
||||||
|
byte producedDate[MAX_DATE_SIZE];
|
||||||
|
/* Date at which this response was signed */
|
||||||
|
byte producedDateFormat; /* format of the producedDate */
|
||||||
|
byte* issuerHash;
|
||||||
|
byte* issuerKeyHash;
|
||||||
|
|
||||||
|
byte* cert;
|
||||||
|
word32 certSz;
|
||||||
|
|
||||||
|
byte* sig; /* Pointer to sig in source */
|
||||||
|
word32 sigSz; /* Length in octets for the sig */
|
||||||
|
word32 sigOID; /* OID for hash used for sig */
|
||||||
|
|
||||||
|
CertStatus* status; /* certificate status to fill out */
|
||||||
|
|
||||||
|
byte* nonce; /* pointer to nonce inside ASN.1 response */
|
||||||
|
int nonceSz; /* length of the nonce string */
|
||||||
|
|
||||||
|
byte* source; /* pointer to source buffer, not owned */
|
||||||
|
word32 maxIdx; /* max offset based on init size */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct OcspRequest {
|
||||||
|
byte issuerHash[KEYID_SIZE];
|
||||||
|
byte issuerKeyHash[KEYID_SIZE];
|
||||||
|
byte* serial; /* copy of the serial number in source cert */
|
||||||
|
int serialSz;
|
||||||
|
byte* url; /* copy of the extAuthInfo in source cert */
|
||||||
|
int urlSz;
|
||||||
|
|
||||||
|
byte nonce[MAX_OCSP_NONCE_SZ];
|
||||||
|
int nonceSz;
|
||||||
|
void* heap;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL void InitOcspResponse(OcspResponse*, CertStatus*, byte*, word32);
|
||||||
|
WOLFSSL_LOCAL int OcspResponseDecode(OcspResponse*, void*, void* heap);
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL int InitOcspRequest(OcspRequest*, DecodedCert*, byte, void*);
|
||||||
|
WOLFSSL_LOCAL void FreeOcspRequest(OcspRequest*);
|
||||||
|
WOLFSSL_LOCAL int EncodeOcspRequest(OcspRequest*, byte*, word32);
|
||||||
|
WOLFSSL_LOCAL word32 EncodeOcspRequestExtensions(OcspRequest*, byte*, word32);
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL int CompareOcspReqResp(OcspRequest*, OcspResponse*);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* HAVE_OCSP */
|
||||||
|
|
||||||
|
|
||||||
|
/* for pointer use */
|
||||||
|
typedef struct RevokedCert RevokedCert;
|
||||||
|
|
||||||
|
#ifdef HAVE_CRL
|
||||||
|
|
||||||
|
struct RevokedCert {
|
||||||
|
byte serialNumber[EXTERNAL_SERIAL_SIZE];
|
||||||
|
int serialSz;
|
||||||
|
RevokedCert* next;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct DecodedCRL DecodedCRL;
|
||||||
|
|
||||||
|
struct DecodedCRL {
|
||||||
|
word32 certBegin; /* offset to start of cert */
|
||||||
|
word32 sigIndex; /* offset to start of signature */
|
||||||
|
word32 sigLength; /* length of signature */
|
||||||
|
word32 signatureOID; /* sum of algorithm object id */
|
||||||
|
byte* signature; /* pointer into raw source, not owned */
|
||||||
|
byte issuerHash[SIGNER_DIGEST_SIZE]; /* issuer hash */
|
||||||
|
byte crlHash[SIGNER_DIGEST_SIZE]; /* raw crl data hash */
|
||||||
|
byte lastDate[MAX_DATE_SIZE]; /* last date updated */
|
||||||
|
byte nextDate[MAX_DATE_SIZE]; /* next update date */
|
||||||
|
byte lastDateFormat; /* format of last date */
|
||||||
|
byte nextDateFormat; /* format of next date */
|
||||||
|
RevokedCert* certs; /* revoked cert list */
|
||||||
|
int totalCerts; /* number on list */
|
||||||
|
void* heap;
|
||||||
|
};
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL void InitDecodedCRL(DecodedCRL*, void* heap);
|
||||||
|
WOLFSSL_LOCAL int ParseCRL(DecodedCRL*, const byte* buff, word32 sz, void* cm);
|
||||||
|
WOLFSSL_LOCAL void FreeDecodedCRL(DecodedCRL*);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* HAVE_CRL */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* !NO_ASN */
|
||||||
|
#endif /* WOLF_CRYPT_ASN_H */
|
|
@ -0,0 +1,288 @@
|
||||||
|
/* asn_public.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_ASN_PUBLIC_H
|
||||||
|
#define WOLF_CRYPT_ASN_PUBLIC_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
#ifdef HAVE_ECC
|
||||||
|
#include <wolfssl/wolfcrypt/ecc.h>
|
||||||
|
#endif
|
||||||
|
#if defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA)
|
||||||
|
#include <wolfssl/wolfcrypt/rsa.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Certificate file Type */
|
||||||
|
enum CertType {
|
||||||
|
CERT_TYPE = 0,
|
||||||
|
PRIVATEKEY_TYPE,
|
||||||
|
DH_PARAM_TYPE,
|
||||||
|
CRL_TYPE,
|
||||||
|
CA_TYPE,
|
||||||
|
ECC_PRIVATEKEY_TYPE,
|
||||||
|
DSA_PRIVATEKEY_TYPE,
|
||||||
|
CERTREQ_TYPE,
|
||||||
|
DSA_TYPE,
|
||||||
|
ECC_TYPE,
|
||||||
|
RSA_TYPE,
|
||||||
|
PUBLICKEY_TYPE,
|
||||||
|
RSA_PUBLICKEY_TYPE,
|
||||||
|
ECC_PUBLICKEY_TYPE,
|
||||||
|
TRUSTED_PEER_TYPE
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Signature type, by OID sum */
|
||||||
|
enum Ctc_SigType {
|
||||||
|
CTC_SHAwDSA = 517,
|
||||||
|
CTC_MD2wRSA = 646,
|
||||||
|
CTC_MD5wRSA = 648,
|
||||||
|
CTC_SHAwRSA = 649,
|
||||||
|
CTC_SHAwECDSA = 520,
|
||||||
|
CTC_SHA224wRSA = 658,
|
||||||
|
CTC_SHA224wECDSA = 527,
|
||||||
|
CTC_SHA256wRSA = 655,
|
||||||
|
CTC_SHA256wECDSA = 524,
|
||||||
|
CTC_SHA384wRSA = 656,
|
||||||
|
CTC_SHA384wECDSA = 525,
|
||||||
|
CTC_SHA512wRSA = 657,
|
||||||
|
CTC_SHA512wECDSA = 526
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Ctc_Encoding {
|
||||||
|
CTC_UTF8 = 0x0c, /* utf8 */
|
||||||
|
CTC_PRINTABLE = 0x13 /* printable */
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Ctc_Misc {
|
||||||
|
CTC_COUNTRY_SIZE = 2,
|
||||||
|
CTC_NAME_SIZE = 64,
|
||||||
|
CTC_DATE_SIZE = 32,
|
||||||
|
CTC_MAX_ALT_SIZE = 16384, /* may be huge */
|
||||||
|
CTC_SERIAL_SIZE = 8,
|
||||||
|
#ifdef WOLFSSL_CERT_EXT
|
||||||
|
/* AKID could contains: hash + (Option) AuthCertIssuer,AuthCertSerialNum
|
||||||
|
* We support only hash */
|
||||||
|
CTC_MAX_SKID_SIZE = 32, /* SHA256_DIGEST_SIZE */
|
||||||
|
CTC_MAX_AKID_SIZE = 32, /* SHA256_DIGEST_SIZE */
|
||||||
|
CTC_MAX_CERTPOL_SZ = 64,
|
||||||
|
CTC_MAX_CERTPOL_NB = 2 /* Max number of Certificate Policy */
|
||||||
|
#endif /* WOLFSSL_CERT_EXT */
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_CERT_GEN
|
||||||
|
|
||||||
|
#ifndef HAVE_ECC
|
||||||
|
typedef struct ecc_key ecc_key;
|
||||||
|
#endif
|
||||||
|
#ifdef NO_RSA
|
||||||
|
typedef struct RsaKey RsaKey;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct CertName {
|
||||||
|
char country[CTC_NAME_SIZE];
|
||||||
|
char countryEnc;
|
||||||
|
char state[CTC_NAME_SIZE];
|
||||||
|
char stateEnc;
|
||||||
|
char locality[CTC_NAME_SIZE];
|
||||||
|
char localityEnc;
|
||||||
|
char sur[CTC_NAME_SIZE];
|
||||||
|
char surEnc;
|
||||||
|
char org[CTC_NAME_SIZE];
|
||||||
|
char orgEnc;
|
||||||
|
char unit[CTC_NAME_SIZE];
|
||||||
|
char unitEnc;
|
||||||
|
char commonName[CTC_NAME_SIZE];
|
||||||
|
char commonNameEnc;
|
||||||
|
char email[CTC_NAME_SIZE]; /* !!!! email has to be last !!!! */
|
||||||
|
} CertName;
|
||||||
|
|
||||||
|
|
||||||
|
/* for user to fill for certificate generation */
|
||||||
|
typedef struct Cert {
|
||||||
|
int version; /* x509 version */
|
||||||
|
byte serial[CTC_SERIAL_SIZE]; /* serial number */
|
||||||
|
int sigType; /* signature algo type */
|
||||||
|
CertName issuer; /* issuer info */
|
||||||
|
int daysValid; /* validity days */
|
||||||
|
int selfSigned; /* self signed flag */
|
||||||
|
CertName subject; /* subject info */
|
||||||
|
int isCA; /* is this going to be a CA */
|
||||||
|
/* internal use only */
|
||||||
|
int bodySz; /* pre sign total size */
|
||||||
|
int keyType; /* public key type of subject */
|
||||||
|
#ifdef WOLFSSL_ALT_NAMES
|
||||||
|
byte altNames[CTC_MAX_ALT_SIZE]; /* altNames copy */
|
||||||
|
int altNamesSz; /* altNames size in bytes */
|
||||||
|
byte beforeDate[CTC_DATE_SIZE]; /* before date copy */
|
||||||
|
int beforeDateSz; /* size of copy */
|
||||||
|
byte afterDate[CTC_DATE_SIZE]; /* after date copy */
|
||||||
|
int afterDateSz; /* size of copy */
|
||||||
|
#endif
|
||||||
|
#ifdef WOLFSSL_CERT_EXT
|
||||||
|
byte skid[CTC_MAX_SKID_SIZE]; /* Subject Key Identifier */
|
||||||
|
int skidSz; /* SKID size in bytes */
|
||||||
|
byte akid[CTC_MAX_AKID_SIZE]; /* Authority Key Identifier */
|
||||||
|
int akidSz; /* AKID size in bytes */
|
||||||
|
word16 keyUsage; /* Key Usage */
|
||||||
|
char certPolicies[CTC_MAX_CERTPOL_NB][CTC_MAX_CERTPOL_SZ];
|
||||||
|
word16 certPoliciesNb; /* Number of Cert Policy */
|
||||||
|
#endif
|
||||||
|
#ifdef WOLFSSL_CERT_REQ
|
||||||
|
char challengePw[CTC_NAME_SIZE];
|
||||||
|
#endif
|
||||||
|
void* heap; /* heap hint */
|
||||||
|
} Cert;
|
||||||
|
#endif /* WOLFSSL_CERT_GEN */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_CERT_GEN
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Initialize and Set Certificate defaults:
|
||||||
|
version = 3 (0x2)
|
||||||
|
serial = 0 (Will be randomly generated)
|
||||||
|
sigType = SHA_WITH_RSA
|
||||||
|
issuer = blank
|
||||||
|
daysValid = 500
|
||||||
|
selfSigned = 1 (true) use subject as issuer
|
||||||
|
subject = blank
|
||||||
|
isCA = 0 (false)
|
||||||
|
keyType = RSA_KEY (default)
|
||||||
|
*/
|
||||||
|
WOLFSSL_API void wc_InitCert(Cert*);
|
||||||
|
WOLFSSL_API int wc_MakeCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*,
|
||||||
|
ecc_key*, WC_RNG*);
|
||||||
|
#ifdef WOLFSSL_CERT_REQ
|
||||||
|
WOLFSSL_API int wc_MakeCertReq(Cert*, byte* derBuffer, word32 derSz,
|
||||||
|
RsaKey*, ecc_key*);
|
||||||
|
#endif
|
||||||
|
WOLFSSL_API int wc_SignCert(int requestSz, int sigType, byte* derBuffer,
|
||||||
|
word32 derSz, RsaKey*, ecc_key*, WC_RNG*);
|
||||||
|
WOLFSSL_API int wc_MakeSelfCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*,
|
||||||
|
WC_RNG*);
|
||||||
|
WOLFSSL_API int wc_SetIssuer(Cert*, const char*);
|
||||||
|
WOLFSSL_API int wc_SetSubject(Cert*, const char*);
|
||||||
|
#ifdef WOLFSSL_ALT_NAMES
|
||||||
|
WOLFSSL_API int wc_SetAltNames(Cert*, const char*);
|
||||||
|
#endif
|
||||||
|
WOLFSSL_API int wc_SetIssuerBuffer(Cert*, const byte*, int);
|
||||||
|
WOLFSSL_API int wc_SetSubjectBuffer(Cert*, const byte*, int);
|
||||||
|
WOLFSSL_API int wc_SetAltNamesBuffer(Cert*, const byte*, int);
|
||||||
|
WOLFSSL_API int wc_SetDatesBuffer(Cert*, const byte*, int);
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_CERT_EXT
|
||||||
|
WOLFSSL_API int wc_SetAuthKeyIdFromPublicKey(Cert *cert, RsaKey *rsakey,
|
||||||
|
ecc_key *eckey);
|
||||||
|
WOLFSSL_API int wc_SetAuthKeyIdFromCert(Cert *cert, const byte *der, int derSz);
|
||||||
|
WOLFSSL_API int wc_SetAuthKeyId(Cert *cert, const char* file);
|
||||||
|
WOLFSSL_API int wc_SetSubjectKeyIdFromPublicKey(Cert *cert, RsaKey *rsakey,
|
||||||
|
ecc_key *eckey);
|
||||||
|
WOLFSSL_API int wc_SetSubjectKeyId(Cert *cert, const char* file);
|
||||||
|
|
||||||
|
#ifdef HAVE_NTRU
|
||||||
|
WOLFSSL_API int wc_SetSubjectKeyIdFromNtruPublicKey(Cert *cert, byte *ntruKey,
|
||||||
|
word16 ntruKeySz);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Set the KeyUsage.
|
||||||
|
* Value is a string separated tokens with ','. Accepted tokens are :
|
||||||
|
* digitalSignature,nonRepudiation,contentCommitment,keyCertSign,cRLSign,
|
||||||
|
* dataEncipherment,keyAgreement,keyEncipherment,encipherOnly and decipherOnly.
|
||||||
|
*
|
||||||
|
* nonRepudiation and contentCommitment are for the same usage.
|
||||||
|
*/
|
||||||
|
WOLFSSL_API int wc_SetKeyUsage(Cert *cert, const char *value);
|
||||||
|
|
||||||
|
#endif /* WOLFSSL_CERT_EXT */
|
||||||
|
|
||||||
|
#ifdef HAVE_NTRU
|
||||||
|
WOLFSSL_API int wc_MakeNtruCert(Cert*, byte* derBuffer, word32 derSz,
|
||||||
|
const byte* ntruKey, word16 keySz,
|
||||||
|
WC_RNG*);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLFSSL_CERT_GEN */
|
||||||
|
|
||||||
|
#if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_PUB_PEM_TO_DER)
|
||||||
|
#ifndef WOLFSSL_PEMPUBKEY_TODER_DEFINED
|
||||||
|
#ifndef NO_FILESYSTEM
|
||||||
|
/* forward from wolfssl */
|
||||||
|
WOLFSSL_API int wolfSSL_PemPubKeyToDer(const char* fileName,
|
||||||
|
unsigned char* derBuf, int derSz);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* forward from wolfssl */
|
||||||
|
WOLFSSL_API int wolfSSL_PubKeyPemToDer(const unsigned char*, int,
|
||||||
|
unsigned char*, int);
|
||||||
|
#define WOLFSSL_PEMPUBKEY_TODER_DEFINED
|
||||||
|
#endif /* WOLFSSL_PEMPUBKEY_TODER_DEFINED */
|
||||||
|
#endif /* WOLFSSL_CERT_EXT || WOLFSSL_PUB_PEM_TO_DER */
|
||||||
|
|
||||||
|
#if defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN) || !defined(NO_DSA)
|
||||||
|
WOLFSSL_API int wc_DerToPem(const byte* der, word32 derSz, byte* output,
|
||||||
|
word32 outputSz, int type);
|
||||||
|
WOLFSSL_API int wc_DerToPemEx(const byte* der, word32 derSz, byte* output,
|
||||||
|
word32 outputSz, byte *cipherIno, int type);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_ECC
|
||||||
|
/* private key helpers */
|
||||||
|
WOLFSSL_API int wc_EccPrivateKeyDecode(const byte*, word32*,
|
||||||
|
ecc_key*, word32);
|
||||||
|
WOLFSSL_API int wc_EccKeyToDer(ecc_key*, byte* output, word32 inLen);
|
||||||
|
|
||||||
|
/* public key helper */
|
||||||
|
WOLFSSL_API int wc_EccPublicKeyDecode(const byte*, word32*,
|
||||||
|
ecc_key*, word32);
|
||||||
|
#if (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
|
||||||
|
WOLFSSL_API int wc_EccPublicKeyToDer(ecc_key*, byte* output,
|
||||||
|
word32 inLen, int with_AlgCurve);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* DER encode signature */
|
||||||
|
WOLFSSL_API word32 wc_EncodeSignature(byte* out, const byte* digest,
|
||||||
|
word32 digSz, int hashOID);
|
||||||
|
WOLFSSL_API int wc_GetCTC_HashOID(int type);
|
||||||
|
|
||||||
|
/* Time */
|
||||||
|
/* Returns seconds (Epoch/UTC)
|
||||||
|
* timePtr: is "time_t", which is typically "long"
|
||||||
|
* Example:
|
||||||
|
long lTime;
|
||||||
|
rc = wc_GetTime(&lTime, (word32)sizeof(lTime));
|
||||||
|
*/
|
||||||
|
WOLFSSL_API int wc_GetTime(void* timePtr, word32 timeSize);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLF_CRYPT_ASN_PUBLIC_H */
|
||||||
|
|
|
@ -0,0 +1,155 @@
|
||||||
|
/*
|
||||||
|
BLAKE2 reference source code package - reference C implementations
|
||||||
|
|
||||||
|
Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
|
||||||
|
|
||||||
|
To the extent possible under law, the author(s) have dedicated all copyright
|
||||||
|
and related and neighboring rights to this software to the public domain
|
||||||
|
worldwide. This software is distributed without any warranty.
|
||||||
|
|
||||||
|
You should have received a copy of the CC0 Public Domain Dedication along with
|
||||||
|
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||||
|
*/
|
||||||
|
/* blake2-impl.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLFCRYPT_BLAKE2_IMPL_H
|
||||||
|
#define WOLFCRYPT_BLAKE2_IMPL_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
static INLINE word32 load32( const void *src )
|
||||||
|
{
|
||||||
|
#if defined(LITTLE_ENDIAN_ORDER)
|
||||||
|
return *( word32 * )( src );
|
||||||
|
#else
|
||||||
|
const byte *p = ( byte * )src;
|
||||||
|
word32 w = *p++;
|
||||||
|
w |= ( word32 )( *p++ ) << 8;
|
||||||
|
w |= ( word32 )( *p++ ) << 16;
|
||||||
|
w |= ( word32 )( *p++ ) << 24;
|
||||||
|
return w;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE word64 load64( const void *src )
|
||||||
|
{
|
||||||
|
#if defined(LITTLE_ENDIAN_ORDER)
|
||||||
|
return *( word64 * )( src );
|
||||||
|
#else
|
||||||
|
const byte *p = ( byte * )src;
|
||||||
|
word64 w = *p++;
|
||||||
|
w |= ( word64 )( *p++ ) << 8;
|
||||||
|
w |= ( word64 )( *p++ ) << 16;
|
||||||
|
w |= ( word64 )( *p++ ) << 24;
|
||||||
|
w |= ( word64 )( *p++ ) << 32;
|
||||||
|
w |= ( word64 )( *p++ ) << 40;
|
||||||
|
w |= ( word64 )( *p++ ) << 48;
|
||||||
|
w |= ( word64 )( *p++ ) << 56;
|
||||||
|
return w;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE void store32( void *dst, word32 w )
|
||||||
|
{
|
||||||
|
#if defined(LITTLE_ENDIAN_ORDER)
|
||||||
|
*( word32 * )( dst ) = w;
|
||||||
|
#else
|
||||||
|
byte *p = ( byte * )dst;
|
||||||
|
*p++ = ( byte )w; w >>= 8;
|
||||||
|
*p++ = ( byte )w; w >>= 8;
|
||||||
|
*p++ = ( byte )w; w >>= 8;
|
||||||
|
*p++ = ( byte )w;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE void store64( void *dst, word64 w )
|
||||||
|
{
|
||||||
|
#if defined(LITTLE_ENDIAN_ORDER)
|
||||||
|
*( word64 * )( dst ) = w;
|
||||||
|
#else
|
||||||
|
byte *p = ( byte * )dst;
|
||||||
|
*p++ = ( byte )w; w >>= 8;
|
||||||
|
*p++ = ( byte )w; w >>= 8;
|
||||||
|
*p++ = ( byte )w; w >>= 8;
|
||||||
|
*p++ = ( byte )w; w >>= 8;
|
||||||
|
*p++ = ( byte )w; w >>= 8;
|
||||||
|
*p++ = ( byte )w; w >>= 8;
|
||||||
|
*p++ = ( byte )w; w >>= 8;
|
||||||
|
*p++ = ( byte )w;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE word64 load48( const void *src )
|
||||||
|
{
|
||||||
|
const byte *p = ( const byte * )src;
|
||||||
|
word64 w = *p++;
|
||||||
|
w |= ( word64 )( *p++ ) << 8;
|
||||||
|
w |= ( word64 )( *p++ ) << 16;
|
||||||
|
w |= ( word64 )( *p++ ) << 24;
|
||||||
|
w |= ( word64 )( *p++ ) << 32;
|
||||||
|
w |= ( word64 )( *p++ ) << 40;
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE void store48( void *dst, word64 w )
|
||||||
|
{
|
||||||
|
byte *p = ( byte * )dst;
|
||||||
|
*p++ = ( byte )w; w >>= 8;
|
||||||
|
*p++ = ( byte )w; w >>= 8;
|
||||||
|
*p++ = ( byte )w; w >>= 8;
|
||||||
|
*p++ = ( byte )w; w >>= 8;
|
||||||
|
*p++ = ( byte )w; w >>= 8;
|
||||||
|
*p++ = ( byte )w;
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE word32 rotl32( const word32 w, const unsigned c )
|
||||||
|
{
|
||||||
|
return ( w << c ) | ( w >> ( 32 - c ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE word64 rotl64( const word64 w, const unsigned c )
|
||||||
|
{
|
||||||
|
return ( w << c ) | ( w >> ( 64 - c ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE word32 rotr32( const word32 w, const unsigned c )
|
||||||
|
{
|
||||||
|
return ( w >> c ) | ( w << ( 32 - c ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE word64 rotr64( const word64 w, const unsigned c )
|
||||||
|
{
|
||||||
|
return ( w >> c ) | ( w << ( 64 - c ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* prevents compiler optimizing out memset() */
|
||||||
|
static INLINE void secure_zero_memory( void *v, word64 n )
|
||||||
|
{
|
||||||
|
volatile byte *p = ( volatile byte * )v;
|
||||||
|
|
||||||
|
while( n-- ) *p++ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* WOLFCRYPT_BLAKE2_IMPL_H */
|
||||||
|
|
|
@ -0,0 +1,184 @@
|
||||||
|
/*
|
||||||
|
BLAKE2 reference source code package - reference C implementations
|
||||||
|
|
||||||
|
Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
|
||||||
|
|
||||||
|
To the extent possible under law, the author(s) have dedicated all copyright
|
||||||
|
and related and neighboring rights to this software to the public domain
|
||||||
|
worldwide. This software is distributed without any warranty.
|
||||||
|
|
||||||
|
You should have received a copy of the CC0 Public Domain Dedication along with
|
||||||
|
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||||
|
*/
|
||||||
|
/* blake2-int.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLFCRYPT_BLAKE2_INT_H
|
||||||
|
#define WOLFCRYPT_BLAKE2_INT_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#define ALIGN(x) __declspec(align(x))
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
#define ALIGN(x) __attribute__((aligned(x)))
|
||||||
|
#else
|
||||||
|
#define ALIGN(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum blake2s_constant
|
||||||
|
{
|
||||||
|
BLAKE2S_BLOCKBYTES = 64,
|
||||||
|
BLAKE2S_OUTBYTES = 32,
|
||||||
|
BLAKE2S_KEYBYTES = 32,
|
||||||
|
BLAKE2S_SALTBYTES = 8,
|
||||||
|
BLAKE2S_PERSONALBYTES = 8
|
||||||
|
};
|
||||||
|
|
||||||
|
enum blake2b_constant
|
||||||
|
{
|
||||||
|
BLAKE2B_BLOCKBYTES = 128,
|
||||||
|
BLAKE2B_OUTBYTES = 64,
|
||||||
|
BLAKE2B_KEYBYTES = 64,
|
||||||
|
BLAKE2B_SALTBYTES = 16,
|
||||||
|
BLAKE2B_PERSONALBYTES = 16
|
||||||
|
};
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
typedef struct __blake2s_param
|
||||||
|
{
|
||||||
|
byte digest_length; /* 1 */
|
||||||
|
byte key_length; /* 2 */
|
||||||
|
byte fanout; /* 3 */
|
||||||
|
byte depth; /* 4 */
|
||||||
|
word32 leaf_length; /* 8 */
|
||||||
|
byte node_offset[6];/* 14 */
|
||||||
|
byte node_depth; /* 15 */
|
||||||
|
byte inner_length; /* 16 */
|
||||||
|
/* byte reserved[0]; */
|
||||||
|
byte salt[BLAKE2B_SALTBYTES]; /* 24 */
|
||||||
|
byte personal[BLAKE2S_PERSONALBYTES]; /* 32 */
|
||||||
|
} blake2s_param;
|
||||||
|
|
||||||
|
ALIGN( 64 ) typedef struct __blake2s_state
|
||||||
|
{
|
||||||
|
word32 h[8];
|
||||||
|
word32 t[2];
|
||||||
|
word32 f[2];
|
||||||
|
byte buf[2 * BLAKE2S_BLOCKBYTES];
|
||||||
|
word64 buflen;
|
||||||
|
byte last_node;
|
||||||
|
} blake2s_state ;
|
||||||
|
|
||||||
|
typedef struct __blake2b_param
|
||||||
|
{
|
||||||
|
byte digest_length; /* 1 */
|
||||||
|
byte key_length; /* 2 */
|
||||||
|
byte fanout; /* 3 */
|
||||||
|
byte depth; /* 4 */
|
||||||
|
word32 leaf_length; /* 8 */
|
||||||
|
word64 node_offset; /* 16 */
|
||||||
|
byte node_depth; /* 17 */
|
||||||
|
byte inner_length; /* 18 */
|
||||||
|
byte reserved[14]; /* 32 */
|
||||||
|
byte salt[BLAKE2B_SALTBYTES]; /* 48 */
|
||||||
|
byte personal[BLAKE2B_PERSONALBYTES]; /* 64 */
|
||||||
|
} blake2b_param;
|
||||||
|
|
||||||
|
ALIGN( 64 ) typedef struct __blake2b_state
|
||||||
|
{
|
||||||
|
word64 h[8];
|
||||||
|
word64 t[2];
|
||||||
|
word64 f[2];
|
||||||
|
byte buf[2 * BLAKE2B_BLOCKBYTES];
|
||||||
|
word64 buflen;
|
||||||
|
byte last_node;
|
||||||
|
} blake2b_state;
|
||||||
|
|
||||||
|
typedef struct __blake2sp_state
|
||||||
|
{
|
||||||
|
blake2s_state S[8][1];
|
||||||
|
blake2s_state R[1];
|
||||||
|
byte buf[8 * BLAKE2S_BLOCKBYTES];
|
||||||
|
word64 buflen;
|
||||||
|
} blake2sp_state;
|
||||||
|
|
||||||
|
typedef struct __blake2bp_state
|
||||||
|
{
|
||||||
|
blake2b_state S[4][1];
|
||||||
|
blake2b_state R[1];
|
||||||
|
byte buf[4 * BLAKE2B_BLOCKBYTES];
|
||||||
|
word64 buflen;
|
||||||
|
} blake2bp_state;
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
/* Streaming API */
|
||||||
|
int blake2s_init( blake2s_state *S, const byte outlen );
|
||||||
|
int blake2s_init_key( blake2s_state *S, const byte outlen, const void *key, const byte keylen );
|
||||||
|
int blake2s_init_param( blake2s_state *S, const blake2s_param *P );
|
||||||
|
int blake2s_update( blake2s_state *S, const byte *in, word64 inlen );
|
||||||
|
int blake2s_final( blake2s_state *S, byte *out, byte outlen );
|
||||||
|
|
||||||
|
int blake2b_init( blake2b_state *S, const byte outlen );
|
||||||
|
int blake2b_init_key( blake2b_state *S, const byte outlen, const void *key, const byte keylen );
|
||||||
|
int blake2b_init_param( blake2b_state *S, const blake2b_param *P );
|
||||||
|
int blake2b_update( blake2b_state *S, const byte *in, word64 inlen );
|
||||||
|
int blake2b_final( blake2b_state *S, byte *out, byte outlen );
|
||||||
|
|
||||||
|
int blake2sp_init( blake2sp_state *S, const byte outlen );
|
||||||
|
int blake2sp_init_key( blake2sp_state *S, const byte outlen, const void *key, const byte keylen );
|
||||||
|
int blake2sp_update( blake2sp_state *S, const byte *in, word64 inlen );
|
||||||
|
int blake2sp_final( blake2sp_state *S, byte *out, byte outlen );
|
||||||
|
|
||||||
|
int blake2bp_init( blake2bp_state *S, const byte outlen );
|
||||||
|
int blake2bp_init_key( blake2bp_state *S, const byte outlen, const void *key, const byte keylen );
|
||||||
|
int blake2bp_update( blake2bp_state *S, const byte *in, word64 inlen );
|
||||||
|
int blake2bp_final( blake2bp_state *S, byte *out, byte outlen );
|
||||||
|
|
||||||
|
/* Simple API */
|
||||||
|
int blake2s( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen );
|
||||||
|
int blake2b( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen );
|
||||||
|
|
||||||
|
int blake2sp( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen );
|
||||||
|
int blake2bp( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen );
|
||||||
|
|
||||||
|
static INLINE int blake2( byte *out, const void *in, const void *key, const byte outlen, const word64 inlen, byte keylen )
|
||||||
|
{
|
||||||
|
return blake2b( out, in, key, outlen, inlen, keylen );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLFCRYPT_BLAKE2_INT_H */
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
/* blake2.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_BLAKE2_H
|
||||||
|
#define WOLF_CRYPT_BLAKE2_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/settings.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_BLAKE2
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/blake2-int.h>
|
||||||
|
|
||||||
|
/* call old functions if using fips for the sake of hmac @wc_fips */
|
||||||
|
#ifdef HAVE_FIPS
|
||||||
|
/* Since hmac can call blake functions provide original calls */
|
||||||
|
#define wc_InitBlake2b InitBlake2b
|
||||||
|
#define wc_Blake2bUpdate Blake2bUpdate
|
||||||
|
#define wc_Blake2bFinal Blake2bFinal
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* in bytes, variable digest size up to 512 bits (64 bytes) */
|
||||||
|
enum {
|
||||||
|
BLAKE2B_ID = 7, /* hash type unique */
|
||||||
|
BLAKE2B_256 = 32 /* 256 bit type, SSL default */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* BLAKE2b digest */
|
||||||
|
typedef struct Blake2b {
|
||||||
|
blake2b_state S[1]; /* our state */
|
||||||
|
word32 digestSz; /* digest size used on init */
|
||||||
|
} Blake2b;
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_InitBlake2b(Blake2b*, word32);
|
||||||
|
WOLFSSL_API int wc_Blake2bUpdate(Blake2b*, const byte*, word32);
|
||||||
|
WOLFSSL_API int wc_Blake2bFinal(Blake2b*, byte*, word32);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAVE_BLAKE2 */
|
||||||
|
#endif /* WOLF_CRYPT_BLAKE2_H */
|
||||||
|
|
|
@ -0,0 +1,97 @@
|
||||||
|
/* camellia.h ver 1.2.0
|
||||||
|
*
|
||||||
|
* Copyright (c) 2006,2007
|
||||||
|
* NTT (Nippon Telegraph and Telephone Corporation) . All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer as
|
||||||
|
* the first lines of this file unmodified.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY NTT ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
* IN NO EVENT SHALL NTT BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* camellia.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_CAMELLIA_H
|
||||||
|
#define WOLF_CRYPT_CAMELLIA_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_CAMELLIA
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum {
|
||||||
|
CAMELLIA_BLOCK_SIZE = 16
|
||||||
|
};
|
||||||
|
|
||||||
|
#define CAMELLIA_TABLE_BYTE_LEN 272
|
||||||
|
#define CAMELLIA_TABLE_WORD_LEN (CAMELLIA_TABLE_BYTE_LEN / sizeof(word32))
|
||||||
|
|
||||||
|
typedef word32 KEY_TABLE_TYPE[CAMELLIA_TABLE_WORD_LEN];
|
||||||
|
|
||||||
|
typedef struct Camellia {
|
||||||
|
word32 keySz;
|
||||||
|
KEY_TABLE_TYPE key;
|
||||||
|
word32 reg[CAMELLIA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
|
||||||
|
word32 tmp[CAMELLIA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
|
||||||
|
} Camellia;
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_CamelliaSetKey(Camellia* cam,
|
||||||
|
const byte* key, word32 len, const byte* iv);
|
||||||
|
WOLFSSL_API int wc_CamelliaSetIV(Camellia* cam, const byte* iv);
|
||||||
|
WOLFSSL_API void wc_CamelliaEncryptDirect(Camellia* cam, byte* out,
|
||||||
|
const byte* in);
|
||||||
|
WOLFSSL_API void wc_CamelliaDecryptDirect(Camellia* cam, byte* out,
|
||||||
|
const byte* in);
|
||||||
|
WOLFSSL_API void wc_CamelliaCbcEncrypt(Camellia* cam,
|
||||||
|
byte* out, const byte* in, word32 sz);
|
||||||
|
WOLFSSL_API void wc_CamelliaCbcDecrypt(Camellia* cam,
|
||||||
|
byte* out, const byte* in, word32 sz);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAVE_CAMELLIA */
|
||||||
|
#endif /* WOLF_CRYPT_CAMELLIA_H */
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
/* chacha.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_CHACHA_H
|
||||||
|
#define WOLF_CRYPT_CHACHA_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_CHACHA
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Size of the IV */
|
||||||
|
#define CHACHA_IV_WORDS 3
|
||||||
|
#define CHACHA_IV_BYTES (CHACHA_IV_WORDS * sizeof(word32))
|
||||||
|
|
||||||
|
/* Size of ChaCha chunks */
|
||||||
|
#define CHACHA_CHUNK_WORDS 16
|
||||||
|
#define CHACHA_CHUNK_BYTES (CHACHA_CHUNK_WORDS * sizeof(word32))
|
||||||
|
|
||||||
|
enum {
|
||||||
|
CHACHA_ENC_TYPE = 7 /* cipher unique type */
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct ChaCha {
|
||||||
|
word32 X[CHACHA_CHUNK_WORDS]; /* state of cipher */
|
||||||
|
} ChaCha;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IV(nonce) changes with each record
|
||||||
|
* counter is for what value the block counter should start ... usually 0
|
||||||
|
*/
|
||||||
|
WOLFSSL_API int wc_Chacha_SetIV(ChaCha* ctx, const byte* inIv, word32 counter);
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_Chacha_Process(ChaCha* ctx, byte* cipher, const byte* plain,
|
||||||
|
word32 msglen);
|
||||||
|
WOLFSSL_API int wc_Chacha_SetKey(ChaCha* ctx, const byte* key, word32 keySz);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAVE_CHACHA */
|
||||||
|
#endif /* WOLF_CRYPT_CHACHA_H */
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
/* chacha20_poly1305.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* This implementation of the ChaCha20-Poly1305 AEAD is based on "ChaCha20
|
||||||
|
* and Poly1305 for IETF protocols" (draft-irtf-cfrg-chacha20-poly1305-10):
|
||||||
|
* https://tools.ietf.org/html/draft-irtf-cfrg-chacha20-poly1305-10
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_CHACHA20_POLY1305_H
|
||||||
|
#define WOLF_CRYPT_CHACHA20_POLY1305_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CHACHA20_POLY1305_AEAD_KEYSIZE 32
|
||||||
|
#define CHACHA20_POLY1305_AEAD_IV_SIZE 12
|
||||||
|
#define CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE 16
|
||||||
|
|
||||||
|
enum {
|
||||||
|
CHACHA20_POLY_1305_ENC_TYPE = 8 /* cipher unique type */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The IV for this implementation is 96 bits to give the most flexibility.
|
||||||
|
*
|
||||||
|
* Some protocols may have unique per-invocation inputs that are not
|
||||||
|
* 96-bit in length. For example, IPsec may specify a 64-bit nonce. In
|
||||||
|
* such a case, it is up to the protocol document to define how to
|
||||||
|
* transform the protocol nonce into a 96-bit nonce, for example by
|
||||||
|
* concatenating a constant value.
|
||||||
|
*/
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ChaCha20Poly1305_Encrypt(
|
||||||
|
const byte inKey[CHACHA20_POLY1305_AEAD_KEYSIZE],
|
||||||
|
const byte inIV[CHACHA20_POLY1305_AEAD_IV_SIZE],
|
||||||
|
const byte* inAAD, const word32 inAADLen,
|
||||||
|
const byte* inPlaintext, const word32 inPlaintextLen,
|
||||||
|
byte* outCiphertext,
|
||||||
|
byte outAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE]);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ChaCha20Poly1305_Decrypt(
|
||||||
|
const byte inKey[CHACHA20_POLY1305_AEAD_KEYSIZE],
|
||||||
|
const byte inIV[CHACHA20_POLY1305_AEAD_IV_SIZE],
|
||||||
|
const byte* inAAD, const word32 inAADLen,
|
||||||
|
const byte* inCiphertext, const word32 inCiphertextLen,
|
||||||
|
const byte inAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE],
|
||||||
|
byte* outPlaintext);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAVE_CHACHA && HAVE_POLY1305 */
|
||||||
|
#endif /* WOLF_CRYPT_CHACHA20_POLY1305_H */
|
|
@ -0,0 +1,79 @@
|
||||||
|
/* cmac.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_CMAC_H
|
||||||
|
#define WOLF_CRYPT_CMAC_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
#include <wolfssl/wolfcrypt/aes.h>
|
||||||
|
|
||||||
|
#if !defined(NO_AES) && defined(WOLFSSL_CMAC)
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct Cmac {
|
||||||
|
Aes aes;
|
||||||
|
byte buffer[AES_BLOCK_SIZE]; /* partially stored block */
|
||||||
|
byte digest[AES_BLOCK_SIZE]; /* running digest */
|
||||||
|
byte k1[AES_BLOCK_SIZE];
|
||||||
|
byte k2[AES_BLOCK_SIZE];
|
||||||
|
word32 bufferSz;
|
||||||
|
word32 totalSz;
|
||||||
|
} Cmac;
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum CmacType {
|
||||||
|
WC_CMAC_AES = 1
|
||||||
|
} CmacType;
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_InitCmac(Cmac* cmac,
|
||||||
|
const byte* key, word32 keySz,
|
||||||
|
int type, void* unused);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_CmacUpdate(Cmac* cmac,
|
||||||
|
const byte* in, word32 inSz);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_CmacFinal(Cmac* cmac,
|
||||||
|
byte* out, word32* outSz);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_AesCmacGenerate(byte* out, word32* outSz,
|
||||||
|
const byte* in, word32 inSz,
|
||||||
|
const byte* key, word32 keySz);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_AesCmacVerify(const byte* check, word32 checkSz,
|
||||||
|
const byte* in, word32 inSz,
|
||||||
|
const byte* key, word32 keySz);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* NO_AES && WOLFSSL_CMAC */
|
||||||
|
#endif /* WOLF_CRYPT_CMAC_H */
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
/* coding.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_CODING_H
|
||||||
|
#define WOLF_CRYPT_CODING_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API int Base64_Decode(const byte* in, word32 inLen, byte* out,
|
||||||
|
word32* outLen);
|
||||||
|
|
||||||
|
#if defined(OPENSSL_EXTRA) || defined(SESSION_CERTS) || defined(WOLFSSL_KEY_GEN) \
|
||||||
|
|| defined(WOLFSSL_CERT_GEN) || defined(HAVE_WEBSERVER) || !defined(NO_DSA)
|
||||||
|
#ifndef WOLFSSL_BASE64_ENCODE
|
||||||
|
#define WOLFSSL_BASE64_ENCODE
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_BASE64_ENCODE
|
||||||
|
enum Escaped {
|
||||||
|
WC_STD_ENC = 0, /* normal \n line ending encoding */
|
||||||
|
WC_ESC_NL_ENC, /* use escape sequence encoding */
|
||||||
|
WC_NO_NL_ENC /* no encoding at all */
|
||||||
|
}; /* Encoding types */
|
||||||
|
|
||||||
|
/* encode isn't */
|
||||||
|
WOLFSSL_API
|
||||||
|
int Base64_Encode(const byte* in, word32 inLen, byte* out,
|
||||||
|
word32* outLen);
|
||||||
|
WOLFSSL_API
|
||||||
|
int Base64_EncodeEsc(const byte* in, word32 inLen, byte* out,
|
||||||
|
word32* outLen);
|
||||||
|
WOLFSSL_API
|
||||||
|
int Base64_Encode_NoNl(const byte* in, word32 inLen, byte* out,
|
||||||
|
word32* outLen);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) || defined(HAVE_FIPS)
|
||||||
|
WOLFSSL_API
|
||||||
|
int Base16_Decode(const byte* in, word32 inLen, byte* out, word32* outLen);
|
||||||
|
WOLFSSL_API
|
||||||
|
int Base16_Encode(const byte* in, word32 inLen, byte* out, word32* outLen);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLF_CRYPT_CODING_H */
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
/* compress.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_COMPRESS_H
|
||||||
|
#define WOLF_CRYPT_COMPRESS_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBZ
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define COMPRESS_FIXED 1
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_Compress(byte*, word32, const byte*, word32, word32);
|
||||||
|
WOLFSSL_API int wc_DeCompress(byte*, word32, const byte*, word32);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* HAVE_LIBZ */
|
||||||
|
#endif /* WOLF_CRYPT_COMPRESS_H */
|
||||||
|
|
|
@ -0,0 +1,145 @@
|
||||||
|
/* curve25519.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_CURVE25519_H
|
||||||
|
#define WOLF_CRYPT_CURVE25519_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_CURVE25519
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/fe_operations.h>
|
||||||
|
#include <wolfssl/wolfcrypt/random.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CURVE25519_KEYSIZE 32
|
||||||
|
|
||||||
|
/* curve25519 set type */
|
||||||
|
typedef struct {
|
||||||
|
int size; /* The size of the curve in octets */
|
||||||
|
const char* name; /* name of this curve */
|
||||||
|
} curve25519_set_type;
|
||||||
|
|
||||||
|
|
||||||
|
/* ECC point, the internal structure is Little endian
|
||||||
|
* the mathematical functions used the endianess */
|
||||||
|
typedef struct {
|
||||||
|
byte point[CURVE25519_KEYSIZE];
|
||||||
|
#ifdef FREESCALE_LTC_ECC
|
||||||
|
byte pointY[CURVE25519_KEYSIZE];
|
||||||
|
#endif
|
||||||
|
}ECPoint;
|
||||||
|
|
||||||
|
/* A CURVE25519 Key */
|
||||||
|
typedef struct {
|
||||||
|
int idx; /* Index into the ecc_sets[] for the parameters of
|
||||||
|
this curve if -1, this key is using user supplied
|
||||||
|
curve in dp */
|
||||||
|
const curve25519_set_type* dp; /* domain parameters, either points to
|
||||||
|
curves (idx >= 0) or user supplied */
|
||||||
|
ECPoint p; /* public key */
|
||||||
|
ECPoint k; /* private key */
|
||||||
|
} curve25519_key;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
EC25519_LITTLE_ENDIAN=0,
|
||||||
|
EC25519_BIG_ENDIAN=1
|
||||||
|
};
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_curve25519_shared_secret(curve25519_key* private_key,
|
||||||
|
curve25519_key* public_key,
|
||||||
|
byte* out, word32* outlen);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_curve25519_shared_secret_ex(curve25519_key* private_key,
|
||||||
|
curve25519_key* public_key,
|
||||||
|
byte* out, word32* outlen, int endian);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_curve25519_init(curve25519_key* key);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
void wc_curve25519_free(curve25519_key* key);
|
||||||
|
|
||||||
|
|
||||||
|
/* raw key helpers */
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_curve25519_import_private(const byte* priv, word32 privSz,
|
||||||
|
curve25519_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_curve25519_import_private_ex(const byte* priv, word32 privSz,
|
||||||
|
curve25519_key* key, int endian);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_curve25519_import_private_raw(const byte* priv, word32 privSz,
|
||||||
|
const byte* pub, word32 pubSz, curve25519_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_curve25519_import_private_raw_ex(const byte* priv, word32 privSz,
|
||||||
|
const byte* pub, word32 pubSz,
|
||||||
|
curve25519_key* key, int endian);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_curve25519_export_private_raw(curve25519_key* key, byte* out,
|
||||||
|
word32* outLen);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_curve25519_export_private_raw_ex(curve25519_key* key, byte* out,
|
||||||
|
word32* outLen, int endian);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_curve25519_import_public(const byte* in, word32 inLen,
|
||||||
|
curve25519_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_curve25519_import_public_ex(const byte* in, word32 inLen,
|
||||||
|
curve25519_key* key, int endian);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_curve25519_export_public(curve25519_key* key, byte* out, word32* outLen);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_curve25519_export_public_ex(curve25519_key* key, byte* out,
|
||||||
|
word32* outLen, int endian);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_curve25519_export_key_raw(curve25519_key* key,
|
||||||
|
byte* priv, word32 *privSz,
|
||||||
|
byte* pub, word32 *pubSz);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_curve25519_export_key_raw_ex(curve25519_key* key,
|
||||||
|
byte* priv, word32 *privSz,
|
||||||
|
byte* pub, word32 *pubSz,
|
||||||
|
int endian);
|
||||||
|
/* size helper */
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_curve25519_size(curve25519_key* key);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAVE_CURVE25519 */
|
||||||
|
#endif /* WOLF_CRYPT_CURVE25519_H */
|
||||||
|
|
|
@ -0,0 +1,117 @@
|
||||||
|
/* des3.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_DES3_H
|
||||||
|
#define WOLF_CRYPT_DES3_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifndef NO_DES3
|
||||||
|
|
||||||
|
#ifdef HAVE_FIPS
|
||||||
|
/* included for fips @wc_fips */
|
||||||
|
#include <cyassl/ctaocrypt/des3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_FIPS /* to avoid redefinition of macros */
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
#include <wolfssl/wolfcrypt/async.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum {
|
||||||
|
DES_ENC_TYPE = 2, /* cipher unique type */
|
||||||
|
DES3_ENC_TYPE = 3, /* cipher unique type */
|
||||||
|
DES_BLOCK_SIZE = 8,
|
||||||
|
DES_KS_SIZE = 32,
|
||||||
|
|
||||||
|
DES_ENCRYPTION = 0,
|
||||||
|
DES_DECRYPTION = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
#define DES_IVLEN 8
|
||||||
|
#define DES_KEYLEN 8
|
||||||
|
#define DES3_IVLEN 8
|
||||||
|
#define DES3_KEYLEN 24
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(STM32F2_CRYPTO) || defined(STM32F4_CRYPTO)
|
||||||
|
enum {
|
||||||
|
DES_CBC = 0,
|
||||||
|
DES_ECB = 1
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* DES encryption and decryption */
|
||||||
|
typedef struct Des {
|
||||||
|
word32 reg[DES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
|
||||||
|
word32 tmp[DES_BLOCK_SIZE / sizeof(word32)]; /* same */
|
||||||
|
word32 key[DES_KS_SIZE];
|
||||||
|
} Des;
|
||||||
|
|
||||||
|
|
||||||
|
/* DES3 encryption and decryption */
|
||||||
|
typedef struct Des3 {
|
||||||
|
word32 key[3][DES_KS_SIZE];
|
||||||
|
word32 reg[DES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
|
||||||
|
word32 tmp[DES_BLOCK_SIZE / sizeof(word32)]; /* same */
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
AsyncCryptDev asyncDev;
|
||||||
|
#endif
|
||||||
|
} Des3;
|
||||||
|
#endif /* HAVE_FIPS */
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_Des_SetKey(Des* des, const byte* key,
|
||||||
|
const byte* iv, int dir);
|
||||||
|
WOLFSSL_API void wc_Des_SetIV(Des* des, const byte* iv);
|
||||||
|
WOLFSSL_API int wc_Des_CbcEncrypt(Des* des, byte* out,
|
||||||
|
const byte* in, word32 sz);
|
||||||
|
WOLFSSL_API int wc_Des_CbcDecrypt(Des* des, byte* out,
|
||||||
|
const byte* in, word32 sz);
|
||||||
|
WOLFSSL_API int wc_Des_EcbEncrypt(Des* des, byte* out,
|
||||||
|
const byte* in, word32 sz);
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_Des3_SetKey(Des3* des, const byte* key,
|
||||||
|
const byte* iv,int dir);
|
||||||
|
WOLFSSL_API int wc_Des3_SetIV(Des3* des, const byte* iv);
|
||||||
|
WOLFSSL_API int wc_Des3_CbcEncrypt(Des3* des, byte* out,
|
||||||
|
const byte* in,word32 sz);
|
||||||
|
WOLFSSL_API int wc_Des3_CbcDecrypt(Des3* des, byte* out,
|
||||||
|
const byte* in,word32 sz);
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
WOLFSSL_API int wc_Des3AsyncInit(Des3*, int);
|
||||||
|
WOLFSSL_API void wc_Des3AsyncFree(Des3*);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* NO_DES3 */
|
||||||
|
#endif /* WOLF_CRYPT_DES3_H */
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
/* dh.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_DH_H
|
||||||
|
#define WOLF_CRYPT_DH_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifndef NO_DH
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/integer.h>
|
||||||
|
#include <wolfssl/wolfcrypt/random.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Diffie-Hellman Key */
|
||||||
|
typedef struct DhKey {
|
||||||
|
mp_int p, g; /* group parameters */
|
||||||
|
} DhKey;
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API void wc_InitDhKey(DhKey* key);
|
||||||
|
WOLFSSL_API void wc_FreeDhKey(DhKey* key);
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_DhGenerateKeyPair(DhKey* key, WC_RNG* rng, byte* priv,
|
||||||
|
word32* privSz, byte* pub, word32* pubSz);
|
||||||
|
WOLFSSL_API int wc_DhAgree(DhKey* key, byte* agree, word32* agreeSz,
|
||||||
|
const byte* priv, word32 privSz, const byte* otherPub,
|
||||||
|
word32 pubSz);
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_DhKeyDecode(const byte* input, word32* inOutIdx, DhKey* key,
|
||||||
|
word32);
|
||||||
|
WOLFSSL_API int wc_DhSetKey(DhKey* key, const byte* p, word32 pSz, const byte* g,
|
||||||
|
word32 gSz);
|
||||||
|
WOLFSSL_API int wc_DhParamsLoad(const byte* input, word32 inSz, byte* p,
|
||||||
|
word32* pInOutSz, byte* g, word32* gInOutSz);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* NO_DH */
|
||||||
|
#endif /* WOLF_CRYPT_DH_H */
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
/* dsa.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_DSA_H
|
||||||
|
#define WOLF_CRYPT_DSA_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifndef NO_DSA
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/integer.h>
|
||||||
|
#include <wolfssl/wolfcrypt/random.h>
|
||||||
|
|
||||||
|
/* for DSA reverse compatibility */
|
||||||
|
#define InitDsaKey wc_InitDsaKey
|
||||||
|
#define FreeDsaKey wc_FreeDsaKey
|
||||||
|
#define DsaSign wc_DsaSign
|
||||||
|
#define DsaVerify wc_DsaVerify
|
||||||
|
#define DsaPublicKeyDecode wc_DsaPublicKeyDecode
|
||||||
|
#define DsaPrivateKeyDecode wc_DsaPrivateKeyDecode
|
||||||
|
#define DsaKeyToDer wc_DsaKeyToDer
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
enum {
|
||||||
|
DSA_PUBLIC = 0,
|
||||||
|
DSA_PRIVATE = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
/* DSA */
|
||||||
|
typedef struct DsaKey {
|
||||||
|
mp_int p, q, g, y, x;
|
||||||
|
int type; /* public or private */
|
||||||
|
void* heap; /* memory hint */
|
||||||
|
} DsaKey;
|
||||||
|
|
||||||
|
WOLFSSL_API void wc_InitDsaKey(DsaKey* key);
|
||||||
|
WOLFSSL_API int wc_InitDsaKey_h(DsaKey* key, void* h);
|
||||||
|
WOLFSSL_API void wc_FreeDsaKey(DsaKey* key);
|
||||||
|
WOLFSSL_API int wc_DsaSign(const byte* digest, byte* out,
|
||||||
|
DsaKey* key, WC_RNG* rng);
|
||||||
|
WOLFSSL_API int wc_DsaVerify(const byte* digest, const byte* sig,
|
||||||
|
DsaKey* key, int* answer);
|
||||||
|
WOLFSSL_API int wc_DsaPublicKeyDecode(const byte* input, word32* inOutIdx,
|
||||||
|
DsaKey*, word32);
|
||||||
|
WOLFSSL_API int wc_DsaPrivateKeyDecode(const byte* input, word32* inOutIdx,
|
||||||
|
DsaKey*, word32);
|
||||||
|
WOLFSSL_API int wc_DsaKeyToDer(DsaKey* key, byte* output, word32 inLen);
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_KEY_GEN
|
||||||
|
WOLFSSL_API int wc_MakeDsaKey(WC_RNG *rng, DsaKey *dsa);
|
||||||
|
WOLFSSL_API int wc_MakeDsaParameters(WC_RNG *rng, int modulus_size, DsaKey *dsa);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* NO_DSA */
|
||||||
|
#endif /* WOLF_CRYPT_DSA_H */
|
||||||
|
|
|
@ -0,0 +1,477 @@
|
||||||
|
/* ecc.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_ECC_H
|
||||||
|
#define WOLF_CRYPT_ECC_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_ECC
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/integer.h>
|
||||||
|
#include <wolfssl/wolfcrypt/random.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_X963_KDF
|
||||||
|
#include <wolfssl/wolfcrypt/hash.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
#include <wolfssl/wolfcrypt/async.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_ATECC508A
|
||||||
|
#include <wolfssl/wolfcrypt/port/atmel/atmel.h>
|
||||||
|
#endif /* WOLFSSL_ATECC508A */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum {
|
||||||
|
ECC_PUBLICKEY = 1,
|
||||||
|
ECC_PRIVATEKEY = 2,
|
||||||
|
ECC_MAXNAME = 16, /* MAX CURVE NAME LENGTH */
|
||||||
|
SIG_HEADER_SZ = 6, /* ECC signature header size */
|
||||||
|
ECC_BUFSIZE = 256, /* for exported keys temp buffer */
|
||||||
|
ECC_MINSIZE = 20, /* MIN Private Key size */
|
||||||
|
ECC_MAXSIZE = 66, /* MAX Private Key size */
|
||||||
|
ECC_MAXSIZE_GEN = 74, /* MAX Buffer size required when generating ECC keys*/
|
||||||
|
ECC_MAX_PAD_SZ = 4, /* ECC maximum padding size */
|
||||||
|
ECC_MAX_OID_LEN = 16,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Curve Types */
|
||||||
|
typedef enum ecc_curve_id {
|
||||||
|
ECC_CURVE_DEF, /* NIST or SECP */
|
||||||
|
|
||||||
|
/* NIST Prime Curves */
|
||||||
|
ECC_SECP192R1,
|
||||||
|
ECC_PRIME192V2,
|
||||||
|
ECC_PRIME192V3,
|
||||||
|
ECC_PRIME239V1,
|
||||||
|
ECC_PRIME239V2,
|
||||||
|
ECC_PRIME239V3,
|
||||||
|
ECC_SECP256R1,
|
||||||
|
|
||||||
|
/* SECP Curves */
|
||||||
|
ECC_SECP112R1,
|
||||||
|
ECC_SECP112R2,
|
||||||
|
ECC_SECP128R1,
|
||||||
|
ECC_SECP128R2,
|
||||||
|
ECC_SECP160R1,
|
||||||
|
ECC_SECP160R2,
|
||||||
|
ECC_SECP224R1,
|
||||||
|
ECC_SECP384R1,
|
||||||
|
ECC_SECP521R1,
|
||||||
|
|
||||||
|
/* Koblitz */
|
||||||
|
ECC_SECP160K1,
|
||||||
|
ECC_SECP192K1,
|
||||||
|
ECC_SECP224K1,
|
||||||
|
ECC_SECP256K1,
|
||||||
|
|
||||||
|
/* Brainpool Curves */
|
||||||
|
ECC_BRAINPOOLP160R1,
|
||||||
|
ECC_BRAINPOOLP192R1,
|
||||||
|
ECC_BRAINPOOLP224R1,
|
||||||
|
ECC_BRAINPOOLP256R1,
|
||||||
|
ECC_BRAINPOOLP320R1,
|
||||||
|
ECC_BRAINPOOLP384R1,
|
||||||
|
ECC_BRAINPOOLP512R1,
|
||||||
|
} ecc_curve_id;
|
||||||
|
|
||||||
|
#ifdef HAVE_OID_ENCODING
|
||||||
|
typedef word16 ecc_oid_t;
|
||||||
|
#else
|
||||||
|
typedef byte ecc_oid_t;
|
||||||
|
/* OID encoded with ASN scheme:
|
||||||
|
first element = (oid[0] * 40) + oid[1]
|
||||||
|
if any element > 127 then MSB 0x80 indicates additional byte */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ECC set type defined a GF(p) curve */
|
||||||
|
typedef struct {
|
||||||
|
int size; /* The size of the curve in octets */
|
||||||
|
int id; /* id of this curve */
|
||||||
|
const char* name; /* name of this curve */
|
||||||
|
const char* prime; /* prime that defines the field, curve is in (hex) */
|
||||||
|
const char* Af; /* fields A param (hex) */
|
||||||
|
const char* Bf; /* fields B param (hex) */
|
||||||
|
const char* order; /* order of the curve (hex) */
|
||||||
|
const char* Gx; /* x coordinate of the base point on curve (hex) */
|
||||||
|
const char* Gy; /* y coordinate of the base point on curve (hex) */
|
||||||
|
const ecc_oid_t* oid;
|
||||||
|
word32 oidSz;
|
||||||
|
word32 oidSum; /* sum of encoded OID bytes */
|
||||||
|
int cofactor;
|
||||||
|
} ecc_set_type;
|
||||||
|
|
||||||
|
|
||||||
|
/* Use this as the key->idx if a custom ecc_set is used for key->dp */
|
||||||
|
#define ECC_CUSTOM_IDX (-1)
|
||||||
|
|
||||||
|
|
||||||
|
/* Determine max ECC bits based on enabled curves */
|
||||||
|
#if defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)
|
||||||
|
#define MAX_ECC_BITS 521
|
||||||
|
#elif defined(HAVE_ECC512)
|
||||||
|
#define MAX_ECC_BITS 512
|
||||||
|
#elif defined(HAVE_ECC384)
|
||||||
|
#define MAX_ECC_BITS 384
|
||||||
|
#elif defined(HAVE_ECC320)
|
||||||
|
#define MAX_ECC_BITS 320
|
||||||
|
#elif defined(HAVE_ECC239)
|
||||||
|
#define MAX_ECC_BITS 239
|
||||||
|
#elif defined(HAVE_ECC224)
|
||||||
|
#define MAX_ECC_BITS 224
|
||||||
|
#elif !defined(NO_ECC256)
|
||||||
|
#define MAX_ECC_BITS 256
|
||||||
|
#elif defined(HAVE_ECC192)
|
||||||
|
#define MAX_ECC_BITS 192
|
||||||
|
#elif defined(HAVE_ECC160)
|
||||||
|
#define MAX_ECC_BITS 160
|
||||||
|
#elif defined(HAVE_ECC128)
|
||||||
|
#define MAX_ECC_BITS 128
|
||||||
|
#elif defined(HAVE_ECC112)
|
||||||
|
#define MAX_ECC_BITS 112
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef ALT_ECC_SIZE
|
||||||
|
|
||||||
|
/* Note on ALT_ECC_SIZE:
|
||||||
|
* The fast math code uses an array of a fixed size to store the big integers.
|
||||||
|
* By default, the array is big enough for RSA keys. There is a size,
|
||||||
|
* FP_MAX_BITS which can be used to make the array smaller when one wants ECC
|
||||||
|
* but not RSA. Some people want fast math sized for both RSA and ECC, where
|
||||||
|
* ECC won't use as much as RSA. The flag ALT_ECC_SIZE switches in an alternate
|
||||||
|
* ecc_point structure that uses an alternate fp_int that has a shorter array
|
||||||
|
* of fp_digits.
|
||||||
|
*
|
||||||
|
* Now, without ALT_ECC_SIZE, the ecc_point has three single item arrays of
|
||||||
|
* mp_ints for the components of the point. With ALT_ECC_SIZE, the components
|
||||||
|
* of the point are pointers that are set to each of a three item array of
|
||||||
|
* alt_fp_ints. While an mp_int will have 4096 bits of digit inside the
|
||||||
|
* structure, the alt_fp_int will only have 528 bits. A size value was added
|
||||||
|
* in the ALT case, as well, and is set by mp_init() and alt_fp_init(). The
|
||||||
|
* functions fp_zero() and fp_copy() use the size parameter. An int needs to
|
||||||
|
* be initialized before using it instead of just fp_zeroing it, the init will
|
||||||
|
* call zero. FP_MAX_BITS_ECC defaults to 528, but can be set to change the
|
||||||
|
* number of bits used in the alternate FP_INT.
|
||||||
|
*
|
||||||
|
* Do not enable ALT_ECC_SIZE and disable fast math in the configuration.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef USE_FAST_MATH
|
||||||
|
#error USE_FAST_MATH must be defined to use ALT_ECC_SIZE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* determine max bits required for ECC math */
|
||||||
|
#ifndef FP_MAX_BITS_ECC
|
||||||
|
/* check alignment */
|
||||||
|
#if ((MAX_ECC_BITS * 2) % DIGIT_BIT) == 0
|
||||||
|
/* max bits is double */
|
||||||
|
#define FP_MAX_BITS_ECC (MAX_ECC_BITS * 2)
|
||||||
|
#else
|
||||||
|
/* max bits is doubled, plus one digit of fudge */
|
||||||
|
#define FP_MAX_BITS_ECC ((MAX_ECC_BITS * 2) + DIGIT_BIT)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
/* verify alignment */
|
||||||
|
#if FP_MAX_BITS_ECC % CHAR_BIT
|
||||||
|
#error FP_MAX_BITS_ECC must be a multiple of CHAR_BIT
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* determine buffer size */
|
||||||
|
#define FP_SIZE_ECC (FP_MAX_BITS_ECC/DIGIT_BIT)
|
||||||
|
|
||||||
|
|
||||||
|
/* This needs to match the size of the fp_int struct, except the
|
||||||
|
* fp_digit array will be shorter. */
|
||||||
|
typedef struct alt_fp_int {
|
||||||
|
int used, sign, size;
|
||||||
|
fp_digit dp[FP_SIZE_ECC];
|
||||||
|
} alt_fp_int;
|
||||||
|
#endif /* ALT_ECC_SIZE */
|
||||||
|
|
||||||
|
/* A point on an ECC curve, stored in Jacbobian format such that (x,y,z) =>
|
||||||
|
(x/z^2, y/z^3, 1) when interpreted as affine */
|
||||||
|
typedef struct {
|
||||||
|
#ifndef ALT_ECC_SIZE
|
||||||
|
mp_int x[1]; /* The x coordinate */
|
||||||
|
mp_int y[1]; /* The y coordinate */
|
||||||
|
mp_int z[1]; /* The z coordinate */
|
||||||
|
#else
|
||||||
|
mp_int* x; /* The x coordinate */
|
||||||
|
mp_int* y; /* The y coordinate */
|
||||||
|
mp_int* z; /* The z coordinate */
|
||||||
|
alt_fp_int xyz[3];
|
||||||
|
#endif
|
||||||
|
} ecc_point;
|
||||||
|
|
||||||
|
|
||||||
|
/* An ECC Key */
|
||||||
|
typedef struct ecc_key {
|
||||||
|
int type; /* Public or Private */
|
||||||
|
int idx; /* Index into the ecc_sets[] for the parameters of
|
||||||
|
this curve if -1, this key is using user supplied
|
||||||
|
curve in dp */
|
||||||
|
const ecc_set_type* dp; /* domain parameters, either points to NIST
|
||||||
|
curves (idx >= 0) or user supplied */
|
||||||
|
void* heap; /* heap hint */
|
||||||
|
#ifdef WOLFSSL_ATECC508A
|
||||||
|
int slot; /* Key Slot Number (-1 unknown) */
|
||||||
|
byte pubkey[PUB_KEY_SIZE];
|
||||||
|
#else
|
||||||
|
ecc_point pubkey; /* public key */
|
||||||
|
mp_int k; /* private key */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
AsyncCryptDev asyncDev;
|
||||||
|
#endif
|
||||||
|
} ecc_key;
|
||||||
|
|
||||||
|
|
||||||
|
/* ECC predefined curve sets */
|
||||||
|
extern const ecc_set_type ecc_sets[];
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_make_key(WC_RNG* rng, int keysize, ecc_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_make_key_ex(WC_RNG* rng, int keysize, ecc_key* key,
|
||||||
|
int curve_id);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_check_key(ecc_key* key);
|
||||||
|
|
||||||
|
#ifdef HAVE_ECC_DHE
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, byte* out,
|
||||||
|
word32* outlen);
|
||||||
|
#ifndef WOLFSSL_ATECC508A
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_shared_secret_ssh(ecc_key* private_key, ecc_point* point,
|
||||||
|
byte* out, word32 *outlen);
|
||||||
|
#endif /* !WOLFSSL_ATECC508A */
|
||||||
|
#endif /* HAVE_ECC_DHE */
|
||||||
|
|
||||||
|
#ifdef HAVE_ECC_SIGN
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen,
|
||||||
|
WC_RNG* rng, ecc_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_sign_hash_ex(const byte* in, word32 inlen, WC_RNG* rng,
|
||||||
|
ecc_key* key, mp_int *r, mp_int *s);
|
||||||
|
#endif /* HAVE_ECC_SIGN */
|
||||||
|
|
||||||
|
#ifdef HAVE_ECC_VERIFY
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_verify_hash(const byte* sig, word32 siglen, const byte* hash,
|
||||||
|
word32 hashlen, int* stat, ecc_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash,
|
||||||
|
word32 hashlen, int* stat, ecc_key* key);
|
||||||
|
#endif /* HAVE_ECC_VERIFY */
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_init(ecc_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_init_ex(ecc_key* key, void* heap, int devId);
|
||||||
|
WOLFSSL_API
|
||||||
|
void wc_ecc_free(ecc_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
void wc_ecc_fp_free(void);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_is_valid_idx(int n);
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_ATECC508A
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
ecc_point* wc_ecc_new_point(void);
|
||||||
|
WOLFSSL_API
|
||||||
|
ecc_point* wc_ecc_new_point_h(void* h);
|
||||||
|
WOLFSSL_API
|
||||||
|
void wc_ecc_del_point(ecc_point* p);
|
||||||
|
WOLFSSL_API
|
||||||
|
void wc_ecc_del_point_h(ecc_point* p, void* h);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_copy_point(ecc_point* p, ecc_point *r);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_cmp_point(ecc_point* a, ecc_point *b);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_point_is_at_infinity(ecc_point *p);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R,
|
||||||
|
mp_int* a, mp_int* modulus, int map);
|
||||||
|
WOLFSSL_LOCAL
|
||||||
|
int wc_ecc_mulmod_ex(mp_int* k, ecc_point *G, ecc_point *R,
|
||||||
|
mp_int* a, mp_int* modulus, int map, void* heap);
|
||||||
|
#endif /* !WOLFSSL_ATECC508A */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_ECC_KEY_EXPORT
|
||||||
|
/* ASN key helpers */
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_export_x963(ecc_key*, byte* out, word32* outLen);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_export_x963_ex(ecc_key*, byte* out, word32* outLen, int compressed);
|
||||||
|
/* extended functionality with compressed option */
|
||||||
|
#endif /* HAVE_ECC_KEY_EXPORT */
|
||||||
|
|
||||||
|
#ifdef HAVE_ECC_KEY_IMPORT
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_import_x963(const byte* in, word32 inLen, ecc_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
|
||||||
|
int curve_id);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_import_private_key(const byte* priv, word32 privSz, const byte* pub,
|
||||||
|
word32 pubSz, ecc_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz,
|
||||||
|
const byte* pub, word32 pubSz, ecc_key* key, int curve_id);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_rs_to_sig(const char* r, const char* s, byte* out, word32* outlen);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_import_raw(ecc_key* key, const char* qx, const char* qy,
|
||||||
|
const char* d, const char* curveName);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_import_raw_ex(ecc_key* key, const char* qx, const char* qy,
|
||||||
|
const char* d, int curve_id);
|
||||||
|
#endif /* HAVE_ECC_KEY_IMPORT */
|
||||||
|
|
||||||
|
#ifdef HAVE_ECC_KEY_EXPORT
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_export_private_only(ecc_key* key, byte* out, word32* outLen);
|
||||||
|
#endif /* HAVE_ECC_KEY_EXPORT */
|
||||||
|
|
||||||
|
#ifdef HAVE_ECC_KEY_EXPORT
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_export_point_der(const int curve_idx, ecc_point* point,
|
||||||
|
byte* out, word32* outLen);
|
||||||
|
#endif /* HAVE_ECC_KEY_EXPORT */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_ECC_KEY_IMPORT
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_import_point_der(byte* in, word32 inLen, const int curve_idx,
|
||||||
|
ecc_point* point);
|
||||||
|
#endif /* HAVE_ECC_KEY_IMPORT */
|
||||||
|
|
||||||
|
/* size helper */
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_size(ecc_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_sig_size(ecc_key* key);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_get_oid(word32 oidSum, const byte** oid, word32* oidSz);
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_CUSTOM_CURVES
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_set_custom_curve(ecc_key* key, const ecc_set_type* dp);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_ECC_ENCRYPT
|
||||||
|
/* ecc encrypt */
|
||||||
|
|
||||||
|
enum ecEncAlgo {
|
||||||
|
ecAES_128_CBC = 1, /* default */
|
||||||
|
ecAES_256_CBC = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ecKdfAlgo {
|
||||||
|
ecHKDF_SHA256 = 1, /* default */
|
||||||
|
ecHKDF_SHA1 = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ecMacAlgo {
|
||||||
|
ecHMAC_SHA256 = 1, /* default */
|
||||||
|
ecHMAC_SHA1 = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
KEY_SIZE_128 = 16,
|
||||||
|
KEY_SIZE_256 = 32,
|
||||||
|
IV_SIZE_64 = 8,
|
||||||
|
IV_SIZE_128 = 16,
|
||||||
|
EXCHANGE_SALT_SZ = 16,
|
||||||
|
EXCHANGE_INFO_SZ = 23
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ecFlags {
|
||||||
|
REQ_RESP_CLIENT = 1,
|
||||||
|
REQ_RESP_SERVER = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct ecEncCtx ecEncCtx;
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
ecEncCtx* wc_ecc_ctx_new(int flags, WC_RNG* rng);
|
||||||
|
WOLFSSL_API
|
||||||
|
ecEncCtx* wc_ecc_ctx_new_ex(int flags, WC_RNG* rng, void* heap);
|
||||||
|
WOLFSSL_API
|
||||||
|
void wc_ecc_ctx_free(ecEncCtx*);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_ctx_reset(ecEncCtx*, WC_RNG*); /* reset for use again w/o alloc/free */
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
const byte* wc_ecc_ctx_get_own_salt(ecEncCtx*);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_ctx_set_peer_salt(ecEncCtx*, const byte* salt);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_ctx_set_info(ecEncCtx*, const byte* info, int sz);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
|
||||||
|
word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
|
||||||
|
word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx);
|
||||||
|
|
||||||
|
#endif /* HAVE_ECC_ENCRYPT */
|
||||||
|
|
||||||
|
#ifdef HAVE_X963_KDF
|
||||||
|
WOLFSSL_API int wc_X963_KDF(enum wc_HashType type, const byte* secret,
|
||||||
|
word32 secretSz, const byte* sinfo, word32 sinfoSz,
|
||||||
|
byte* out, word32 outSz);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
WOLFSSL_API int wc_ecc_async_handle(ecc_key* key,
|
||||||
|
WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event);
|
||||||
|
WOLFSSL_API int wc_ecc_async_wait(int ret, ecc_key* key);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAVE_ECC */
|
||||||
|
#endif /* WOLF_CRYPT_ECC_H */
|
|
@ -0,0 +1,113 @@
|
||||||
|
/* ed25519.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_ED25519_H
|
||||||
|
#define WOLF_CRYPT_ED25519_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_ED25519
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/fe_operations.h>
|
||||||
|
#include <wolfssl/wolfcrypt/ge_operations.h>
|
||||||
|
#include <wolfssl/wolfcrypt/random.h>
|
||||||
|
#include <wolfssl/wolfcrypt/sha512.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* info about EdDSA curve specifically ed25519, defined as an elliptic curve
|
||||||
|
over GF(p) */
|
||||||
|
/*
|
||||||
|
32, key size
|
||||||
|
"ED25519", curve name
|
||||||
|
"2^255-19", prime number
|
||||||
|
"SHA512", hash function
|
||||||
|
"-121665/121666", value of d
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define ED25519_KEY_SIZE 32 /* private key only */
|
||||||
|
#define ED25519_SIG_SIZE 64
|
||||||
|
|
||||||
|
#define ED25519_PUB_KEY_SIZE 32 /* compressed */
|
||||||
|
/* both private and public key */
|
||||||
|
#define ED25519_PRV_KEY_SIZE (ED25519_PUB_KEY_SIZE+ED25519_KEY_SIZE)
|
||||||
|
|
||||||
|
/* An ED25519 Key */
|
||||||
|
typedef struct {
|
||||||
|
byte p[ED25519_PUB_KEY_SIZE]; /* compressed public key */
|
||||||
|
byte k[ED25519_PRV_KEY_SIZE]; /* private key : 32 secret -- 32 public */
|
||||||
|
#ifdef FREESCALE_LTC_ECC
|
||||||
|
/* uncompressed point coordinates */
|
||||||
|
byte pointX[ED25519_KEY_SIZE]; /* recovered X coordinate */
|
||||||
|
byte pointY[ED25519_KEY_SIZE]; /* Y coordinate is the public key with The most significant bit of the final octet always zero. */
|
||||||
|
#endif
|
||||||
|
} ed25519_key;
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ed25519_make_key(WC_RNG* rng, int keysize, ed25519_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ed25519_sign_msg(const byte* in, word32 inlen, byte* out,
|
||||||
|
word32 *outlen, ed25519_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ed25519_verify_msg(byte* sig, word32 siglen, const byte* msg,
|
||||||
|
word32 msglen, int* stat, ed25519_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ed25519_init(ed25519_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
void wc_ed25519_free(ed25519_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ed25519_import_public(const byte* in, word32 inLen, ed25519_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ed25519_import_private_key(const byte* priv, word32 privSz,
|
||||||
|
const byte* pub, word32 pubSz, ed25519_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ed25519_export_public(ed25519_key*, byte* out, word32* outLen);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ed25519_export_private_only(ed25519_key* key, byte* out, word32* outLen);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ed25519_export_private(ed25519_key* key, byte* out, word32* outLen);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ed25519_export_key(ed25519_key* key,
|
||||||
|
byte* priv, word32 *privSz,
|
||||||
|
byte* pub, word32 *pubSz);
|
||||||
|
|
||||||
|
/* size helper */
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ed25519_size(ed25519_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ed25519_priv_size(ed25519_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ed25519_pub_size(ed25519_key* key);
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ed25519_sig_size(ed25519_key* key);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAVE_ED25519 */
|
||||||
|
#endif /* WOLF_CRYPT_ED25519_H */
|
||||||
|
|
|
@ -0,0 +1,198 @@
|
||||||
|
/* error-crypt.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_ERROR_H
|
||||||
|
#define WOLF_CRYPT_ERROR_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_FIPS
|
||||||
|
#include <cyassl/ctaocrypt/error-crypt.h>
|
||||||
|
#endif /* HAVE_FIPS */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* error codes, add string for new errors !!! */
|
||||||
|
enum {
|
||||||
|
MAX_CODE_E = -100, /* errors -101 - -299 */
|
||||||
|
OPEN_RAN_E = -101, /* opening random device error */
|
||||||
|
READ_RAN_E = -102, /* reading random device error */
|
||||||
|
WINCRYPT_E = -103, /* windows crypt init error */
|
||||||
|
CRYPTGEN_E = -104, /* windows crypt generation error */
|
||||||
|
RAN_BLOCK_E = -105, /* reading random device would block */
|
||||||
|
BAD_MUTEX_E = -106, /* Bad mutex operation */
|
||||||
|
WC_TIMEOUT_E = -107, /* timeout error */
|
||||||
|
WC_PENDING_E = -108, /* wolfCrypt operation pending (would block) */
|
||||||
|
WC_NOT_PENDING_E = -109, /* wolfCrypt operation not pending */
|
||||||
|
|
||||||
|
MP_INIT_E = -110, /* mp_init error state */
|
||||||
|
MP_READ_E = -111, /* mp_read error state */
|
||||||
|
MP_EXPTMOD_E = -112, /* mp_exptmod error state */
|
||||||
|
MP_TO_E = -113, /* mp_to_xxx error state, can't convert */
|
||||||
|
MP_SUB_E = -114, /* mp_sub error state, can't subtract */
|
||||||
|
MP_ADD_E = -115, /* mp_add error state, can't add */
|
||||||
|
MP_MUL_E = -116, /* mp_mul error state, can't multiply */
|
||||||
|
MP_MULMOD_E = -117, /* mp_mulmod error state, can't multiply mod */
|
||||||
|
MP_MOD_E = -118, /* mp_mod error state, can't mod */
|
||||||
|
MP_INVMOD_E = -119, /* mp_invmod error state, can't inv mod */
|
||||||
|
MP_CMP_E = -120, /* mp_cmp error state */
|
||||||
|
MP_ZERO_E = -121, /* got a mp zero result, not expected */
|
||||||
|
|
||||||
|
MEMORY_E = -125, /* out of memory error */
|
||||||
|
VAR_STATE_CHANGE_E = -126, /* var state modified by different thread */
|
||||||
|
|
||||||
|
RSA_WRONG_TYPE_E = -130, /* RSA wrong block type for RSA function */
|
||||||
|
RSA_BUFFER_E = -131, /* RSA buffer error, output too small or
|
||||||
|
input too large */
|
||||||
|
BUFFER_E = -132, /* output buffer too small or input too large */
|
||||||
|
ALGO_ID_E = -133, /* setting algo id error */
|
||||||
|
PUBLIC_KEY_E = -134, /* setting public key error */
|
||||||
|
DATE_E = -135, /* setting date validity error */
|
||||||
|
SUBJECT_E = -136, /* setting subject name error */
|
||||||
|
ISSUER_E = -137, /* setting issuer name error */
|
||||||
|
CA_TRUE_E = -138, /* setting CA basic constraint true error */
|
||||||
|
EXTENSIONS_E = -139, /* setting extensions error */
|
||||||
|
|
||||||
|
ASN_PARSE_E = -140, /* ASN parsing error, invalid input */
|
||||||
|
ASN_VERSION_E = -141, /* ASN version error, invalid number */
|
||||||
|
ASN_GETINT_E = -142, /* ASN get big int error, invalid data */
|
||||||
|
ASN_RSA_KEY_E = -143, /* ASN key init error, invalid input */
|
||||||
|
ASN_OBJECT_ID_E = -144, /* ASN object id error, invalid id */
|
||||||
|
ASN_TAG_NULL_E = -145, /* ASN tag error, not null */
|
||||||
|
ASN_EXPECT_0_E = -146, /* ASN expect error, not zero */
|
||||||
|
ASN_BITSTR_E = -147, /* ASN bit string error, wrong id */
|
||||||
|
ASN_UNKNOWN_OID_E = -148, /* ASN oid error, unknown sum id */
|
||||||
|
ASN_DATE_SZ_E = -149, /* ASN date error, bad size */
|
||||||
|
ASN_BEFORE_DATE_E = -150, /* ASN date error, current date before */
|
||||||
|
ASN_AFTER_DATE_E = -151, /* ASN date error, current date after */
|
||||||
|
ASN_SIG_OID_E = -152, /* ASN signature error, mismatched oid */
|
||||||
|
ASN_TIME_E = -153, /* ASN time error, unknown time type */
|
||||||
|
ASN_INPUT_E = -154, /* ASN input error, not enough data */
|
||||||
|
ASN_SIG_CONFIRM_E = -155, /* ASN sig error, confirm failure */
|
||||||
|
ASN_SIG_HASH_E = -156, /* ASN sig error, unsupported hash type */
|
||||||
|
ASN_SIG_KEY_E = -157, /* ASN sig error, unsupported key type */
|
||||||
|
ASN_DH_KEY_E = -158, /* ASN key init error, invalid input */
|
||||||
|
ASN_NTRU_KEY_E = -159, /* ASN ntru key decode error, invalid input */
|
||||||
|
ASN_CRIT_EXT_E = -160, /* ASN unsupported critical extension */
|
||||||
|
|
||||||
|
ECC_BAD_ARG_E = -170, /* ECC input argument of wrong type */
|
||||||
|
ASN_ECC_KEY_E = -171, /* ASN ECC bad input */
|
||||||
|
ECC_CURVE_OID_E = -172, /* Unsupported ECC OID curve type */
|
||||||
|
BAD_FUNC_ARG = -173, /* Bad function argument provided */
|
||||||
|
NOT_COMPILED_IN = -174, /* Feature not compiled in */
|
||||||
|
UNICODE_SIZE_E = -175, /* Unicode password too big */
|
||||||
|
NO_PASSWORD = -176, /* no password provided by user */
|
||||||
|
ALT_NAME_E = -177, /* alt name size problem, too big */
|
||||||
|
|
||||||
|
AES_GCM_AUTH_E = -180, /* AES-GCM Authentication check failure */
|
||||||
|
AES_CCM_AUTH_E = -181, /* AES-CCM Authentication check failure */
|
||||||
|
|
||||||
|
ASYNC_INIT_E = -182, /* Async Init type error */
|
||||||
|
|
||||||
|
COMPRESS_INIT_E = -183, /* Compress init error */
|
||||||
|
COMPRESS_E = -184, /* Compress error */
|
||||||
|
DECOMPRESS_INIT_E = -185, /* DeCompress init error */
|
||||||
|
DECOMPRESS_E = -186, /* DeCompress error */
|
||||||
|
|
||||||
|
BAD_ALIGN_E = -187, /* Bad alignment for operation, no alloc */
|
||||||
|
ASN_NO_SIGNER_E = -188, /* ASN no signer to confirm failure */
|
||||||
|
ASN_CRL_CONFIRM_E = -189, /* ASN CRL signature confirm failure */
|
||||||
|
ASN_CRL_NO_SIGNER_E = -190, /* ASN CRL no signer to confirm failure */
|
||||||
|
ASN_OCSP_CONFIRM_E = -191, /* ASN OCSP signature confirm failure */
|
||||||
|
|
||||||
|
BAD_STATE_E = -192, /* Bad state operation */
|
||||||
|
BAD_PADDING_E = -193, /* Bad padding, msg not correct length */
|
||||||
|
|
||||||
|
REQ_ATTRIBUTE_E = -194, /* setting cert request attributes error */
|
||||||
|
|
||||||
|
PKCS7_OID_E = -195, /* PKCS#7, mismatched OID error */
|
||||||
|
PKCS7_RECIP_E = -196, /* PKCS#7, recipient error */
|
||||||
|
FIPS_NOT_ALLOWED_E = -197, /* FIPS not allowed error */
|
||||||
|
ASN_NAME_INVALID_E = -198, /* ASN name constraint error */
|
||||||
|
|
||||||
|
RNG_FAILURE_E = -199, /* RNG Failed, Reinitialize */
|
||||||
|
HMAC_MIN_KEYLEN_E = -200, /* FIPS Mode HMAC Minimum Key Length error */
|
||||||
|
RSA_PAD_E = -201, /* RSA Padding Error */
|
||||||
|
LENGTH_ONLY_E = -202, /* Returning output length only */
|
||||||
|
|
||||||
|
IN_CORE_FIPS_E = -203, /* In Core Integrity check failure */
|
||||||
|
AES_KAT_FIPS_E = -204, /* AES KAT failure */
|
||||||
|
DES3_KAT_FIPS_E = -205, /* DES3 KAT failure */
|
||||||
|
HMAC_KAT_FIPS_E = -206, /* HMAC KAT failure */
|
||||||
|
RSA_KAT_FIPS_E = -207, /* RSA KAT failure */
|
||||||
|
DRBG_KAT_FIPS_E = -208, /* HASH DRBG KAT failure */
|
||||||
|
DRBG_CONT_FIPS_E = -209, /* HASH DRBG Continuous test failure */
|
||||||
|
AESGCM_KAT_FIPS_E = -210, /* AESGCM KAT failure */
|
||||||
|
THREAD_STORE_KEY_E = -211, /* Thread local storage key create failure */
|
||||||
|
THREAD_STORE_SET_E = -212, /* Thread local storage key set failure */
|
||||||
|
|
||||||
|
MAC_CMP_FAILED_E = -213, /* MAC comparison failed */
|
||||||
|
IS_POINT_E = -214, /* ECC is point on curve failed */
|
||||||
|
ECC_INF_E = -215, /* ECC point infinity error */
|
||||||
|
ECC_PRIV_KEY_E = -216, /* ECC private key not valid error */
|
||||||
|
|
||||||
|
SRP_CALL_ORDER_E = -217, /* SRP function called in the wrong order. */
|
||||||
|
SRP_VERIFY_E = -218, /* SRP proof verification failed. */
|
||||||
|
SRP_BAD_KEY_E = -219, /* SRP bad ephemeral values. */
|
||||||
|
|
||||||
|
ASN_NO_SKID = -220, /* ASN no Subject Key Identifier found */
|
||||||
|
ASN_NO_AKID = -221, /* ASN no Authority Key Identifier found */
|
||||||
|
ASN_NO_KEYUSAGE = -223, /* ASN no Key Usage found */
|
||||||
|
SKID_E = -224, /* setting Subject Key Identifier error */
|
||||||
|
AKID_E = -225, /* setting Authority Key Identifier error */
|
||||||
|
KEYUSAGE_E = -226, /* Bad Key Usage value */
|
||||||
|
CERTPOLICIES_E = -227, /* setting Certificate Policies error */
|
||||||
|
|
||||||
|
WC_INIT_E = -228, /* wolfcrypt failed to initialize */
|
||||||
|
SIG_VERIFY_E = -229, /* wolfcrypt signature verify error */
|
||||||
|
BAD_COND_E = -230, /* Bad condition variable operation */
|
||||||
|
SIG_TYPE_E = -231, /* Signature Type not enabled/available */
|
||||||
|
HASH_TYPE_E = -232, /* Hash Type not enabled/available */
|
||||||
|
|
||||||
|
WC_KEY_SIZE_E = -234, /* Key size error, either too small or large */
|
||||||
|
ASN_COUNTRY_SIZE_E = -235, /* ASN Cert Gen, invalid country code size */
|
||||||
|
MISSING_RNG_E = -236, /* RNG required but not provided */
|
||||||
|
ASN_PATHLEN_SIZE_E = -237, /* ASN CA path length too large error */
|
||||||
|
ASN_PATHLEN_INV_E = -238, /* ASN CA path length inversion error */
|
||||||
|
|
||||||
|
BAD_KEYWRAP_ALG_E = -239,
|
||||||
|
BAD_KEYWRAP_IV_E = -240, /* Decrypted AES key wrap IV incorrect */
|
||||||
|
|
||||||
|
MIN_CODE_E = -300 /* errors -101 - -299 */
|
||||||
|
|
||||||
|
/* add new companion error id strings for any new error codes
|
||||||
|
wolfcrypt/src/error.c !!! */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API void wc_ErrorString(int err, char* buff);
|
||||||
|
WOLFSSL_API const char* wc_GetErrorString(int error);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
#endif /* WOLF_CRYPT_ERROR_H */
|
|
@ -0,0 +1,135 @@
|
||||||
|
/* fe_operations.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_FE_OPERATIONS_H
|
||||||
|
#define WOLF_CRYPT_FE_OPERATIONS_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/settings.h>
|
||||||
|
|
||||||
|
#if defined(HAVE_CURVE25519) || defined(HAVE_ED25519)
|
||||||
|
|
||||||
|
#ifndef CURVED25519_SMALL
|
||||||
|
#include <stdint.h>
|
||||||
|
#endif
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
fe means field element.
|
||||||
|
Here the field is \Z/(2^255-19).
|
||||||
|
An element t, entries t[0]...t[9], represents the integer
|
||||||
|
t[0]+2^26 t[1]+2^51 t[2]+2^77 t[3]+2^102 t[4]+...+2^230 t[9].
|
||||||
|
Bounds on each t[i] vary depending on context.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef CURVED25519_SMALL
|
||||||
|
#define F25519_SIZE 32
|
||||||
|
typedef byte fe[32];
|
||||||
|
#else
|
||||||
|
typedef int32_t fe[10];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if! defined FREESCALE_LTC_ECC
|
||||||
|
WOLFSSL_LOCAL int curve25519(byte * q, byte * n, byte * p);
|
||||||
|
#endif
|
||||||
|
WOLFSSL_LOCAL void fe_copy(fe, const fe);
|
||||||
|
WOLFSSL_LOCAL void fe_add(fe, const fe, const fe);
|
||||||
|
WOLFSSL_LOCAL void fe_neg(fe,const fe);
|
||||||
|
WOLFSSL_LOCAL void fe_sub(fe, const fe, const fe);
|
||||||
|
WOLFSSL_LOCAL void fe_invert(fe, const fe);
|
||||||
|
WOLFSSL_LOCAL void fe_mul(fe,const fe,const fe);
|
||||||
|
|
||||||
|
/* default to be faster but take more memory */
|
||||||
|
#ifndef CURVED25519_SMALL
|
||||||
|
|
||||||
|
/* Based On Daniel J Bernstein's curve25519 and ed25519 Public Domain ref10
|
||||||
|
work. */
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL void fe_0(fe);
|
||||||
|
WOLFSSL_LOCAL void fe_1(fe);
|
||||||
|
WOLFSSL_LOCAL int fe_isnonzero(const fe);
|
||||||
|
WOLFSSL_LOCAL int fe_isnegative(const fe);
|
||||||
|
WOLFSSL_LOCAL void fe_tobytes(unsigned char *, const fe);
|
||||||
|
WOLFSSL_LOCAL void fe_sq(fe, const fe);
|
||||||
|
WOLFSSL_LOCAL void fe_sq2(fe,const fe);
|
||||||
|
WOLFSSL_LOCAL void fe_frombytes(fe,const unsigned char *);
|
||||||
|
WOLFSSL_LOCAL void fe_cswap(fe,fe,unsigned int);
|
||||||
|
WOLFSSL_LOCAL void fe_mul121666(fe,fe);
|
||||||
|
WOLFSSL_LOCAL void fe_cmov(fe,const fe,unsigned int);
|
||||||
|
WOLFSSL_LOCAL void fe_pow22523(fe,const fe);
|
||||||
|
|
||||||
|
/* 64 type needed for SHA512 */
|
||||||
|
WOLFSSL_LOCAL uint64_t load_3(const unsigned char *in);
|
||||||
|
WOLFSSL_LOCAL uint64_t load_4(const unsigned char *in);
|
||||||
|
#endif /* not defined CURVED25519_SMALL */
|
||||||
|
|
||||||
|
/* Use less memory and only 32bit types or less, but is slower
|
||||||
|
Based on Daniel Beer's public domain work. */
|
||||||
|
#ifdef CURVED25519_SMALL
|
||||||
|
static const byte c25519_base_x[F25519_SIZE] = {9};
|
||||||
|
static const byte f25519_zero[F25519_SIZE] = {0};
|
||||||
|
static const byte f25519_one[F25519_SIZE] = {1};
|
||||||
|
static const byte fprime_zero[F25519_SIZE] = {0};
|
||||||
|
static const byte fprime_one[F25519_SIZE] = {1};
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL void fe_load(byte *x, word32 c);
|
||||||
|
WOLFSSL_LOCAL void fe_normalize(byte *x);
|
||||||
|
WOLFSSL_LOCAL void fe_inv__distinct(byte *r, const byte *x);
|
||||||
|
|
||||||
|
/* Conditional copy. If condition == 0, then zero is copied to dst. If
|
||||||
|
* condition == 1, then one is copied to dst. Any other value results in
|
||||||
|
* undefined behavior.
|
||||||
|
*/
|
||||||
|
WOLFSSL_LOCAL void fe_select(byte *dst, const byte *zero, const byte *one,
|
||||||
|
byte condition);
|
||||||
|
|
||||||
|
/* Multiply a point by a small constant. The two pointers are not
|
||||||
|
* required to be distinct.
|
||||||
|
*
|
||||||
|
* The constant must be less than 2^24.
|
||||||
|
*/
|
||||||
|
WOLFSSL_LOCAL void fe_mul_c(byte *r, const byte *a, word32 b);
|
||||||
|
WOLFSSL_LOCAL void fe_mul__distinct(byte *r, const byte *a, const byte *b);
|
||||||
|
|
||||||
|
/* Compute one of the square roots of the field element, if the element
|
||||||
|
* is square. The other square is -r.
|
||||||
|
*
|
||||||
|
* If the input is not square, the returned value is a valid field
|
||||||
|
* element, but not the correct answer. If you don't already know that
|
||||||
|
* your element is square, you should square the return value and test.
|
||||||
|
*/
|
||||||
|
WOLFSSL_LOCAL void fe_sqrt(byte *r, const byte *x);
|
||||||
|
|
||||||
|
/* Conditional copy. If condition == 0, then zero is copied to dst. If
|
||||||
|
* condition == 1, then one is copied to dst. Any other value results in
|
||||||
|
* undefined behavior.
|
||||||
|
*/
|
||||||
|
WOLFSSL_LOCAL void fprime_select(byte *dst, const byte *zero, const byte *one,
|
||||||
|
byte condition);
|
||||||
|
WOLFSSL_LOCAL void fprime_add(byte *r, const byte *a, const byte *modulus);
|
||||||
|
WOLFSSL_LOCAL void fprime_sub(byte *r, const byte *a, const byte *modulus);
|
||||||
|
WOLFSSL_LOCAL void fprime_mul(byte *r, const byte *a, const byte *b,
|
||||||
|
const byte *modulus);
|
||||||
|
WOLFSSL_LOCAL void fprime_copy(byte *x, const byte *a);
|
||||||
|
#endif /* CURVED25519_SMALL */
|
||||||
|
#endif /* HAVE_CURVE25519 or HAVE_ED25519 */
|
||||||
|
#endif /* WOLF_CRYPT_FE_OPERATIONS_H */
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/* fips_test.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_FIPS_TEST_H
|
||||||
|
#define WOLF_CRYPT_FIPS_TEST_H
|
||||||
|
|
||||||
|
#include <cyassl/ctaocrypt/types.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Known Answer Test string inputs are hex, internal */
|
||||||
|
CYASSL_LOCAL int DoKnownAnswerTests(char*, int);
|
||||||
|
|
||||||
|
|
||||||
|
/* FIPS failure callback */
|
||||||
|
typedef void(*wolfCrypt_fips_cb)(int ok, int err, const char* hash);
|
||||||
|
|
||||||
|
/* Public set function */
|
||||||
|
CYASSL_API int wolfCrypt_SetCb_fips(wolfCrypt_fips_cb cbf);
|
||||||
|
|
||||||
|
/* Public get status functions */
|
||||||
|
CYASSL_API int wolfCrypt_GetStatus_fips(void);
|
||||||
|
CYASSL_API const char* wolfCrypt_GetCoreHash_fips(void);
|
||||||
|
|
||||||
|
#ifdef HAVE_FORCE_FIPS_FAILURE
|
||||||
|
/* Public function to force failure mode for operational testing */
|
||||||
|
CYASSL_API int wolfCrypt_SetStatus_fips(int);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLF_CRYPT_FIPS_TEST_H */
|
||||||
|
|
|
@ -0,0 +1,116 @@
|
||||||
|
/* ge_operations.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* Based On Daniel J Bernstein's ed25519 Public Domain ref10 work. */
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_GE_OPERATIONS_H
|
||||||
|
#define WOLF_CRYPT_GE_OPERATIONS_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/settings.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_ED25519
|
||||||
|
|
||||||
|
#ifndef CURVED25519_SMALL
|
||||||
|
#include <stdint.h>
|
||||||
|
#endif
|
||||||
|
#include <wolfssl/wolfcrypt/fe_operations.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
ge means group element.
|
||||||
|
|
||||||
|
Here the group is the set of pairs (x,y) of field elements (see fe.h)
|
||||||
|
satisfying -x^2 + y^2 = 1 + d x^2y^2
|
||||||
|
where d = -121665/121666.
|
||||||
|
|
||||||
|
Representations:
|
||||||
|
ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
|
||||||
|
ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
|
||||||
|
ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
|
||||||
|
ge_precomp (Duif): (y+x,y-x,2dxy)
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
fe X;
|
||||||
|
fe Y;
|
||||||
|
fe Z;
|
||||||
|
} ge_p2;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
fe X;
|
||||||
|
fe Y;
|
||||||
|
fe Z;
|
||||||
|
fe T;
|
||||||
|
} ge_p3;
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL int ge_compress_key(byte* out, const byte* xIn, const byte* yIn,
|
||||||
|
word32 keySz);
|
||||||
|
WOLFSSL_LOCAL int ge_frombytes_negate_vartime(ge_p3 *,const unsigned char *);
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL int ge_double_scalarmult_vartime(ge_p2 *,const unsigned char *,
|
||||||
|
const ge_p3 *,const unsigned char *);
|
||||||
|
WOLFSSL_LOCAL void ge_scalarmult_base(ge_p3 *,const unsigned char *);
|
||||||
|
WOLFSSL_LOCAL void sc_reduce(byte* s);
|
||||||
|
WOLFSSL_LOCAL void sc_muladd(byte* s, const byte* a, const byte* b,
|
||||||
|
const byte* c);
|
||||||
|
WOLFSSL_LOCAL void ge_tobytes(unsigned char *,const ge_p2 *);
|
||||||
|
WOLFSSL_LOCAL void ge_p3_tobytes(unsigned char *,const ge_p3 *);
|
||||||
|
|
||||||
|
#ifndef CURVED25519_SMALL
|
||||||
|
typedef struct {
|
||||||
|
fe X;
|
||||||
|
fe Y;
|
||||||
|
fe Z;
|
||||||
|
fe T;
|
||||||
|
} ge_p1p1;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
fe yplusx;
|
||||||
|
fe yminusx;
|
||||||
|
fe xy2d;
|
||||||
|
} ge_precomp;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
fe YplusX;
|
||||||
|
fe YminusX;
|
||||||
|
fe Z;
|
||||||
|
fe T2d;
|
||||||
|
} ge_cached;
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL void ge_p2_0(ge_p2 *);
|
||||||
|
WOLFSSL_LOCAL void ge_p3_0(ge_p3 *);
|
||||||
|
WOLFSSL_LOCAL void ge_precomp_0(ge_precomp *);
|
||||||
|
WOLFSSL_LOCAL void ge_p3_to_p2(ge_p2 *,const ge_p3 *);
|
||||||
|
WOLFSSL_LOCAL void ge_p3_to_cached(ge_cached *,const ge_p3 *);
|
||||||
|
WOLFSSL_LOCAL void ge_p1p1_to_p2(ge_p2 *,const ge_p1p1 *);
|
||||||
|
WOLFSSL_LOCAL void ge_p1p1_to_p3(ge_p3 *,const ge_p1p1 *);
|
||||||
|
WOLFSSL_LOCAL void ge_p2_dbl(ge_p1p1 *,const ge_p2 *);
|
||||||
|
WOLFSSL_LOCAL void ge_p3_dbl(ge_p1p1 *,const ge_p3 *);
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL void ge_madd(ge_p1p1 *,const ge_p3 *,const ge_precomp *);
|
||||||
|
WOLFSSL_LOCAL void ge_msub(ge_p1p1 *,const ge_p3 *,const ge_precomp *);
|
||||||
|
WOLFSSL_LOCAL void ge_add(ge_p1p1 *,const ge_p3 *,const ge_cached *);
|
||||||
|
WOLFSSL_LOCAL void ge_sub(ge_p1p1 *,const ge_p3 *,const ge_cached *);
|
||||||
|
#endif /* no CURVED25519_SMALL */
|
||||||
|
#endif /* HAVE_ED25519 */
|
||||||
|
#endif /* WOLF_CRYPT_GE_OPERATIONS_H */
|
||||||
|
|
|
@ -0,0 +1,174 @@
|
||||||
|
/* hash.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_HASH_H
|
||||||
|
#define WOLF_CRYPT_HASH_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifndef NO_MD5
|
||||||
|
#include <wolfssl/wolfcrypt/md5.h>
|
||||||
|
#endif
|
||||||
|
#ifndef NO_SHA
|
||||||
|
#include <wolfssl/wolfcrypt/sha.h>
|
||||||
|
#endif
|
||||||
|
#if defined(WOLFSSL_SHA224) || !defined(NO_SHA256)
|
||||||
|
#include <wolfssl/wolfcrypt/sha256.h>
|
||||||
|
#endif
|
||||||
|
#if defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)
|
||||||
|
#include <wolfssl/wolfcrypt/sha512.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Hash types */
|
||||||
|
enum wc_HashType {
|
||||||
|
WC_HASH_TYPE_NONE = 0,
|
||||||
|
WC_HASH_TYPE_MD2 = 1,
|
||||||
|
WC_HASH_TYPE_MD4 = 2,
|
||||||
|
WC_HASH_TYPE_MD5 = 3,
|
||||||
|
WC_HASH_TYPE_SHA = 4, /* SHA-1 (not old SHA-0) */
|
||||||
|
WC_HASH_TYPE_SHA224 = 9,
|
||||||
|
WC_HASH_TYPE_SHA256 = 5,
|
||||||
|
WC_HASH_TYPE_SHA384 = 6,
|
||||||
|
WC_HASH_TYPE_SHA512 = 7,
|
||||||
|
WC_HASH_TYPE_MD5_SHA = 8,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
#ifndef NO_MD5
|
||||||
|
Md5 md5;
|
||||||
|
#endif
|
||||||
|
#ifndef NO_SHA
|
||||||
|
Sha sha;
|
||||||
|
#endif
|
||||||
|
#ifdef WOLFSSL_SHA224
|
||||||
|
Sha224 sha224;
|
||||||
|
#endif
|
||||||
|
#ifndef NO_SHA256
|
||||||
|
Sha256 sha256;
|
||||||
|
#endif
|
||||||
|
#ifdef WOLFSSL_SHA384
|
||||||
|
Sha384 sha384;
|
||||||
|
#endif
|
||||||
|
#ifdef WOLFSSL_SHA512
|
||||||
|
Sha512 sha512;
|
||||||
|
#endif
|
||||||
|
} wc_HashAlg;
|
||||||
|
|
||||||
|
/* Find largest possible digest size
|
||||||
|
Note if this gets up to the size of 80 or over check smallstack build */
|
||||||
|
#if defined(WOLFSSL_SHA512)
|
||||||
|
#define WC_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE
|
||||||
|
#elif defined(WOLFSSL_SHA384)
|
||||||
|
#define WC_MAX_DIGEST_SIZE SHA384_DIGEST_SIZE
|
||||||
|
#elif !defined(NO_SHA256)
|
||||||
|
#define WC_MAX_DIGEST_SIZE SHA256_DIGEST_SIZE
|
||||||
|
#elif defined(WOLFSSL_SHA224)
|
||||||
|
#define WC_MAX_DIGEST_SIZE SHA224_DIGEST_SIZE
|
||||||
|
#elif !defined(NO_SHA)
|
||||||
|
#define WC_MAX_DIGEST_SIZE SHA_DIGEST_SIZE
|
||||||
|
#elif !defined(NO_MD5)
|
||||||
|
#define WC_MAX_DIGEST_SIZE MD5_DIGEST_SIZE
|
||||||
|
#else
|
||||||
|
#define WC_MAX_DIGEST_SIZE 64 /* default to max size of 64 */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
|
||||||
|
WOLFSSL_API int wc_HashGetOID(enum wc_HashType hash_type);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_HashGetDigestSize(enum wc_HashType hash_type);
|
||||||
|
WOLFSSL_API int wc_Hash(enum wc_HashType hash_type,
|
||||||
|
const byte* data, word32 data_len,
|
||||||
|
byte* hash, word32 hash_len);
|
||||||
|
|
||||||
|
/* generic hash operation wrappers */
|
||||||
|
WOLFSSL_API int wc_HashInit(wc_HashAlg* hash, enum wc_HashType type);
|
||||||
|
WOLFSSL_API int wc_HashUpdate(wc_HashAlg* hash, enum wc_HashType type,
|
||||||
|
const byte* data, word32 dataSz);
|
||||||
|
WOLFSSL_API int wc_HashFinal(wc_HashAlg* hash, enum wc_HashType type,
|
||||||
|
byte* out);
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef NO_MD5
|
||||||
|
#include <wolfssl/wolfcrypt/md5.h>
|
||||||
|
WOLFSSL_API void wc_Md5GetHash(Md5*, byte*);
|
||||||
|
WOLFSSL_API void wc_Md5RestorePos(Md5*, Md5*);
|
||||||
|
#if defined(WOLFSSL_TI_HASH)
|
||||||
|
WOLFSSL_API void wc_Md5Free(Md5*);
|
||||||
|
#else
|
||||||
|
#define wc_Md5Free(d)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NO_SHA
|
||||||
|
#include <wolfssl/wolfcrypt/sha.h>
|
||||||
|
WOLFSSL_API int wc_ShaGetHash(Sha*, byte*);
|
||||||
|
WOLFSSL_API void wc_ShaRestorePos(Sha*, Sha*);
|
||||||
|
WOLFSSL_API int wc_ShaHash(const byte*, word32, byte*);
|
||||||
|
#if defined(WOLFSSL_TI_HASH)
|
||||||
|
WOLFSSL_API void wc_ShaFree(Sha*);
|
||||||
|
#else
|
||||||
|
#define wc_ShaFree(d)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NO_SHA256
|
||||||
|
#include <wolfssl/wolfcrypt/sha256.h>
|
||||||
|
WOLFSSL_API int wc_Sha256GetHash(Sha256*, byte*);
|
||||||
|
WOLFSSL_API void wc_Sha256RestorePos(Sha256*, Sha256*);
|
||||||
|
WOLFSSL_API int wc_Sha256Hash(const byte*, word32, byte*);
|
||||||
|
#if defined(WOLFSSL_TI_HASH)
|
||||||
|
WOLFSSL_API void wc_Sha256Free(Sha256*);
|
||||||
|
#else
|
||||||
|
#define wc_Sha256Free(d)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(WOLFSSL_SHA224)
|
||||||
|
WOLFSSL_API int wc_Sha224GetHash(Sha224*, byte*);
|
||||||
|
WOLFSSL_API int wc_Sha224Hash(const byte*, word32, byte*);
|
||||||
|
#define wc_Sha224Free(d)
|
||||||
|
#endif /* defined(WOLFSSL_SHA224) */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_SHA512
|
||||||
|
#include <wolfssl/wolfcrypt/sha512.h>
|
||||||
|
WOLFSSL_API int wc_Sha512GetHash(Sha512*, byte*);
|
||||||
|
WOLFSSL_API int wc_Sha512Hash(const byte*, word32, byte*);
|
||||||
|
#define wc_Sha512Free(d)
|
||||||
|
|
||||||
|
#if defined(WOLFSSL_SHA384)
|
||||||
|
WOLFSSL_API int wc_Sha384GetHash(Sha384*, byte*);
|
||||||
|
WOLFSSL_API int wc_Sha384Hash(const byte*, word32, byte*);
|
||||||
|
#define wc_Sha384Free(d)
|
||||||
|
#endif /* defined(WOLFSSL_SHA384) */
|
||||||
|
#endif /* WOLFSSL_SHA512 */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLF_CRYPT_HASH_H */
|
|
@ -0,0 +1,63 @@
|
||||||
|
/* hc128.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_HC128_H
|
||||||
|
#define WOLF_CRYPT_HC128_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifndef NO_HC128
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum {
|
||||||
|
HC128_ENC_TYPE = 6 /* cipher unique type */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* HC-128 stream cipher */
|
||||||
|
typedef struct HC128 {
|
||||||
|
word32 T[1024]; /* P[i] = T[i]; Q[i] = T[1024 + i ]; */
|
||||||
|
word32 X[16];
|
||||||
|
word32 Y[16];
|
||||||
|
word32 counter1024; /* counter1024 = i mod 1024 at the ith step */
|
||||||
|
word32 key[8];
|
||||||
|
word32 iv[8];
|
||||||
|
#ifdef XSTREAM_ALIGN
|
||||||
|
void* heap; /* heap hint, currently XMALLOC only used with aligning */
|
||||||
|
#endif
|
||||||
|
} HC128;
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_Hc128_Process(HC128*, byte*, const byte*, word32);
|
||||||
|
WOLFSSL_API int wc_Hc128_SetKey(HC128*, const byte* key, const byte* iv);
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL int wc_Hc128_SetHeap(HC128* ctx, void* heap);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAVE_HC128 */
|
||||||
|
#endif /* WOLF_CRYPT_HC128_H */
|
||||||
|
|
|
@ -0,0 +1,201 @@
|
||||||
|
/* hmac.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef NO_HMAC
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_HMAC_H
|
||||||
|
#define WOLF_CRYPT_HMAC_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifndef NO_MD5
|
||||||
|
#include <wolfssl/wolfcrypt/md5.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NO_SHA
|
||||||
|
#include <wolfssl/wolfcrypt/sha.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(NO_SHA256) || defined(WOLFSSL_SHA224)
|
||||||
|
#include <wolfssl/wolfcrypt/sha256.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_SHA512
|
||||||
|
#include <wolfssl/wolfcrypt/sha512.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_BLAKE2
|
||||||
|
#include <wolfssl/wolfcrypt/blake2.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_FIPS
|
||||||
|
/* for fips */
|
||||||
|
#include <cyassl/ctaocrypt/hmac.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
#ifndef HAVE_FIPS
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
#include <wolfssl/wolfcrypt/async.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum {
|
||||||
|
HMAC_FIPS_MIN_KEY = 14, /* 112 bit key length minimum */
|
||||||
|
|
||||||
|
IPAD = 0x36,
|
||||||
|
OPAD = 0x5C,
|
||||||
|
|
||||||
|
/* If any hash is not enabled, add the ID here. */
|
||||||
|
#ifdef NO_MD5
|
||||||
|
MD5 = 0,
|
||||||
|
#endif
|
||||||
|
#ifdef NO_SHA
|
||||||
|
SHA = 1,
|
||||||
|
#endif
|
||||||
|
#ifdef NO_SHA256
|
||||||
|
SHA256 = 2,
|
||||||
|
#endif
|
||||||
|
#ifndef WOLFSSL_SHA512
|
||||||
|
SHA512 = 4,
|
||||||
|
#endif
|
||||||
|
#ifndef WOLFSSL_SHA384
|
||||||
|
SHA384 = 5,
|
||||||
|
#endif
|
||||||
|
#ifndef HAVE_BLAKE2
|
||||||
|
BLAKE2B_ID = 7,
|
||||||
|
#endif
|
||||||
|
#ifndef WOLFSSL_SHA224
|
||||||
|
SHA224 = 8,
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Select the largest available hash for the buffer size. */
|
||||||
|
#if defined(WOLFSSL_SHA512)
|
||||||
|
MAX_DIGEST_SIZE = SHA512_DIGEST_SIZE,
|
||||||
|
HMAC_BLOCK_SIZE = SHA512_BLOCK_SIZE
|
||||||
|
#elif defined(HAVE_BLAKE2)
|
||||||
|
MAX_DIGEST_SIZE = BLAKE2B_OUTBYTES,
|
||||||
|
HMAC_BLOCK_SIZE = BLAKE2B_BLOCKBYTES,
|
||||||
|
#elif defined(WOLFSSL_SHA384)
|
||||||
|
MAX_DIGEST_SIZE = SHA384_DIGEST_SIZE,
|
||||||
|
HMAC_BLOCK_SIZE = SHA384_BLOCK_SIZE
|
||||||
|
#elif !defined(NO_SHA256)
|
||||||
|
MAX_DIGEST_SIZE = SHA256_DIGEST_SIZE,
|
||||||
|
HMAC_BLOCK_SIZE = SHA256_BLOCK_SIZE
|
||||||
|
#elif defined(WOLFSSL_SHA224)
|
||||||
|
MAX_DIGEST_SIZE = SHA224_DIGEST_SIZE,
|
||||||
|
HMAC_BLOCK_SIZE = SHA224_BLOCK_SIZE
|
||||||
|
#elif !defined(NO_SHA)
|
||||||
|
MAX_DIGEST_SIZE = SHA_DIGEST_SIZE,
|
||||||
|
HMAC_BLOCK_SIZE = SHA_BLOCK_SIZE
|
||||||
|
#elif !defined(NO_MD5)
|
||||||
|
MAX_DIGEST_SIZE = MD5_DIGEST_SIZE,
|
||||||
|
HMAC_BLOCK_SIZE = MD5_BLOCK_SIZE
|
||||||
|
#else
|
||||||
|
#error "You have to have some kind of hash if you want to use HMAC."
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* hash union */
|
||||||
|
typedef union {
|
||||||
|
#ifndef NO_MD5
|
||||||
|
Md5 md5;
|
||||||
|
#endif
|
||||||
|
#ifndef NO_SHA
|
||||||
|
Sha sha;
|
||||||
|
#endif
|
||||||
|
#ifdef WOLFSSL_SHA224
|
||||||
|
Sha224 sha224;
|
||||||
|
#endif
|
||||||
|
#ifndef NO_SHA256
|
||||||
|
Sha256 sha256;
|
||||||
|
#endif
|
||||||
|
#ifdef WOLFSSL_SHA384
|
||||||
|
Sha384 sha384;
|
||||||
|
#endif
|
||||||
|
#ifdef WOLFSSL_SHA512
|
||||||
|
Sha512 sha512;
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_BLAKE2
|
||||||
|
Blake2b blake2b;
|
||||||
|
#endif
|
||||||
|
} Hash;
|
||||||
|
|
||||||
|
/* Hmac digest */
|
||||||
|
typedef struct Hmac {
|
||||||
|
Hash hash;
|
||||||
|
word32 ipad[HMAC_BLOCK_SIZE / sizeof(word32)]; /* same block size all*/
|
||||||
|
word32 opad[HMAC_BLOCK_SIZE / sizeof(word32)];
|
||||||
|
word32 innerHash[MAX_DIGEST_SIZE / sizeof(word32)];
|
||||||
|
void* heap; /* heap hint */
|
||||||
|
byte macType; /* md5 sha or sha256 */
|
||||||
|
byte innerHashKeyed; /* keyed flag */
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
AsyncCryptDev asyncDev;
|
||||||
|
#ifdef HAVE_CAVIUM
|
||||||
|
word16 keyLen; /* hmac key length */
|
||||||
|
word16 dataLen;
|
||||||
|
HashType type; /* hmac key type */
|
||||||
|
byte* data; /* buffered input data for one call */
|
||||||
|
#endif /* HAVE_CAVIUM */
|
||||||
|
#endif /* WOLFSSL_ASYNC_CRYPT */
|
||||||
|
} Hmac;
|
||||||
|
|
||||||
|
#endif /* HAVE_FIPS */
|
||||||
|
|
||||||
|
/* does init */
|
||||||
|
WOLFSSL_API int wc_HmacSetKey(Hmac*, int type, const byte* key, word32 keySz);
|
||||||
|
WOLFSSL_API int wc_HmacUpdate(Hmac*, const byte*, word32);
|
||||||
|
WOLFSSL_API int wc_HmacFinal(Hmac*, byte*);
|
||||||
|
WOLFSSL_API int wc_HmacSizeByType(int type);
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
WOLFSSL_API int wc_HmacAsyncInit(Hmac*, int);
|
||||||
|
WOLFSSL_API void wc_HmacAsyncFree(Hmac*);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API int wolfSSL_GetHmacMaxSize(void);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_HKDF
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_HKDF(int type, const byte* inKey, word32 inKeySz,
|
||||||
|
const byte* salt, word32 saltSz,
|
||||||
|
const byte* info, word32 infoSz,
|
||||||
|
byte* out, word32 outSz);
|
||||||
|
|
||||||
|
#endif /* HAVE_HKDF */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLF_CRYPT_HMAC_H */
|
||||||
|
|
||||||
|
#endif /* NO_HMAC */
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
/* idea.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_IDEA_H
|
||||||
|
#define WOLF_CRYPT_IDEA_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_IDEA
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum {
|
||||||
|
IDEA_MODULO = 0x10001, /* 2^16+1 */
|
||||||
|
IDEA_2EXP16 = 0x10000, /* 2^16 */
|
||||||
|
IDEA_MASK = 0xFFFF, /* 16 bits set to one */
|
||||||
|
IDEA_ROUNDS = 8, /* number of rounds for IDEA */
|
||||||
|
IDEA_SK_NUM = (6*IDEA_ROUNDS + 4), /* number of subkeys */
|
||||||
|
IDEA_KEY_SIZE = 16, /* size of key in bytes */
|
||||||
|
IDEA_BLOCK_SIZE = 8, /* size of IDEA blocks in bytes */
|
||||||
|
IDEA_IV_SIZE = 8, /* size of IDEA IV in bytes */
|
||||||
|
IDEA_ENCRYPTION = 0,
|
||||||
|
IDEA_DECRYPTION = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
/* IDEA encryption and decryption */
|
||||||
|
typedef struct Idea {
|
||||||
|
word32 reg[IDEA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
|
||||||
|
word32 tmp[IDEA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
|
||||||
|
word16 skey[IDEA_SK_NUM]; /* 832 bits expanded key */
|
||||||
|
} Idea;
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_IdeaSetKey(Idea *idea, const byte* key, word16 keySz,
|
||||||
|
const byte *iv, int dir);
|
||||||
|
WOLFSSL_API int wc_IdeaSetIV(Idea *idea, const byte* iv);
|
||||||
|
WOLFSSL_API void wc_IdeaCipher(Idea *idea, byte* out, const byte* in);
|
||||||
|
WOLFSSL_API int wc_IdeaCbcEncrypt(Idea *idea, byte* out,
|
||||||
|
const byte* in, word32 len);
|
||||||
|
WOLFSSL_API int wc_IdeaCbcDecrypt(Idea *idea, byte* out,
|
||||||
|
const byte* in, word32 len);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAVE_IDEA */
|
||||||
|
#endif /* WOLF_CRYPT_IDEA_H */
|
|
@ -0,0 +1,73 @@
|
||||||
|
# vim:ft=automake
|
||||||
|
# All paths should be given relative to the root
|
||||||
|
|
||||||
|
nobase_include_HEADERS+= \
|
||||||
|
wolfssl/wolfcrypt/aes.h \
|
||||||
|
wolfssl/wolfcrypt/arc4.h \
|
||||||
|
wolfssl/wolfcrypt/asn.h \
|
||||||
|
wolfssl/wolfcrypt/asn_public.h \
|
||||||
|
wolfssl/wolfcrypt/poly1305.h \
|
||||||
|
wolfssl/wolfcrypt/camellia.h \
|
||||||
|
wolfssl/wolfcrypt/cmac.h \
|
||||||
|
wolfssl/wolfcrypt/coding.h \
|
||||||
|
wolfssl/wolfcrypt/compress.h \
|
||||||
|
wolfssl/wolfcrypt/des3.h \
|
||||||
|
wolfssl/wolfcrypt/dh.h \
|
||||||
|
wolfssl/wolfcrypt/dsa.h \
|
||||||
|
wolfssl/wolfcrypt/ecc.h \
|
||||||
|
wolfssl/wolfcrypt/curve25519.h \
|
||||||
|
wolfssl/wolfcrypt/ed25519.h \
|
||||||
|
wolfssl/wolfcrypt/fe_operations.h \
|
||||||
|
wolfssl/wolfcrypt/ge_operations.h \
|
||||||
|
wolfssl/wolfcrypt/error-crypt.h \
|
||||||
|
wolfssl/wolfcrypt/fips_test.h \
|
||||||
|
wolfssl/wolfcrypt/hash.h \
|
||||||
|
wolfssl/wolfcrypt/hc128.h \
|
||||||
|
wolfssl/wolfcrypt/hmac.h \
|
||||||
|
wolfssl/wolfcrypt/integer.h \
|
||||||
|
wolfssl/wolfcrypt/md2.h \
|
||||||
|
wolfssl/wolfcrypt/md4.h \
|
||||||
|
wolfssl/wolfcrypt/md5.h \
|
||||||
|
wolfssl/wolfcrypt/misc.h \
|
||||||
|
wolfssl/wolfcrypt/pkcs7.h \
|
||||||
|
wolfssl/wolfcrypt/wc_encrypt.h \
|
||||||
|
wolfssl/wolfcrypt/wc_port.h \
|
||||||
|
wolfssl/wolfcrypt/pwdbased.h \
|
||||||
|
wolfssl/wolfcrypt/rabbit.h \
|
||||||
|
wolfssl/wolfcrypt/chacha.h \
|
||||||
|
wolfssl/wolfcrypt/chacha20_poly1305.h \
|
||||||
|
wolfssl/wolfcrypt/random.h \
|
||||||
|
wolfssl/wolfcrypt/ripemd.h \
|
||||||
|
wolfssl/wolfcrypt/rsa.h \
|
||||||
|
wolfssl/wolfcrypt/settings.h \
|
||||||
|
wolfssl/wolfcrypt/sha256.h \
|
||||||
|
wolfssl/wolfcrypt/sha512.h \
|
||||||
|
wolfssl/wolfcrypt/sha.h \
|
||||||
|
wolfssl/wolfcrypt/signature.h \
|
||||||
|
wolfssl/wolfcrypt/blake2.h \
|
||||||
|
wolfssl/wolfcrypt/blake2-int.h \
|
||||||
|
wolfssl/wolfcrypt/blake2-impl.h \
|
||||||
|
wolfssl/wolfcrypt/tfm.h \
|
||||||
|
wolfssl/wolfcrypt/srp.h \
|
||||||
|
wolfssl/wolfcrypt/idea.h \
|
||||||
|
wolfssl/wolfcrypt/types.h \
|
||||||
|
wolfssl/wolfcrypt/visibility.h \
|
||||||
|
wolfssl/wolfcrypt/logging.h \
|
||||||
|
wolfssl/wolfcrypt/memory.h \
|
||||||
|
wolfssl/wolfcrypt/mpi_class.h \
|
||||||
|
wolfssl/wolfcrypt/mpi_superclass.h \
|
||||||
|
wolfssl/wolfcrypt/mem_track.h \
|
||||||
|
wolfssl/wolfcrypt/wolfevent.h \
|
||||||
|
wolfssl/wolfcrypt/pkcs12.h
|
||||||
|
|
||||||
|
noinst_HEADERS+= \
|
||||||
|
wolfssl/wolfcrypt/port/pic32/pic32mz-crypt.h \
|
||||||
|
wolfssl/wolfcrypt/port/ti/ti-hash.h \
|
||||||
|
wolfssl/wolfcrypt/port/ti/ti-ccm.h \
|
||||||
|
wolfssl/wolfcrypt/port/nrf51.h \
|
||||||
|
wolfssl/wolfcrypt/port/nxp/ksdk_port.h \
|
||||||
|
wolfssl/wolfcrypt/port/atmel/atmel.h
|
||||||
|
|
||||||
|
if BUILD_CAVIUM
|
||||||
|
noinst_HEADERS+= wolfssl/wolfcrypt/port/cavium/cavium_nitrox.h
|
||||||
|
endif
|
|
@ -0,0 +1,353 @@
|
||||||
|
/* integer.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Based on public domain LibTomMath 0.38 by Tom St Denis, tomstdenis@iahu.ca,
|
||||||
|
* http://math.libtomcrypt.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_INTEGER_H
|
||||||
|
#define WOLF_CRYPT_INTEGER_H
|
||||||
|
|
||||||
|
/* may optionally use fast math instead, not yet supported on all platforms and
|
||||||
|
may not be faster on all
|
||||||
|
*/
|
||||||
|
#include <wolfssl/wolfcrypt/types.h> /* will set MP_xxBIT if not default */
|
||||||
|
#ifdef USE_FAST_MATH
|
||||||
|
#include <wolfssl/wolfcrypt/tfm.h>
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/random.h>
|
||||||
|
|
||||||
|
#ifndef CHAR_BIT
|
||||||
|
#include <limits.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/mpi_class.h>
|
||||||
|
|
||||||
|
#ifndef MIN
|
||||||
|
#define MIN(x,y) ((x)<(y)?(x):(y))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAX
|
||||||
|
#define MAX(x,y) ((x)>(y)?(x):(y))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
/* C++ compilers don't like assigning void * to mp_digit * */
|
||||||
|
#define OPT_CAST(x) (x *)
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/* C on the other hand doesn't care */
|
||||||
|
#define OPT_CAST(x)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* detect 64-bit mode if possible */
|
||||||
|
#if defined(__x86_64__)
|
||||||
|
#if !(defined(MP_64BIT) && defined(MP_16BIT) && defined(MP_8BIT))
|
||||||
|
#define MP_64BIT
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
/* if intel compiler doesn't provide 128 bit type don't turn on 64bit */
|
||||||
|
#if defined(MP_64BIT) && defined(__INTEL_COMPILER) && !defined(HAVE___UINT128_T)
|
||||||
|
#undef MP_64BIT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* allow user to define on mp_digit, mp_word, DIGIT_BIT types */
|
||||||
|
#ifndef WOLFSSL_BIGINT_TYPES
|
||||||
|
|
||||||
|
/* some default configurations.
|
||||||
|
*
|
||||||
|
* A "mp_digit" must be able to hold DIGIT_BIT + 1 bits
|
||||||
|
* A "mp_word" must be able to hold 2*DIGIT_BIT + 1 bits
|
||||||
|
*
|
||||||
|
* At the very least a mp_digit must be able to hold 7 bits
|
||||||
|
* [any size beyond that is ok provided it doesn't overflow the data type]
|
||||||
|
*/
|
||||||
|
#ifdef MP_8BIT
|
||||||
|
typedef unsigned char mp_digit;
|
||||||
|
typedef unsigned short mp_word;
|
||||||
|
#elif defined(MP_16BIT) || defined(NO_64BIT)
|
||||||
|
typedef unsigned short mp_digit;
|
||||||
|
typedef unsigned int mp_word;
|
||||||
|
#define DIGIT_BIT 12
|
||||||
|
#elif defined(MP_64BIT)
|
||||||
|
/* for GCC only on supported platforms */
|
||||||
|
typedef unsigned long long mp_digit; /* 64 bit type, 128 uses mode(TI) */
|
||||||
|
typedef unsigned long mp_word __attribute__ ((mode(TI)));
|
||||||
|
|
||||||
|
#define DIGIT_BIT 60
|
||||||
|
#else
|
||||||
|
/* this is the default case, 28-bit digits */
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||||
|
typedef unsigned __int64 ulong64;
|
||||||
|
#else
|
||||||
|
typedef unsigned long long ulong64;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef unsigned int mp_digit; /* long could be 64 now, changed TAO */
|
||||||
|
typedef ulong64 mp_word;
|
||||||
|
|
||||||
|
#ifdef MP_31BIT
|
||||||
|
/* this is an extension that uses 31-bit digits */
|
||||||
|
#define DIGIT_BIT 31
|
||||||
|
#else
|
||||||
|
/* default case is 28-bit digits, defines MP_28BIT as a handy test macro */
|
||||||
|
#define DIGIT_BIT 28
|
||||||
|
#define MP_28BIT
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLFSSL_BIGINT_TYPES */
|
||||||
|
|
||||||
|
/* otherwise the bits per digit is calculated automatically from the size of
|
||||||
|
a mp_digit */
|
||||||
|
#ifndef DIGIT_BIT
|
||||||
|
#define DIGIT_BIT ((int)((CHAR_BIT * sizeof(mp_digit) - 1)))
|
||||||
|
/* bits per digit */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MP_DIGIT_BIT DIGIT_BIT
|
||||||
|
#define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
|
||||||
|
#define MP_DIGIT_MAX MP_MASK
|
||||||
|
|
||||||
|
/* equalities */
|
||||||
|
#define MP_LT -1 /* less than */
|
||||||
|
#define MP_EQ 0 /* equal to */
|
||||||
|
#define MP_GT 1 /* greater than */
|
||||||
|
|
||||||
|
#define MP_ZPOS 0 /* positive integer */
|
||||||
|
#define MP_NEG 1 /* negative */
|
||||||
|
|
||||||
|
#define MP_OKAY 0 /* ok result */
|
||||||
|
#define MP_MEM -2 /* out of mem */
|
||||||
|
#define MP_VAL -3 /* invalid input */
|
||||||
|
#define MP_NOT_INF -4 /* point not at infinity */
|
||||||
|
#define MP_RANGE MP_NOT_INF
|
||||||
|
|
||||||
|
#define MP_YES 1 /* yes response */
|
||||||
|
#define MP_NO 0 /* no response */
|
||||||
|
|
||||||
|
/* Primality generation flags */
|
||||||
|
#define LTM_PRIME_BBS 0x0001 /* BBS style prime */
|
||||||
|
#define LTM_PRIME_SAFE 0x0002 /* Safe prime (p-1)/2 == prime */
|
||||||
|
#define LTM_PRIME_2MSB_ON 0x0008 /* force 2nd MSB to 1 */
|
||||||
|
|
||||||
|
typedef int mp_err;
|
||||||
|
|
||||||
|
/* define this to use lower memory usage routines (exptmods mostly) */
|
||||||
|
#define MP_LOW_MEM
|
||||||
|
|
||||||
|
/* default precision */
|
||||||
|
#ifndef MP_PREC
|
||||||
|
#ifndef MP_LOW_MEM
|
||||||
|
#define MP_PREC 32 /* default digits of precision */
|
||||||
|
#else
|
||||||
|
#define MP_PREC 1 /* default digits of precision */
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD -
|
||||||
|
BITS_PER_DIGIT*2) */
|
||||||
|
#define MP_WARRAY (1 << (sizeof(mp_word) * CHAR_BIT - 2 * DIGIT_BIT + 1))
|
||||||
|
|
||||||
|
/* the infamous mp_int structure */
|
||||||
|
typedef struct {
|
||||||
|
int used, alloc, sign;
|
||||||
|
mp_digit *dp;
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
byte* dpraw; /* Used for hardware crypto */
|
||||||
|
#endif
|
||||||
|
} mp_int;
|
||||||
|
|
||||||
|
/* callback for mp_prime_random, should fill dst with random bytes and return
|
||||||
|
how many read [up to len] */
|
||||||
|
typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat);
|
||||||
|
|
||||||
|
|
||||||
|
#define USED(m) ((m)->used)
|
||||||
|
#define DIGIT(m,k) ((m)->dp[(k)])
|
||||||
|
#define SIGN(m) ((m)->sign)
|
||||||
|
|
||||||
|
|
||||||
|
/* ---> Basic Manipulations <--- */
|
||||||
|
#define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
|
||||||
|
#define mp_isone(a) \
|
||||||
|
(((((a)->used == 1)) && ((a)->dp[0] == 1u)) ? MP_YES : MP_NO)
|
||||||
|
#define mp_iseven(a) \
|
||||||
|
(((a)->used > 0 && (((a)->dp[0] & 1u) == 0u)) ? MP_YES : MP_NO)
|
||||||
|
#define mp_isodd(a) \
|
||||||
|
(((a)->used > 0 && (((a)->dp[0] & 1u) == 1u)) ? MP_YES : MP_NO)
|
||||||
|
#define mp_isneg(a) (((a)->sign != MP_ZPOS) ? MP_YES : MP_NO)
|
||||||
|
|
||||||
|
/* number of primes */
|
||||||
|
#ifdef MP_8BIT
|
||||||
|
#define PRIME_SIZE 31
|
||||||
|
#else
|
||||||
|
#define PRIME_SIZE 256
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define mp_prime_random(a, t, size, bbs, cb, dat) \
|
||||||
|
mp_prime_random_ex(a, t, ((size) * 8) + 1, (bbs==1)?LTM_PRIME_BBS:0, cb, dat)
|
||||||
|
|
||||||
|
#define mp_read_raw(mp, str, len) mp_read_signed_bin((mp), (str), (len))
|
||||||
|
#define mp_raw_size(mp) mp_signed_bin_size(mp)
|
||||||
|
#define mp_toraw(mp, str) mp_to_signed_bin((mp), (str))
|
||||||
|
#define mp_read_mag(mp, str, len) mp_read_unsigned_bin((mp), (str), (len))
|
||||||
|
#define mp_mag_size(mp) mp_unsigned_bin_size(mp)
|
||||||
|
#define mp_tomag(mp, str) mp_to_unsigned_bin((mp), (str))
|
||||||
|
|
||||||
|
#define mp_tobinary(M, S) mp_toradix((M), (S), 2)
|
||||||
|
#define mp_tooctal(M, S) mp_toradix((M), (S), 8)
|
||||||
|
#define mp_todecimal(M, S) mp_toradix((M), (S), 10)
|
||||||
|
#define mp_tohex(M, S) mp_toradix((M), (S), 16)
|
||||||
|
|
||||||
|
#define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
|
||||||
|
|
||||||
|
extern const char *mp_s_rmap;
|
||||||
|
|
||||||
|
/* 6 functions needed by Rsa */
|
||||||
|
int mp_init (mp_int * a);
|
||||||
|
void mp_clear (mp_int * a);
|
||||||
|
void mp_forcezero(mp_int * a);
|
||||||
|
int mp_unsigned_bin_size(mp_int * a);
|
||||||
|
int mp_read_unsigned_bin (mp_int * a, const unsigned char *b, int c);
|
||||||
|
int mp_to_unsigned_bin (mp_int * a, unsigned char *b);
|
||||||
|
int mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y);
|
||||||
|
/* end functions needed by Rsa */
|
||||||
|
|
||||||
|
/* functions added to support above needed, removed TOOM and KARATSUBA */
|
||||||
|
int mp_count_bits (mp_int * a);
|
||||||
|
int mp_leading_bit (mp_int * a);
|
||||||
|
int mp_init_copy (mp_int * a, mp_int * b);
|
||||||
|
int mp_copy (mp_int * a, mp_int * b);
|
||||||
|
int mp_grow (mp_int * a, int size);
|
||||||
|
int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d);
|
||||||
|
void mp_zero (mp_int * a);
|
||||||
|
void mp_clamp (mp_int * a);
|
||||||
|
void mp_exch (mp_int * a, mp_int * b);
|
||||||
|
void mp_rshd (mp_int * a, int b);
|
||||||
|
void mp_rshb (mp_int * a, int b);
|
||||||
|
int mp_mod_2d (mp_int * a, int b, mp_int * c);
|
||||||
|
int mp_mul_2d (mp_int * a, int b, mp_int * c);
|
||||||
|
int mp_lshd (mp_int * a, int b);
|
||||||
|
int mp_abs (mp_int * a, mp_int * b);
|
||||||
|
int mp_invmod (mp_int * a, mp_int * b, mp_int * c);
|
||||||
|
int fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c);
|
||||||
|
int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c);
|
||||||
|
int mp_cmp_mag (mp_int * a, mp_int * b);
|
||||||
|
int mp_cmp (mp_int * a, mp_int * b);
|
||||||
|
int mp_cmp_d(mp_int * a, mp_digit b);
|
||||||
|
void mp_set (mp_int * a, mp_digit b);
|
||||||
|
int mp_is_bit_set (mp_int * a, mp_digit b);
|
||||||
|
int mp_mod (mp_int * a, mp_int * b, mp_int * c);
|
||||||
|
int mp_div(mp_int * a, mp_int * b, mp_int * c, mp_int * d);
|
||||||
|
int mp_div_2(mp_int * a, mp_int * b);
|
||||||
|
int mp_add (mp_int * a, mp_int * b, mp_int * c);
|
||||||
|
int s_mp_add (mp_int * a, mp_int * b, mp_int * c);
|
||||||
|
int s_mp_sub (mp_int * a, mp_int * b, mp_int * c);
|
||||||
|
int mp_sub (mp_int * a, mp_int * b, mp_int * c);
|
||||||
|
int mp_reduce_is_2k_l(mp_int *a);
|
||||||
|
int mp_reduce_is_2k(mp_int *a);
|
||||||
|
int mp_dr_is_modulus(mp_int *a);
|
||||||
|
int mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int);
|
||||||
|
int mp_montgomery_setup (mp_int * n, mp_digit * rho);
|
||||||
|
int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho);
|
||||||
|
int mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho);
|
||||||
|
void mp_dr_setup(mp_int *a, mp_digit *d);
|
||||||
|
int mp_dr_reduce (mp_int * x, mp_int * n, mp_digit k);
|
||||||
|
int mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d);
|
||||||
|
int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
|
||||||
|
int s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
|
||||||
|
int mp_reduce_2k_setup_l(mp_int *a, mp_int *d);
|
||||||
|
int mp_reduce_2k_l(mp_int *a, mp_int *n, mp_int *d);
|
||||||
|
int mp_reduce (mp_int * x, mp_int * m, mp_int * mu);
|
||||||
|
int mp_reduce_setup (mp_int * a, mp_int * b);
|
||||||
|
int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode);
|
||||||
|
int mp_montgomery_calc_normalization (mp_int * a, mp_int * b);
|
||||||
|
int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
|
||||||
|
int s_mp_sqr (mp_int * a, mp_int * b);
|
||||||
|
int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
|
||||||
|
int fast_s_mp_sqr (mp_int * a, mp_int * b);
|
||||||
|
int mp_init_size (mp_int * a, int size);
|
||||||
|
int mp_div_3 (mp_int * a, mp_int *c, mp_digit * d);
|
||||||
|
int mp_mul_2(mp_int * a, mp_int * b);
|
||||||
|
int mp_mul (mp_int * a, mp_int * b, mp_int * c);
|
||||||
|
int mp_sqr (mp_int * a, mp_int * b);
|
||||||
|
int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d);
|
||||||
|
int mp_submod (mp_int* a, mp_int* b, mp_int* c, mp_int* d);
|
||||||
|
int mp_addmod (mp_int* a, mp_int* b, mp_int* c, mp_int* d);
|
||||||
|
int mp_mul_d (mp_int * a, mp_digit b, mp_int * c);
|
||||||
|
int mp_2expt (mp_int * a, int b);
|
||||||
|
int mp_set_bit (mp_int * a, int b);
|
||||||
|
int mp_reduce_2k_setup(mp_int *a, mp_digit *d);
|
||||||
|
int mp_add_d (mp_int* a, mp_digit b, mp_int* c);
|
||||||
|
int mp_set_int (mp_int * a, unsigned long b);
|
||||||
|
int mp_sub_d (mp_int * a, mp_digit b, mp_int * c);
|
||||||
|
/* end support added functions */
|
||||||
|
|
||||||
|
/* added */
|
||||||
|
int mp_init_multi(mp_int* a, mp_int* b, mp_int* c, mp_int* d, mp_int* e,
|
||||||
|
mp_int* f);
|
||||||
|
int mp_toradix (mp_int *a, char *str, int radix);
|
||||||
|
int mp_radix_size (mp_int * a, int radix, int *size);
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_DEBUG_MATH
|
||||||
|
void mp_dump(const char* desc, mp_int* a, byte verbose);
|
||||||
|
#else
|
||||||
|
#define mp_dump(desc, a, verbose)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
|
||||||
|
int mp_sqrmod(mp_int* a, mp_int* b, mp_int* c);
|
||||||
|
#endif
|
||||||
|
#if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
|
||||||
|
int mp_read_radix(mp_int* a, const char* str, int radix);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_KEY_GEN
|
||||||
|
int mp_prime_is_prime (mp_int * a, int t, int *result);
|
||||||
|
int mp_gcd (mp_int * a, mp_int * b, mp_int * c);
|
||||||
|
int mp_lcm (mp_int * a, mp_int * b, mp_int * c);
|
||||||
|
int mp_rand_prime(mp_int* N, int len, WC_RNG* rng, void* heap);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int mp_cnt_lsb(mp_int *a);
|
||||||
|
int mp_mod_d(mp_int* a, mp_digit b, mp_digit* c);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* USE_FAST_MATH */
|
||||||
|
|
||||||
|
#endif /* WOLF_CRYPT_INTEGER_H */
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
/* logging.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* submitted by eof */
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_LOGGING_H
|
||||||
|
#define WOLFSSL_LOGGING_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
enum CYA_Log_Levels {
|
||||||
|
ERROR_LOG = 0,
|
||||||
|
INFO_LOG,
|
||||||
|
ENTER_LOG,
|
||||||
|
LEAVE_LOG,
|
||||||
|
OTHER_LOG
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void (*wolfSSL_Logging_cb)(const int logLevel,
|
||||||
|
const char *const logMessage);
|
||||||
|
|
||||||
|
WOLFSSL_API int wolfSSL_SetLoggingCb(wolfSSL_Logging_cb log_function);
|
||||||
|
|
||||||
|
#ifdef DEBUG_WOLFSSL
|
||||||
|
/* a is prepended to m and b is appended, creating a log msg a + m + b */
|
||||||
|
#define WOLFSSL_LOG_CAT(a, m, b) #a " " m " " #b
|
||||||
|
|
||||||
|
void WOLFSSL_ENTER(const char* msg);
|
||||||
|
void WOLFSSL_LEAVE(const char* msg, int ret);
|
||||||
|
#define WOLFSSL_STUB(m) \
|
||||||
|
WOLFSSL_MSG(WOLFSSL_LOG_CAT(wolfSSL Stub, m, not implemented))
|
||||||
|
|
||||||
|
void WOLFSSL_ERROR(int);
|
||||||
|
void WOLFSSL_MSG(const char* msg);
|
||||||
|
void WOLFSSL_BUFFER(byte* buffer, word32 length);
|
||||||
|
|
||||||
|
#else /* DEBUG_WOLFSSL */
|
||||||
|
|
||||||
|
#define WOLFSSL_ENTER(m)
|
||||||
|
#define WOLFSSL_LEAVE(m, r)
|
||||||
|
#define WOLFSSL_STUB(m)
|
||||||
|
|
||||||
|
#define WOLFSSL_ERROR(e)
|
||||||
|
#define WOLFSSL_MSG(m)
|
||||||
|
#define WOLFSSL_BUFFER(b, l)
|
||||||
|
|
||||||
|
#endif /* DEBUG_WOLFSSL */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif /* WOLFSSL_LOGGING_H */
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
/* md2.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_MD2_H
|
||||||
|
#define WOLF_CRYPT_MD2_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_MD2
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* in bytes */
|
||||||
|
enum {
|
||||||
|
MD2 = 6, /* hash type unique */
|
||||||
|
MD2_BLOCK_SIZE = 16,
|
||||||
|
MD2_DIGEST_SIZE = 16,
|
||||||
|
MD2_PAD_SIZE = 16,
|
||||||
|
MD2_X_SIZE = 48
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Md2 digest */
|
||||||
|
typedef struct Md2 {
|
||||||
|
word32 count; /* bytes % PAD_SIZE */
|
||||||
|
byte X[MD2_X_SIZE];
|
||||||
|
byte C[MD2_BLOCK_SIZE];
|
||||||
|
byte buffer[MD2_BLOCK_SIZE];
|
||||||
|
} Md2;
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API void wc_InitMd2(Md2*);
|
||||||
|
WOLFSSL_API void wc_Md2Update(Md2*, const byte*, word32);
|
||||||
|
WOLFSSL_API void wc_Md2Final(Md2*, byte*);
|
||||||
|
WOLFSSL_API int wc_Md2Hash(const byte*, word32, byte*);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLFSSL_MD2 */
|
||||||
|
#endif /* WOLF_CRYPT_MD2_H */
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
/* md4.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_MD4_H
|
||||||
|
#define WOLF_CRYPT_MD4_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifndef NO_MD4
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* in bytes */
|
||||||
|
enum {
|
||||||
|
MD4_BLOCK_SIZE = 64,
|
||||||
|
MD4_DIGEST_SIZE = 16,
|
||||||
|
MD4_PAD_SIZE = 56
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* MD4 digest */
|
||||||
|
typedef struct Md4 {
|
||||||
|
word32 buffLen; /* in bytes */
|
||||||
|
word32 loLen; /* length in bytes */
|
||||||
|
word32 hiLen; /* length in bytes */
|
||||||
|
word32 digest[MD4_DIGEST_SIZE / sizeof(word32)];
|
||||||
|
word32 buffer[MD4_BLOCK_SIZE / sizeof(word32)];
|
||||||
|
} Md4;
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API void wc_InitMd4(Md4*);
|
||||||
|
WOLFSSL_API void wc_Md4Update(Md4*, const byte*, word32);
|
||||||
|
WOLFSSL_API void wc_Md4Final(Md4*, byte*);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* NO_MD4 */
|
||||||
|
#endif /* WOLF_CRYPT_MD4_H */
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
/* md5.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_MD5_H
|
||||||
|
#define WOLF_CRYPT_MD5_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifndef NO_MD5
|
||||||
|
|
||||||
|
#ifdef HAVE_FIPS
|
||||||
|
#define wc_InitMd5 InitMd5
|
||||||
|
#define wc_Md5Update Md5Update
|
||||||
|
#define wc_Md5Final Md5Final
|
||||||
|
#define wc_Md5Hash Md5Hash
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* in bytes */
|
||||||
|
enum {
|
||||||
|
#if defined(STM32F2_HASH) || defined(STM32F4_HASH)
|
||||||
|
MD5_REG_SIZE = 4, /* STM32 register size, bytes */
|
||||||
|
#endif
|
||||||
|
MD5 = 0, /* hash type unique */
|
||||||
|
MD5_BLOCK_SIZE = 64,
|
||||||
|
MD5_DIGEST_SIZE = 16,
|
||||||
|
MD5_PAD_SIZE = 56
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined(WOLFSSL_PIC32MZ_HASH)
|
||||||
|
#include "port/pic32/pic32mz-crypt.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_TI_HASH
|
||||||
|
|
||||||
|
/* MD5 digest */
|
||||||
|
typedef struct Md5 {
|
||||||
|
word32 buffLen; /* in bytes */
|
||||||
|
word32 loLen; /* length in bytes */
|
||||||
|
word32 hiLen; /* length in bytes */
|
||||||
|
word32 buffer[MD5_BLOCK_SIZE / sizeof(word32)];
|
||||||
|
#if !defined(WOLFSSL_PIC32MZ_HASH)
|
||||||
|
word32 digest[MD5_DIGEST_SIZE / sizeof(word32)];
|
||||||
|
#else
|
||||||
|
word32 digest[PIC32_HASH_SIZE / sizeof(word32)];
|
||||||
|
pic32mz_desc desc ; /* Crypt Engine descriptor */
|
||||||
|
#endif
|
||||||
|
} Md5;
|
||||||
|
|
||||||
|
#else /* WOLFSSL_TI_HASH */
|
||||||
|
#include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WOLFSSL_API void wc_InitMd5(Md5*);
|
||||||
|
WOLFSSL_API void wc_Md5Update(Md5*, const byte*, word32);
|
||||||
|
WOLFSSL_API void wc_Md5Final(Md5*, byte*);
|
||||||
|
WOLFSSL_API int wc_Md5Hash(const byte*, word32, byte*);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* NO_MD5 */
|
||||||
|
#endif /* WOLF_CRYPT_MD5_H */
|
|
@ -0,0 +1,232 @@
|
||||||
|
/* mem_track.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* The memory tracker overrides the wolfSSL memory callback system and uses a
|
||||||
|
* static to track the total, peak and currently allocated bytes.
|
||||||
|
*
|
||||||
|
* If you are already using the memory callbacks then enabling this will
|
||||||
|
* override the memory callbacks and prevent your memory callbacks from
|
||||||
|
* working. This assumes malloc() and free() are available. Feel free to
|
||||||
|
* customize this for your needs.
|
||||||
|
|
||||||
|
* The enable this feature define the following:
|
||||||
|
* #define USE_WOLFSSL_MEMORY
|
||||||
|
* #define WOLFSSL_TRACK_MEMORY
|
||||||
|
*
|
||||||
|
* On startup call:
|
||||||
|
* InitMemoryTracker();
|
||||||
|
*
|
||||||
|
* When ready to dump the memory report call:
|
||||||
|
* ShowMemoryTracker();
|
||||||
|
*
|
||||||
|
* Report example:
|
||||||
|
* total Allocs = 228
|
||||||
|
* total Bytes = 93442
|
||||||
|
* peak Bytes = 8840
|
||||||
|
* current Bytes = 0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* You can also:
|
||||||
|
* #define WOLFSSL_DEBUG_MEMORY
|
||||||
|
*
|
||||||
|
* To print every alloc/free along with the function and line number.
|
||||||
|
* Example output:
|
||||||
|
* Alloc: 0x7fa14a500010 -> 120 at wc_InitRng:496
|
||||||
|
* Free: 0x7fa14a500010 -> 120 at wc_FreeRng:606
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_MEM_TRACK_H
|
||||||
|
#define WOLFSSL_MEM_TRACK_H
|
||||||
|
|
||||||
|
#if defined(USE_WOLFSSL_MEMORY) && !defined(WOLFSSL_STATIC_MEMORY)
|
||||||
|
|
||||||
|
#include "wolfssl/wolfcrypt/logging.h"
|
||||||
|
|
||||||
|
typedef struct memoryStats {
|
||||||
|
size_t totalAllocs; /* number of allocations */
|
||||||
|
size_t totalBytes; /* total number of bytes allocated */
|
||||||
|
size_t peakBytes; /* concurrent max bytes */
|
||||||
|
size_t currentBytes; /* total current bytes in use */
|
||||||
|
} memoryStats;
|
||||||
|
|
||||||
|
typedef struct memHint {
|
||||||
|
size_t thisSize; /* size of this memory */
|
||||||
|
void* thisMemory; /* actual memory for user */
|
||||||
|
} memHint;
|
||||||
|
|
||||||
|
typedef struct memoryTrack {
|
||||||
|
union {
|
||||||
|
memHint hint;
|
||||||
|
byte alignit[16]; /* make sure we have strong alignment */
|
||||||
|
} u;
|
||||||
|
} memoryTrack;
|
||||||
|
|
||||||
|
#if defined(WOLFSSL_TRACK_MEMORY)
|
||||||
|
#define DO_MEM_STATS
|
||||||
|
static memoryStats ourMemStats;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* if defined to not using inline then declare function prototypes */
|
||||||
|
#ifdef NO_INLINE
|
||||||
|
#define STATIC
|
||||||
|
WOLFSSL_LOCAL void* TrackMalloc(size_t sz);
|
||||||
|
WOLFSSL_LOCAL void TrackFree(void* ptr);
|
||||||
|
WOLFSSL_LOCAL void* TrackRealloc(void* ptr, size_t sz);
|
||||||
|
WOLFSSL_LOCAL int InitMemoryTracker(void);
|
||||||
|
WOLFSSL_LOCAL void ShowMemoryTracker(void);
|
||||||
|
#else
|
||||||
|
#define STATIC static
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_DEBUG_MEMORY
|
||||||
|
STATIC INLINE void* TrackMalloc(size_t sz, const char* func, unsigned int line)
|
||||||
|
#else
|
||||||
|
STATIC INLINE void* TrackMalloc(size_t sz)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
memoryTrack* mt;
|
||||||
|
|
||||||
|
if (sz == 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
mt = (memoryTrack*)malloc(sizeof(memoryTrack) + sz);
|
||||||
|
if (mt == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
mt->u.hint.thisSize = sz;
|
||||||
|
mt->u.hint.thisMemory = (byte*)mt + sizeof(memoryTrack);
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_DEBUG_MEMORY
|
||||||
|
printf("Alloc: %p -> %u at %s:%d\n", mt->u.hint.thisMemory, (word32)sz, func, line);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DO_MEM_STATS
|
||||||
|
ourMemStats.totalAllocs++;
|
||||||
|
ourMemStats.totalBytes += sz;
|
||||||
|
ourMemStats.currentBytes += sz;
|
||||||
|
if (ourMemStats.currentBytes > ourMemStats.peakBytes)
|
||||||
|
ourMemStats.peakBytes = ourMemStats.currentBytes;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return mt->u.hint.thisMemory;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_DEBUG_MEMORY
|
||||||
|
STATIC INLINE void TrackFree(void* ptr, const char* func, unsigned int line)
|
||||||
|
#else
|
||||||
|
STATIC INLINE void TrackFree(void* ptr)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
memoryTrack* mt;
|
||||||
|
|
||||||
|
if (ptr == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mt = (memoryTrack*)ptr;
|
||||||
|
--mt; /* same as minus sizeof(memoryTrack), removes header */
|
||||||
|
|
||||||
|
#ifdef DO_MEM_STATS
|
||||||
|
ourMemStats.currentBytes -= mt->u.hint.thisSize;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_DEBUG_MEMORY
|
||||||
|
printf("Free: %p -> %u at %s:%d\n", ptr, (word32)mt->u.hint.thisSize, func, line);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
free(mt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_DEBUG_MEMORY
|
||||||
|
STATIC INLINE void* TrackRealloc(void* ptr, size_t sz, const char* func, unsigned int line)
|
||||||
|
#else
|
||||||
|
STATIC INLINE void* TrackRealloc(void* ptr, size_t sz)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
#ifdef WOLFSSL_DEBUG_MEMORY
|
||||||
|
void* ret = TrackMalloc(sz, func, line);
|
||||||
|
#else
|
||||||
|
void* ret = TrackMalloc(sz);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (ptr) {
|
||||||
|
/* if realloc is bigger, don't overread old ptr */
|
||||||
|
memoryTrack* mt = (memoryTrack*)ptr;
|
||||||
|
--mt; /* same as minus sizeof(memoryTrack), removes header */
|
||||||
|
|
||||||
|
if (mt->u.hint.thisSize < sz)
|
||||||
|
sz = mt->u.hint.thisSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret && ptr)
|
||||||
|
XMEMCPY(ret, ptr, sz);
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
#ifdef WOLFSSL_DEBUG_MEMORY
|
||||||
|
TrackFree(ptr, func, line);
|
||||||
|
#else
|
||||||
|
TrackFree(ptr);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC INLINE int InitMemoryTracker(void)
|
||||||
|
{
|
||||||
|
int ret = wolfSSL_SetAllocators(TrackMalloc, TrackFree, TrackRealloc);
|
||||||
|
if (ret < 0) {
|
||||||
|
printf("wolfSSL SetAllocators failed for track memory\n");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DO_MEM_STATS
|
||||||
|
ourMemStats.totalAllocs = 0;
|
||||||
|
ourMemStats.totalBytes = 0;
|
||||||
|
ourMemStats.peakBytes = 0;
|
||||||
|
ourMemStats.currentBytes = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC INLINE void ShowMemoryTracker(void)
|
||||||
|
{
|
||||||
|
#ifdef DO_MEM_STATS
|
||||||
|
printf("total Allocs = %9lu\n",
|
||||||
|
(unsigned long)ourMemStats.totalAllocs);
|
||||||
|
printf("total Bytes = %9lu\n",
|
||||||
|
(unsigned long)ourMemStats.totalBytes);
|
||||||
|
printf("peak Bytes = %9lu\n",
|
||||||
|
(unsigned long)ourMemStats.peakBytes);
|
||||||
|
printf("current Bytes = %9lu\n",
|
||||||
|
(unsigned long)ourMemStats.currentBytes);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* USE_WOLFSSL_MEMORY */
|
||||||
|
|
||||||
|
#endif /* WOLFSSL_MEM_TRACK_H */
|
||||||
|
|
|
@ -0,0 +1,185 @@
|
||||||
|
/* memory.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* submitted by eof */
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_MEMORY_H
|
||||||
|
#define WOLFSSL_MEMORY_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_STATIC_MEMORY
|
||||||
|
#ifdef WOLFSSL_DEBUG_MEMORY
|
||||||
|
typedef void *(*wolfSSL_Malloc_cb)(size_t size, void* heap, int type, const char* func, unsigned int line);
|
||||||
|
typedef void (*wolfSSL_Free_cb)(void *ptr, void* heap, int type, const char* func, unsigned int line);
|
||||||
|
typedef void *(*wolfSSL_Realloc_cb)(void *ptr, size_t size, void* heap, int type, const char* func, unsigned int line);
|
||||||
|
WOLFSSL_API void* wolfSSL_Malloc(size_t size, void* heap, int type, const char* func, unsigned int line);
|
||||||
|
WOLFSSL_API void wolfSSL_Free(void *ptr, void* heap, int type, const char* func, unsigned int line);
|
||||||
|
WOLFSSL_API void* wolfSSL_Realloc(void *ptr, size_t size, void* heap, int type, const char* func, unsigned int line);
|
||||||
|
#else
|
||||||
|
typedef void *(*wolfSSL_Malloc_cb)(size_t size, void* heap, int type);
|
||||||
|
typedef void (*wolfSSL_Free_cb)(void *ptr, void* heap, int type);
|
||||||
|
typedef void *(*wolfSSL_Realloc_cb)(void *ptr, size_t size, void* heap, int type);
|
||||||
|
WOLFSSL_API void* wolfSSL_Malloc(size_t size, void* heap, int type);
|
||||||
|
WOLFSSL_API void wolfSSL_Free(void *ptr, void* heap, int type);
|
||||||
|
WOLFSSL_API void* wolfSSL_Realloc(void *ptr, size_t size, void* heap, int type);
|
||||||
|
#endif /* WOLFSSL_DEBUG_MEMORY */
|
||||||
|
#else
|
||||||
|
#ifdef WOLFSSL_DEBUG_MEMORY
|
||||||
|
typedef void *(*wolfSSL_Malloc_cb)(size_t size, const char* func, unsigned int line);
|
||||||
|
typedef void (*wolfSSL_Free_cb)(void *ptr, const char* func, unsigned int line);
|
||||||
|
typedef void *(*wolfSSL_Realloc_cb)(void *ptr, size_t size, const char* func, unsigned int line);
|
||||||
|
|
||||||
|
/* Public in case user app wants to use XMALLOC/XFREE */
|
||||||
|
WOLFSSL_API void* wolfSSL_Malloc(size_t size, const char* func, unsigned int line);
|
||||||
|
WOLFSSL_API void wolfSSL_Free(void *ptr, const char* func, unsigned int line);
|
||||||
|
WOLFSSL_API void* wolfSSL_Realloc(void *ptr, size_t size, const char* func, unsigned int line);
|
||||||
|
#else
|
||||||
|
typedef void *(*wolfSSL_Malloc_cb)(size_t size);
|
||||||
|
typedef void (*wolfSSL_Free_cb)(void *ptr);
|
||||||
|
typedef void *(*wolfSSL_Realloc_cb)(void *ptr, size_t size);
|
||||||
|
/* Public in case user app wants to use XMALLOC/XFREE */
|
||||||
|
WOLFSSL_API void* wolfSSL_Malloc(size_t size);
|
||||||
|
WOLFSSL_API void wolfSSL_Free(void *ptr);
|
||||||
|
WOLFSSL_API void* wolfSSL_Realloc(void *ptr, size_t size);
|
||||||
|
#endif /* WOLFSSL_DEBUG_MEMORY */
|
||||||
|
#endif /* WOLFSSL_STATIC_MEMORY */
|
||||||
|
|
||||||
|
/* Public set function */
|
||||||
|
WOLFSSL_API int wolfSSL_SetAllocators(wolfSSL_Malloc_cb malloc_function,
|
||||||
|
wolfSSL_Free_cb free_function,
|
||||||
|
wolfSSL_Realloc_cb realloc_function);
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_STATIC_MEMORY
|
||||||
|
#define WOLFSSL_STATIC_TIMEOUT 1
|
||||||
|
#ifndef WOLFSSL_STATIC_ALIGN
|
||||||
|
#define WOLFSSL_STATIC_ALIGN 16
|
||||||
|
#endif
|
||||||
|
#ifndef WOLFMEM_MAX_BUCKETS
|
||||||
|
#define WOLFMEM_MAX_BUCKETS 9
|
||||||
|
#endif
|
||||||
|
#define WOLFMEM_DEF_BUCKETS 9 /* number of default memory blocks */
|
||||||
|
#define WOLFMEM_IO_SZ 16992 /* 16 byte aligned */
|
||||||
|
#ifndef WOLFMEM_BUCKETS
|
||||||
|
/* default size of chunks of memory to seperate into
|
||||||
|
* having session certs enabled makes a 21k SSL struct */
|
||||||
|
#ifndef SESSION_CERTS
|
||||||
|
#define WOLFMEM_BUCKETS 64,128,256,512,1024,2432,3456,4544,16128
|
||||||
|
#else
|
||||||
|
#define WOLFMEM_BUCKETS 64,128,256,512,1024,2432,3456,4544,21056
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#ifndef WOLFMEM_DIST
|
||||||
|
#define WOLFMEM_DIST 8,4,4,12,4,5,2,1,1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* flags for loading static memory (one hot bit) */
|
||||||
|
#define WOLFMEM_GENERAL 0x01
|
||||||
|
#define WOLFMEM_IO_POOL 0x02
|
||||||
|
#define WOLFMEM_IO_POOL_FIXED 0x04
|
||||||
|
#define WOLFMEM_TRACK_STATS 0x08
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_MEM_GUARD
|
||||||
|
#define WOLFSSL_MEM_GUARD
|
||||||
|
typedef struct WOLFSSL_MEM_STATS WOLFSSL_MEM_STATS;
|
||||||
|
typedef struct WOLFSSL_MEM_CONN_STATS WOLFSSL_MEM_CONN_STATS;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct WOLFSSL_MEM_CONN_STATS {
|
||||||
|
word32 peakMem; /* peak memory usage */
|
||||||
|
word32 curMem; /* current memory usage */
|
||||||
|
word32 peakAlloc; /* peak memory allocations */
|
||||||
|
word32 curAlloc; /* current memory allocations */
|
||||||
|
word32 totalAlloc;/* total memory allocations for lifetime */
|
||||||
|
word32 totalFr; /* total frees for lifetime */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct WOLFSSL_MEM_STATS {
|
||||||
|
word32 curAlloc; /* current memory allocations */
|
||||||
|
word32 totalAlloc;/* total memory allocations for lifetime */
|
||||||
|
word32 totalFr; /* total frees for lifetime */
|
||||||
|
word32 totalUse; /* total amount of memory used in blocks */
|
||||||
|
word32 avaIO; /* available IO specific pools */
|
||||||
|
word32 maxHa; /* max number of concurent handshakes allowed */
|
||||||
|
word32 maxIO; /* max number of concurent IO connections allowed */
|
||||||
|
word32 blockSz[WOLFMEM_MAX_BUCKETS]; /* block sizes in stacks */
|
||||||
|
word32 avaBlock[WOLFMEM_MAX_BUCKETS];/* ava block sizes */
|
||||||
|
word32 usedBlock[WOLFMEM_MAX_BUCKETS];
|
||||||
|
int flag; /* flag used */
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct wc_Memory wc_Memory; /* internal structure for mem bucket */
|
||||||
|
typedef struct WOLFSSL_HEAP {
|
||||||
|
wc_Memory* ava[WOLFMEM_MAX_BUCKETS];
|
||||||
|
wc_Memory* io; /* list of buffers to use for IO */
|
||||||
|
word32 maxHa; /* max concurent handshakes */
|
||||||
|
word32 curHa;
|
||||||
|
word32 maxIO; /* max concurrent IO connections */
|
||||||
|
word32 curIO;
|
||||||
|
word32 sizeList[WOLFMEM_MAX_BUCKETS];/* memory sizes in ava list */
|
||||||
|
word32 distList[WOLFMEM_MAX_BUCKETS];/* general distribution */
|
||||||
|
word32 inUse; /* amount of memory currently in use */
|
||||||
|
word32 ioUse;
|
||||||
|
word32 alloc; /* total number of allocs */
|
||||||
|
word32 frAlc; /* total number of frees */
|
||||||
|
int flag;
|
||||||
|
wolfSSL_Mutex memory_mutex;
|
||||||
|
} WOLFSSL_HEAP;
|
||||||
|
|
||||||
|
/* structure passed into XMALLOC as heap hint
|
||||||
|
* having this abstraction allows tracking statistics of individual ssl's
|
||||||
|
*/
|
||||||
|
typedef struct WOLFSSL_HEAP_HINT {
|
||||||
|
WOLFSSL_HEAP* memory;
|
||||||
|
WOLFSSL_MEM_CONN_STATS* stats; /* hold individual connection stats */
|
||||||
|
wc_Memory* outBuf; /* set if using fixed io buffers */
|
||||||
|
wc_Memory* inBuf;
|
||||||
|
byte haFlag; /* flag used for checking handshake count */
|
||||||
|
} WOLFSSL_HEAP_HINT;
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_LoadStaticMemory(WOLFSSL_HEAP_HINT** pHint,
|
||||||
|
unsigned char* buf, unsigned int sz, int flag, int max);
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL int wolfSSL_init_memory_heap(WOLFSSL_HEAP* heap);
|
||||||
|
WOLFSSL_LOCAL int wolfSSL_load_static_memory(byte* buffer, word32 sz,
|
||||||
|
int flag, WOLFSSL_HEAP* heap);
|
||||||
|
WOLFSSL_LOCAL int wolfSSL_GetMemStats(WOLFSSL_HEAP* heap,
|
||||||
|
WOLFSSL_MEM_STATS* stats);
|
||||||
|
WOLFSSL_LOCAL int SetFixedIO(WOLFSSL_HEAP* heap, wc_Memory** io);
|
||||||
|
WOLFSSL_LOCAL int FreeFixedIO(WOLFSSL_HEAP* heap, wc_Memory** io);
|
||||||
|
|
||||||
|
WOLFSSL_API int wolfSSL_StaticBufferSz(byte* buffer, word32 sz, int flag);
|
||||||
|
WOLFSSL_API int wolfSSL_MemoryPaddingSz(void);
|
||||||
|
#endif /* WOLFSSL_STATIC_MEMORY */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLFSSL_MEMORY_H */
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
/* misc.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_MISC_H
|
||||||
|
#define WOLF_CRYPT_MISC_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef NO_INLINE
|
||||||
|
WOLFSSL_LOCAL
|
||||||
|
word32 rotlFixed(word32, word32);
|
||||||
|
WOLFSSL_LOCAL
|
||||||
|
word32 rotrFixed(word32, word32);
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL
|
||||||
|
word32 ByteReverseWord32(word32);
|
||||||
|
WOLFSSL_LOCAL
|
||||||
|
void ByteReverseWords(word32*, const word32*, word32);
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL
|
||||||
|
void XorWords(wolfssl_word*, const wolfssl_word*, word32);
|
||||||
|
WOLFSSL_LOCAL
|
||||||
|
void xorbuf(void*, const void*, word32);
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL
|
||||||
|
void ForceZero(const void*, word32);
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL
|
||||||
|
int ConstantCompare(const byte*, const byte*, int);
|
||||||
|
|
||||||
|
#ifdef WORD64_AVAILABLE
|
||||||
|
WOLFSSL_LOCAL
|
||||||
|
word64 rotlFixed64(word64, word64);
|
||||||
|
WOLFSSL_LOCAL
|
||||||
|
word64 rotrFixed64(word64, word64);
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL
|
||||||
|
word64 ByteReverseWord64(word64);
|
||||||
|
WOLFSSL_LOCAL
|
||||||
|
void ByteReverseWords64(word64*, const word64*, word32);
|
||||||
|
#endif /* WORD64_AVAILABLE */
|
||||||
|
|
||||||
|
#endif /* NO_INLINE */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* WOLF_CRYPT_MISC_H */
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,96 @@
|
||||||
|
/* mpi_superclass.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* super class file for PK algos */
|
||||||
|
|
||||||
|
/* default ... include all MPI */
|
||||||
|
#define LTM_ALL
|
||||||
|
|
||||||
|
/* RSA only (does not support DH/DSA/ECC) */
|
||||||
|
/* #define SC_RSA_1 */
|
||||||
|
|
||||||
|
/* For reference.... On an Athlon64 optimizing for speed...
|
||||||
|
|
||||||
|
LTM's mpi.o with all functions [striped] is 142KiB in size.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Works for RSA only, mpi.o is 68KiB */
|
||||||
|
#ifdef SC_RSA_1
|
||||||
|
#define BN_MP_SHRINK_C
|
||||||
|
#define BN_MP_LCM_C
|
||||||
|
#define BN_MP_PRIME_RANDOM_EX_C
|
||||||
|
#define BN_MP_INVMOD_C
|
||||||
|
#define BN_MP_GCD_C
|
||||||
|
#define BN_MP_MOD_C
|
||||||
|
#define BN_MP_MULMOD_C
|
||||||
|
#define BN_MP_ADDMOD_C
|
||||||
|
#define BN_MP_EXPTMOD_C
|
||||||
|
#define BN_MP_SET_INT_C
|
||||||
|
#define BN_MP_INIT_MULTI_C
|
||||||
|
#define BN_MP_CLEAR_MULTI_C
|
||||||
|
#define BN_MP_UNSIGNED_BIN_SIZE_C
|
||||||
|
#define BN_MP_TO_UNSIGNED_BIN_C
|
||||||
|
#define BN_MP_MOD_D_C
|
||||||
|
#define BN_MP_PRIME_RABIN_MILLER_TRIALS_C
|
||||||
|
#define BN_REVERSE_C
|
||||||
|
#define BN_PRIME_TAB_C
|
||||||
|
|
||||||
|
/* other modifiers */
|
||||||
|
#define BN_MP_DIV_SMALL /* Slower division, not critical */
|
||||||
|
|
||||||
|
/* here we are on the last pass so we turn things off. The functions classes are still there
|
||||||
|
* but we remove them specifically from the build. This also invokes tweaks in functions
|
||||||
|
* like removing support for even moduli, etc...
|
||||||
|
*/
|
||||||
|
#ifdef LTM_LAST
|
||||||
|
#undef BN_MP_TOOM_MUL_C
|
||||||
|
#undef BN_MP_TOOM_SQR_C
|
||||||
|
#undef BN_MP_KARATSUBA_MUL_C
|
||||||
|
#undef BN_MP_KARATSUBA_SQR_C
|
||||||
|
#undef BN_MP_REDUCE_C
|
||||||
|
#undef BN_MP_REDUCE_SETUP_C
|
||||||
|
#undef BN_MP_DR_IS_MODULUS_C
|
||||||
|
#undef BN_MP_DR_SETUP_C
|
||||||
|
#undef BN_MP_DR_REDUCE_C
|
||||||
|
#undef BN_MP_REDUCE_IS_2K_C
|
||||||
|
#undef BN_MP_REDUCE_2K_SETUP_C
|
||||||
|
#undef BN_MP_REDUCE_2K_C
|
||||||
|
#undef BN_S_MP_EXPTMOD_C
|
||||||
|
#undef BN_MP_DIV_3_C
|
||||||
|
#undef BN_S_MP_MUL_HIGH_DIGS_C
|
||||||
|
#undef BN_FAST_S_MP_MUL_HIGH_DIGS_C
|
||||||
|
#undef BN_FAST_MP_INVMOD_C
|
||||||
|
|
||||||
|
/* To safely undefine these you have to make sure your RSA key won't exceed the Comba threshold
|
||||||
|
* which is roughly 255 digits [7140 bits for 32-bit machines, 15300 bits for 64-bit machines]
|
||||||
|
* which means roughly speaking you can handle up to 2536-bit RSA keys with these defined without
|
||||||
|
* trouble.
|
||||||
|
*/
|
||||||
|
#undef BN_S_MP_MUL_DIGS_C
|
||||||
|
#undef BN_S_MP_SQR_C
|
||||||
|
#undef BN_MP_MONTGOMERY_REDUCE_C
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
/* pkcs12.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_PKCS12_H
|
||||||
|
#define WOLF_CRYPT_PKCS12_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_TYPES_DEFINED /* do not redeclare from ssl.h */
|
||||||
|
typedef struct WC_PKCS12 WC_PKCS12;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct WC_DerCertList { /* dereferenced in ssl.c */
|
||||||
|
byte* buffer;
|
||||||
|
word32 bufferSz;
|
||||||
|
struct WC_DerCertList* next;
|
||||||
|
} WC_DerCertList;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API WC_PKCS12* wc_PKCS12_new(void);
|
||||||
|
WOLFSSL_API void wc_PKCS12_free(WC_PKCS12* pkcs12);
|
||||||
|
WOLFSSL_API int wc_d2i_PKCS12(const byte* der, word32 derSz, WC_PKCS12* pkcs12);
|
||||||
|
WOLFSSL_API int wc_PKCS12_parse(WC_PKCS12* pkcs12, const char* psw,
|
||||||
|
byte** pkey, word32* pkeySz, byte** cert, word32* certSz,
|
||||||
|
WC_DerCertList** ca);
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL int wc_PKCS12_SetHeap(WC_PKCS12* pkcs12, void* heap);
|
||||||
|
WOLFSSL_LOCAL void* wc_PKCS12_GetHeap(WC_PKCS12* pkcs12);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLF_CRYPT_PKCS12_H */
|
||||||
|
|
|
@ -0,0 +1,157 @@
|
||||||
|
/* pkcs7.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_PKCS7_H
|
||||||
|
#define WOLF_CRYPT_PKCS7_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_PKCS7
|
||||||
|
|
||||||
|
#ifndef NO_ASN
|
||||||
|
#include <wolfssl/wolfcrypt/asn.h>
|
||||||
|
#endif
|
||||||
|
#include <wolfssl/wolfcrypt/asn_public.h>
|
||||||
|
#include <wolfssl/wolfcrypt/random.h>
|
||||||
|
#ifndef NO_AES
|
||||||
|
#include <wolfssl/wolfcrypt/aes.h>
|
||||||
|
#endif
|
||||||
|
#ifndef NO_DES3
|
||||||
|
#include <wolfssl/wolfcrypt/des3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* PKCS#7 content types, ref RFC 2315 (Section 14) */
|
||||||
|
enum PKCS7_TYPES {
|
||||||
|
PKCS7_MSG = 650, /* 1.2.840.113549.1.7 */
|
||||||
|
DATA = 651, /* 1.2.840.113549.1.7.1 */
|
||||||
|
SIGNED_DATA = 652, /* 1.2.840.113549.1.7.2 */
|
||||||
|
ENVELOPED_DATA = 653, /* 1.2.840.113549.1.7.3 */
|
||||||
|
SIGNED_AND_ENVELOPED_DATA = 654, /* 1.2.840.113549.1.7.4 */
|
||||||
|
DIGESTED_DATA = 655, /* 1.2.840.113549.1.7.5 */
|
||||||
|
ENCRYPTED_DATA = 656 /* 1.2.840.113549.1.7.6 */
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Pkcs7_Misc {
|
||||||
|
PKCS7_NONCE_SZ = 16,
|
||||||
|
MAX_ENCRYPTED_KEY_SZ = 512, /* max enc. key size, RSA <= 4096 */
|
||||||
|
MAX_CONTENT_KEY_LEN = 32, /* highest current cipher is AES-256-CBC */
|
||||||
|
MAX_CONTENT_IV_SIZE = 16, /* highest current is AES128 */
|
||||||
|
#ifndef NO_AES
|
||||||
|
MAX_CONTENT_BLOCK_LEN = AES_BLOCK_SIZE,
|
||||||
|
#else
|
||||||
|
MAX_CONTENT_BLOCK_LEN = DES_BLOCK_SIZE,
|
||||||
|
#endif
|
||||||
|
MAX_RECIP_SZ = MAX_VERSION_SZ +
|
||||||
|
MAX_SEQ_SZ + ASN_NAME_MAX + MAX_SN_SZ +
|
||||||
|
MAX_SEQ_SZ + MAX_ALGO_SZ + 1 + MAX_ENCRYPTED_KEY_SZ
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct PKCS7Attrib {
|
||||||
|
byte* oid;
|
||||||
|
word32 oidSz;
|
||||||
|
byte* value;
|
||||||
|
word32 valueSz;
|
||||||
|
} PKCS7Attrib;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct PKCS7DecodedAttrib {
|
||||||
|
byte* oid;
|
||||||
|
word32 oidSz;
|
||||||
|
byte* value;
|
||||||
|
word32 valueSz;
|
||||||
|
struct PKCS7DecodedAttrib* next;
|
||||||
|
} PKCS7DecodedAttrib;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct PKCS7 {
|
||||||
|
byte* content; /* inner content, not owner */
|
||||||
|
word32 contentSz; /* content size */
|
||||||
|
int contentOID; /* PKCS#7 content type OID sum */
|
||||||
|
|
||||||
|
WC_RNG* rng;
|
||||||
|
|
||||||
|
int hashOID;
|
||||||
|
int encryptOID; /* key encryption algorithm OID */
|
||||||
|
int keyWrapOID; /* key wrap algorithm OID */
|
||||||
|
int keyAgreeOID; /* key agreement algorithm OID */
|
||||||
|
|
||||||
|
void* heap; /* heap hint for dynamic memory */
|
||||||
|
byte* singleCert; /* recipient cert, DER, not owner */
|
||||||
|
word32 singleCertSz; /* size of recipient cert buffer, bytes */
|
||||||
|
byte issuerHash[KEYID_SIZE]; /* hash of all alt Names */
|
||||||
|
byte* issuer; /* issuer name of singleCert */
|
||||||
|
word32 issuerSz; /* length of issuer name */
|
||||||
|
byte issuerSn[MAX_SN_SZ]; /* singleCert's serial number */
|
||||||
|
word32 issuerSnSz; /* length of serial number */
|
||||||
|
|
||||||
|
byte publicKey[512];
|
||||||
|
word32 publicKeySz;
|
||||||
|
word32 publicKeyOID; /* key OID (RSAk, ECDSAk, etc) */
|
||||||
|
byte* privateKey; /* private key, DER, not owner */
|
||||||
|
word32 privateKeySz; /* size of private key buffer, bytes */
|
||||||
|
|
||||||
|
PKCS7Attrib* signedAttribs;
|
||||||
|
word32 signedAttribsSz;
|
||||||
|
|
||||||
|
/* Enveloped-data optional ukm, not owner */
|
||||||
|
byte* ukm;
|
||||||
|
word32 ukmSz;
|
||||||
|
|
||||||
|
/* Encrypted-data Content Type */
|
||||||
|
byte* encryptionKey; /* block cipher encryption key */
|
||||||
|
word32 encryptionKeySz; /* size of key buffer, bytes */
|
||||||
|
PKCS7Attrib* unprotectedAttribs; /* optional */
|
||||||
|
word32 unprotectedAttribsSz;
|
||||||
|
PKCS7DecodedAttrib* decodedAttrib; /* linked list of decoded attribs */
|
||||||
|
} PKCS7;
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_PKCS7_InitWithCert(PKCS7* pkcs7, byte* cert, word32 certSz);
|
||||||
|
WOLFSSL_API void wc_PKCS7_Free(PKCS7* pkcs7);
|
||||||
|
WOLFSSL_API int wc_PKCS7_EncodeData(PKCS7* pkcs7, byte* output,
|
||||||
|
word32 outputSz);
|
||||||
|
WOLFSSL_API int wc_PKCS7_EncodeSignedData(PKCS7* pkcs7,
|
||||||
|
byte* output, word32 outputSz);
|
||||||
|
WOLFSSL_API int wc_PKCS7_VerifySignedData(PKCS7* pkcs7,
|
||||||
|
byte* pkiMsg, word32 pkiMsgSz);
|
||||||
|
WOLFSSL_API int wc_PKCS7_EncodeEnvelopedData(PKCS7* pkcs7,
|
||||||
|
byte* output, word32 outputSz);
|
||||||
|
WOLFSSL_API int wc_PKCS7_DecodeEnvelopedData(PKCS7* pkcs7, byte* pkiMsg,
|
||||||
|
word32 pkiMsgSz, byte* output,
|
||||||
|
word32 outputSz);
|
||||||
|
WOLFSSL_API int wc_PKCS7_EncodeEncryptedData(PKCS7* pkcs7,
|
||||||
|
byte* output, word32 outputSz);
|
||||||
|
WOLFSSL_API int wc_PKCS7_DecodeEncryptedData(PKCS7* pkcs7, byte* pkiMsg,
|
||||||
|
word32 pkiMsgSz, byte* output,
|
||||||
|
word32 outputSz);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAVE_PKCS7 */
|
||||||
|
#endif /* WOLF_CRYPT_PKCS7_H */
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
/* poly1305.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_POLY1305_H
|
||||||
|
#define WOLF_CRYPT_POLY1305_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_POLY1305
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* auto detect between 32bit / 64bit */
|
||||||
|
#if defined(__SIZEOF_INT128__) && defined(__LP64__)
|
||||||
|
#define WC_HAS_SIZEOF_INT128_64BIT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && defined(_M_X64)
|
||||||
|
#define WC_HAS_MSVC_64BIT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (defined(__GNUC__) && defined(__LP64__) && \
|
||||||
|
((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4))))
|
||||||
|
#define WC_HAS_GCC_4_4_64BIT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (defined(WC_HAS_SIZEOF_INT128_64BIT) || defined(WC_HAS_MSVC_64BIT) || \
|
||||||
|
defined(WC_HAS_GCC_4_4_64BIT))
|
||||||
|
#define POLY130564
|
||||||
|
#else
|
||||||
|
#define POLY130532
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum {
|
||||||
|
POLY1305 = 7,
|
||||||
|
POLY1305_BLOCK_SIZE = 16,
|
||||||
|
POLY1305_DIGEST_SIZE = 16,
|
||||||
|
};
|
||||||
|
|
||||||
|
#define WC_POLY1305_PAD_SZ 16
|
||||||
|
#define WC_POLY1305_MAC_SZ 16
|
||||||
|
|
||||||
|
/* Poly1305 state */
|
||||||
|
typedef struct Poly1305 {
|
||||||
|
#if defined(POLY130564)
|
||||||
|
word64 r[3];
|
||||||
|
word64 h[3];
|
||||||
|
word64 pad[2];
|
||||||
|
#else
|
||||||
|
word32 r[5];
|
||||||
|
word32 h[5];
|
||||||
|
word32 pad[4];
|
||||||
|
#endif
|
||||||
|
size_t leftover;
|
||||||
|
unsigned char buffer[POLY1305_BLOCK_SIZE];
|
||||||
|
unsigned char final;
|
||||||
|
} Poly1305;
|
||||||
|
|
||||||
|
|
||||||
|
/* does init */
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_Poly1305SetKey(Poly1305* poly1305, const byte* key, word32 kySz);
|
||||||
|
WOLFSSL_API int wc_Poly1305Update(Poly1305* poly1305, const byte*, word32);
|
||||||
|
WOLFSSL_API int wc_Poly1305Final(Poly1305* poly1305, byte* tag);
|
||||||
|
WOLFSSL_API int wc_Poly1305_MAC(Poly1305* ctx, byte* additional, word32 addSz,
|
||||||
|
byte* input, word32 sz, byte* tag, word32 tagSz);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAVE_POLY1305 */
|
||||||
|
#endif /* WOLF_CRYPT_POLY1305_H */
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
/* pwdbased.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_PWDBASED_H
|
||||||
|
#define WOLF_CRYPT_PWDBASED_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifndef NO_PWDBASED
|
||||||
|
|
||||||
|
#ifndef NO_MD5
|
||||||
|
#include <wolfssl/wolfcrypt/md5.h> /* for hash type */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/sha.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* hashType renamed to typeH to avoid shadowing global declaration here:
|
||||||
|
* wolfssl/wolfcrypt/asn.h line 173 in enum Oid_Types
|
||||||
|
*/
|
||||||
|
WOLFSSL_API int wc_PBKDF1(byte* output, const byte* passwd, int pLen,
|
||||||
|
const byte* salt, int sLen, int iterations, int kLen,
|
||||||
|
int typeH);
|
||||||
|
WOLFSSL_API int wc_PBKDF2(byte* output, const byte* passwd, int pLen,
|
||||||
|
const byte* salt, int sLen, int iterations, int kLen,
|
||||||
|
int typeH);
|
||||||
|
WOLFSSL_API int wc_PKCS12_PBKDF(byte* output, const byte* passwd, int pLen,
|
||||||
|
const byte* salt, int sLen, int iterations,
|
||||||
|
int kLen, int typeH, int purpose);
|
||||||
|
WOLFSSL_API int wc_PKCS12_PBKDF_ex(byte* output, const byte* passwd,int passLen,
|
||||||
|
const byte* salt, int saltLen, int iterations, int kLen,
|
||||||
|
int hashType, int id, void* heap);
|
||||||
|
|
||||||
|
#ifdef HAVE_SCRYPT
|
||||||
|
WOLFSSL_API int wc_scrypt(byte* output, const byte* passwd, int passLen,
|
||||||
|
const byte* salt, int saltLen, int cost,
|
||||||
|
int blockSize, int parallel, int dkLen);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* helper functions */
|
||||||
|
WOLFSSL_LOCAL int GetDigestSize(int typeH);
|
||||||
|
WOLFSSL_LOCAL int GetPKCS12HashSizes(int typeH, word32* v, word32* u);
|
||||||
|
WOLFSSL_LOCAL int DoPKCS12Hash(int typeH, byte* buffer, word32 totalLen,
|
||||||
|
byte* Ai, word32 u, int iterations);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* NO_PWDBASED */
|
||||||
|
#endif /* WOLF_CRYPT_PWDBASED_H */
|
|
@ -0,0 +1,69 @@
|
||||||
|
/* rabbit.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_RABBIT_H
|
||||||
|
#define WOLF_CRYPT_RABBIT_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifndef NO_RABBIT
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
enum {
|
||||||
|
RABBIT_ENC_TYPE = 5 /* cipher unique type */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Rabbit Context */
|
||||||
|
typedef struct RabbitCtx {
|
||||||
|
word32 x[8];
|
||||||
|
word32 c[8];
|
||||||
|
word32 carry;
|
||||||
|
} RabbitCtx;
|
||||||
|
|
||||||
|
|
||||||
|
/* Rabbit stream cipher */
|
||||||
|
typedef struct Rabbit {
|
||||||
|
RabbitCtx masterCtx;
|
||||||
|
RabbitCtx workCtx;
|
||||||
|
#ifdef XSTREAM_ALIGN
|
||||||
|
void* heap; /* heap hint, currently XMALLOC only used with aligning */
|
||||||
|
#endif
|
||||||
|
} Rabbit;
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_RabbitProcess(Rabbit*, byte*, const byte*, word32);
|
||||||
|
WOLFSSL_API int wc_RabbitSetKey(Rabbit*, const byte* key, const byte* iv);
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL int wc_Rabbit_SetHeap(Rabbit* ctx, void* heap);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* NO_RABBIT */
|
||||||
|
#endif /* WOLF_CRYPT_RABBIT_H */
|
||||||
|
|
|
@ -0,0 +1,179 @@
|
||||||
|
/* random.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_RANDOM_H
|
||||||
|
#define WOLF_CRYPT_RANDOM_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_FIPS
|
||||||
|
/* for fips @wc_fips */
|
||||||
|
#include <cyassl/ctaocrypt/random.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Maximum generate block length */
|
||||||
|
#define RNG_MAX_BLOCK_LEN (0x10000)
|
||||||
|
|
||||||
|
#ifndef HAVE_FIPS /* avoid redefining structs and macros */
|
||||||
|
|
||||||
|
#if defined(WOLFSSL_FORCE_RC4_DRBG) && defined(NO_RC4)
|
||||||
|
#error Cannot have WOLFSSL_FORCE_RC4_DRBG and NO_RC4 defined.
|
||||||
|
#endif /* WOLFSSL_FORCE_RC4_DRBG && NO_RC4 */
|
||||||
|
|
||||||
|
|
||||||
|
/* RNG supports the following sources (in order):
|
||||||
|
* 1. CUSTOM_RAND_GENERATE_BLOCK: Defines name of function as RNG source and
|
||||||
|
* bypasses the P-RNG.
|
||||||
|
* 2. HAVE_HASHDRBG && !NO_SHA256 (SHA256 enabled): Uses SHA256 based P-RNG
|
||||||
|
* seeded via wc_GenerateSeed. This is the default source.
|
||||||
|
* 3. !NO_RC4 (RC4 enabled): Uses RC4
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(CUSTOM_RAND_GENERATE_BLOCK)
|
||||||
|
/* To use define the following:
|
||||||
|
* #define CUSTOM_RAND_GENERATE_BLOCK myRngFunc
|
||||||
|
* extern int myRngFunc(byte* output, word32 sz);
|
||||||
|
*/
|
||||||
|
#elif (defined(HAVE_HASHDRBG) || defined(NO_RC4))
|
||||||
|
#ifdef NO_SHA256
|
||||||
|
#error "Hash DRBG requires SHA-256."
|
||||||
|
#endif /* NO_SHA256 */
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/sha256.h>
|
||||||
|
#else
|
||||||
|
#include <wolfssl/wolfcrypt/arc4.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_WNR
|
||||||
|
#include <wnr.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(USE_WINDOWS_API)
|
||||||
|
#if defined(_WIN64)
|
||||||
|
typedef unsigned __int64 ProviderHandle;
|
||||||
|
/* type HCRYPTPROV, avoid #include <windows.h> */
|
||||||
|
#else
|
||||||
|
typedef unsigned long ProviderHandle;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* OS specific seeder */
|
||||||
|
typedef struct OS_Seed {
|
||||||
|
#if defined(USE_WINDOWS_API)
|
||||||
|
ProviderHandle handle;
|
||||||
|
#else
|
||||||
|
int fd;
|
||||||
|
#endif
|
||||||
|
} OS_Seed;
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WC_RNG_TYPE_DEFINED /* guard on redeclaration */
|
||||||
|
typedef struct WC_RNG WC_RNG;
|
||||||
|
#define WC_RNG_TYPE_DEFINED
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (defined(HAVE_HASHDRBG) || defined(NO_RC4)) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
|
||||||
|
|
||||||
|
#define DRBG_SEED_LEN (440/8)
|
||||||
|
|
||||||
|
|
||||||
|
struct DRBG; /* Private DRBG state */
|
||||||
|
|
||||||
|
|
||||||
|
/* Hash-based Deterministic Random Bit Generator */
|
||||||
|
struct WC_RNG {
|
||||||
|
struct DRBG* drbg;
|
||||||
|
OS_Seed seed;
|
||||||
|
void* heap;
|
||||||
|
byte status;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#else /* (HAVE_HASHDRBG || NO_RC4) && !CUSTOM_RAND_GENERATE_BLOCK */
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
#include <wolfssl/wolfcrypt/async.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* secure Random Number Generator */
|
||||||
|
|
||||||
|
|
||||||
|
struct WC_RNG {
|
||||||
|
OS_Seed seed;
|
||||||
|
#ifndef NO_RC4
|
||||||
|
Arc4 cipher;
|
||||||
|
#endif
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
AsyncCryptDev asyncDev;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* (HAVE_HASHDRBG || NO_RC4) && !CUSTOM_RAND_GENERATE_BLOCK */
|
||||||
|
#endif /* HAVE_FIPS */
|
||||||
|
|
||||||
|
/* NO_OLD_RNGNAME removes RNG struct name to prevent possible type conflicts,
|
||||||
|
* can't be used with CTaoCrypt FIPS */
|
||||||
|
#if !defined(NO_OLD_RNGNAME) && !defined(HAVE_FIPS)
|
||||||
|
#define RNG WC_RNG
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL
|
||||||
|
int wc_GenerateSeed(OS_Seed* os, byte* seed, word32 sz);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_WNR
|
||||||
|
/* Whitewood netRandom client library */
|
||||||
|
WOLFSSL_API int wc_InitNetRandom(const char*, wnr_hmac_key, int);
|
||||||
|
WOLFSSL_API int wc_FreeNetRandom(void);
|
||||||
|
#endif /* HAVE_WNR */
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_InitRng(WC_RNG*);
|
||||||
|
WOLFSSL_API int wc_InitRng_ex(WC_RNG* rng, void* heap);
|
||||||
|
WOLFSSL_API int wc_RNG_GenerateBlock(WC_RNG*, byte*, word32 sz);
|
||||||
|
WOLFSSL_API int wc_RNG_GenerateByte(WC_RNG*, byte*);
|
||||||
|
WOLFSSL_API int wc_FreeRng(WC_RNG*);
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(HAVE_HASHDRBG) || defined(NO_RC4)
|
||||||
|
WOLFSSL_API int wc_RNG_HealthTest(int reseed,
|
||||||
|
const byte* entropyA, word32 entropyASz,
|
||||||
|
const byte* entropyB, word32 entropyBSz,
|
||||||
|
byte* output, word32 outputSz);
|
||||||
|
#endif /* HAVE_HASHDRBG || NO_RC4 */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLF_CRYPT_RANDOM_H */
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
/* ripemd.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_RIPEMD_H
|
||||||
|
#define WOLF_CRYPT_RIPEMD_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_RIPEMD
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* in bytes */
|
||||||
|
enum {
|
||||||
|
RIPEMD = 3, /* hash type unique */
|
||||||
|
RIPEMD_BLOCK_SIZE = 64,
|
||||||
|
RIPEMD_DIGEST_SIZE = 20,
|
||||||
|
RIPEMD_PAD_SIZE = 56
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* RipeMd 160 digest */
|
||||||
|
typedef struct RipeMd {
|
||||||
|
word32 buffLen; /* in bytes */
|
||||||
|
word32 loLen; /* length in bytes */
|
||||||
|
word32 hiLen; /* length in bytes */
|
||||||
|
word32 digest[RIPEMD_DIGEST_SIZE / sizeof(word32)];
|
||||||
|
word32 buffer[RIPEMD_BLOCK_SIZE / sizeof(word32)];
|
||||||
|
} RipeMd;
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API void wc_InitRipeMd(RipeMd*);
|
||||||
|
WOLFSSL_API void wc_RipeMdUpdate(RipeMd*, const byte*, word32);
|
||||||
|
WOLFSSL_API void wc_RipeMdFinal(RipeMd*, byte*);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLFSSL_RIPEMD */
|
||||||
|
#endif /* WOLF_CRYPT_RIPEMD_H */
|
|
@ -0,0 +1,179 @@
|
||||||
|
/* rsa.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_RSA_H
|
||||||
|
#define WOLF_CRYPT_RSA_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifndef NO_RSA
|
||||||
|
|
||||||
|
/* allow for user to plug in own crypto */
|
||||||
|
#if !defined(HAVE_FIPS) && (defined(HAVE_USER_RSA) || defined(HAVE_FAST_RSA))
|
||||||
|
#include "user_rsa.h"
|
||||||
|
#else
|
||||||
|
|
||||||
|
#ifdef HAVE_FIPS
|
||||||
|
/* for fips @wc_fips */
|
||||||
|
#include <cyassl/ctaocrypt/rsa.h>
|
||||||
|
#if defined(CYASSL_KEY_GEN) && !defined(WOLFSSL_KEY_GEN)
|
||||||
|
#define WOLFSSL_KEY_GEN
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#include <wolfssl/wolfcrypt/integer.h>
|
||||||
|
#include <wolfssl/wolfcrypt/random.h>
|
||||||
|
#endif /* HAVE_FIPS */
|
||||||
|
|
||||||
|
/* header file needed for OAEP padding */
|
||||||
|
#include <wolfssl/wolfcrypt/hash.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* avoid redefinition of structs */
|
||||||
|
#if !defined(HAVE_FIPS)
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
#include <wolfssl/wolfcrypt/async.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum {
|
||||||
|
RSA_PUBLIC = 0,
|
||||||
|
RSA_PRIVATE = 1,
|
||||||
|
|
||||||
|
RSA_TYPE_UNKNOWN = -1,
|
||||||
|
RSA_PUBLIC_ENCRYPT = 0,
|
||||||
|
RSA_PUBLIC_DECRYPT = 1,
|
||||||
|
RSA_PRIVATE_ENCRYPT = 2,
|
||||||
|
RSA_PRIVATE_DECRYPT = 3,
|
||||||
|
|
||||||
|
RSA_BLOCK_TYPE_1 = 1,
|
||||||
|
RSA_BLOCK_TYPE_2 = 2,
|
||||||
|
|
||||||
|
RSA_MIN_SIZE = 512,
|
||||||
|
RSA_MAX_SIZE = 4096,
|
||||||
|
|
||||||
|
RSA_MIN_PAD_SZ = 11 /* separator + 0 + pad value + 8 pads */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* RSA */
|
||||||
|
typedef struct RsaKey {
|
||||||
|
mp_int n, e, d, p, q, dP, dQ, u;
|
||||||
|
int type; /* public or private */
|
||||||
|
void* heap; /* for user memory overrides */
|
||||||
|
int state;
|
||||||
|
byte* tmp; /* temp buffer for async RSA */
|
||||||
|
word32 tmpLen;
|
||||||
|
byte tmpIsAlloc;
|
||||||
|
#ifdef WC_RSA_BLINDING
|
||||||
|
WC_RNG* rng; /* for PrivateDecrypt blinding */
|
||||||
|
#endif
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
AsyncCryptDev asyncDev;
|
||||||
|
#endif /* WOLFSSL_ASYNC_CRYPT */
|
||||||
|
} RsaKey;
|
||||||
|
#endif /*HAVE_FIPS */
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_InitRsaKey(RsaKey* key, void* heap);
|
||||||
|
WOLFSSL_API int wc_InitRsaKey_ex(RsaKey* key, void* heap, int devId);
|
||||||
|
WOLFSSL_API int wc_FreeRsaKey(RsaKey* key);
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL int wc_RsaFunction(const byte* in, word32 inLen, byte* out,
|
||||||
|
word32* outLen, int type, RsaKey* key, WC_RNG* rng);
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_RsaPublicEncrypt(const byte* in, word32 inLen, byte* out,
|
||||||
|
word32 outLen, RsaKey* key, WC_RNG* rng);
|
||||||
|
WOLFSSL_API int wc_RsaPrivateDecryptInline(byte* in, word32 inLen, byte** out,
|
||||||
|
RsaKey* key);
|
||||||
|
WOLFSSL_API int wc_RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out,
|
||||||
|
word32 outLen, RsaKey* key);
|
||||||
|
WOLFSSL_API int wc_RsaSSL_Sign(const byte* in, word32 inLen, byte* out,
|
||||||
|
word32 outLen, RsaKey* key, WC_RNG* rng);
|
||||||
|
WOLFSSL_API int wc_RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out,
|
||||||
|
RsaKey* key);
|
||||||
|
WOLFSSL_API int wc_RsaSSL_Verify(const byte* in, word32 inLen, byte* out,
|
||||||
|
word32 outLen, RsaKey* key);
|
||||||
|
WOLFSSL_API int wc_RsaEncryptSize(RsaKey* key);
|
||||||
|
|
||||||
|
#ifndef HAVE_FIPS /* to avoid asn duplicate symbols @wc_fips */
|
||||||
|
WOLFSSL_API int wc_RsaPrivateKeyDecode(const byte* input, word32* inOutIdx,
|
||||||
|
RsaKey*, word32);
|
||||||
|
WOLFSSL_API int wc_RsaPublicKeyDecode(const byte* input, word32* inOutIdx,
|
||||||
|
RsaKey*, word32);
|
||||||
|
WOLFSSL_API int wc_RsaPublicKeyDecodeRaw(const byte* n, word32 nSz,
|
||||||
|
const byte* e, word32 eSz, RsaKey* key);
|
||||||
|
#ifdef WOLFSSL_KEY_GEN
|
||||||
|
WOLFSSL_API int wc_RsaKeyToDer(RsaKey*, byte* output, word32 inLen);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_RsaSetRNG(RsaKey* key, WC_RNG* rng);
|
||||||
|
|
||||||
|
/*
|
||||||
|
choice of padding added after fips, so not available when using fips RSA
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Mask Generation Function Identifiers */
|
||||||
|
#define WC_MGF1NONE 0
|
||||||
|
#define WC_MGF1SHA1 26
|
||||||
|
#define WC_MGF1SHA224 4
|
||||||
|
#define WC_MGF1SHA256 1
|
||||||
|
#define WC_MGF1SHA384 2
|
||||||
|
#define WC_MGF1SHA512 3
|
||||||
|
|
||||||
|
/* Padding types */
|
||||||
|
#define WC_RSA_PKCSV15_PAD 0
|
||||||
|
#define WC_RSA_OAEP_PAD 1
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_RsaPublicEncrypt_ex(const byte* in, word32 inLen, byte* out,
|
||||||
|
word32 outLen, RsaKey* key, WC_RNG* rng, int type,
|
||||||
|
enum wc_HashType hash, int mgf, byte* label, word32 lableSz);
|
||||||
|
WOLFSSL_API int wc_RsaPrivateDecrypt_ex(const byte* in, word32 inLen,
|
||||||
|
byte* out, word32 outLen, RsaKey* key, int type,
|
||||||
|
enum wc_HashType hash, int mgf, byte* label, word32 lableSz);
|
||||||
|
WOLFSSL_API int wc_RsaPrivateDecryptInline_ex(byte* in, word32 inLen,
|
||||||
|
byte** out, RsaKey* key, int type, enum wc_HashType hash,
|
||||||
|
int mgf, byte* label, word32 lableSz);
|
||||||
|
#endif /* HAVE_FIPS*/
|
||||||
|
WOLFSSL_API int wc_RsaFlattenPublicKey(RsaKey*, byte*, word32*, byte*,
|
||||||
|
word32*);
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_KEY_GEN
|
||||||
|
WOLFSSL_API int wc_RsaKeyToPublicDer(RsaKey*, byte* output, word32 inLen);
|
||||||
|
WOLFSSL_API int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
WOLFSSL_API int wc_RsaAsyncHandle(RsaKey* key, WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event);
|
||||||
|
WOLFSSL_API int wc_RsaAsyncWait(int ret, RsaKey* key);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAVE_USER_RSA */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* NO_RSA */
|
||||||
|
#endif /* WOLF_CRYPT_RSA_H */
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,95 @@
|
||||||
|
/* sha.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_SHA_H
|
||||||
|
#define WOLF_CRYPT_SHA_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifndef NO_SHA
|
||||||
|
|
||||||
|
#ifdef HAVE_FIPS
|
||||||
|
/* for fips @wc_fips */
|
||||||
|
#include <cyassl/ctaocrypt/sha.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef FREESCALE_LTC_SHA
|
||||||
|
#include "fsl_ltc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_FIPS /* avoid redefining structs */
|
||||||
|
/* in bytes */
|
||||||
|
enum {
|
||||||
|
#if defined(STM32F2_HASH) || defined(STM32F4_HASH)
|
||||||
|
SHA_REG_SIZE = 4, /* STM32 register size, bytes */
|
||||||
|
#endif
|
||||||
|
SHA = 1, /* hash type unique */
|
||||||
|
SHA_BLOCK_SIZE = 64,
|
||||||
|
SHA_DIGEST_SIZE = 20,
|
||||||
|
SHA_PAD_SIZE = 56
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_PIC32MZ_HASH
|
||||||
|
#include "port/pic32/pic32mz-crypt.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_TI_HASH
|
||||||
|
|
||||||
|
/* Sha digest */
|
||||||
|
typedef struct Sha {
|
||||||
|
#ifdef FREESCALE_LTC_SHA
|
||||||
|
ltc_hash_ctx_t ctx;
|
||||||
|
#else
|
||||||
|
word32 buffLen; /* in bytes */
|
||||||
|
word32 loLen; /* length in bytes */
|
||||||
|
word32 hiLen; /* length in bytes */
|
||||||
|
word32 buffer[SHA_BLOCK_SIZE / sizeof(word32)];
|
||||||
|
#ifndef WOLFSSL_PIC32MZ_HASH
|
||||||
|
word32 digest[SHA_DIGEST_SIZE / sizeof(word32)];
|
||||||
|
#else
|
||||||
|
word32 digest[PIC32_HASH_SIZE / sizeof(word32)];
|
||||||
|
pic32mz_desc desc; /* Crypt Engine descriptor */
|
||||||
|
#endif
|
||||||
|
#endif /* FREESCALE_LTC_SHA */
|
||||||
|
} Sha;
|
||||||
|
|
||||||
|
#else /* WOLFSSL_TI_HASH */
|
||||||
|
#include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAVE_FIPS */
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_InitSha(Sha*);
|
||||||
|
WOLFSSL_API int wc_ShaUpdate(Sha*, const byte*, word32);
|
||||||
|
WOLFSSL_API int wc_ShaFinal(Sha*, byte*);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* NO_SHA */
|
||||||
|
#endif /* WOLF_CRYPT_SHA_H */
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
/* sha256.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* code submitted by raphael.huck@efixo.com */
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_SHA256_H
|
||||||
|
#define WOLF_CRYPT_SHA256_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifndef NO_SHA256
|
||||||
|
|
||||||
|
#ifdef HAVE_FIPS
|
||||||
|
/* for fips @wc_fips */
|
||||||
|
#include <cyassl/ctaocrypt/sha256.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef FREESCALE_LTC_SHA
|
||||||
|
#include "fsl_ltc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_FIPS /* avoid redefinition of structs */
|
||||||
|
#ifdef WOLFSSL_PIC32MZ_HASH
|
||||||
|
#include "port/pic32/pic32mz-crypt.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* in bytes */
|
||||||
|
enum {
|
||||||
|
SHA256 = 2, /* hash type unique */
|
||||||
|
SHA256_BLOCK_SIZE = 64,
|
||||||
|
SHA256_DIGEST_SIZE = 32,
|
||||||
|
SHA256_PAD_SIZE = 56
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_TI_HASH
|
||||||
|
|
||||||
|
/* Sha256 digest */
|
||||||
|
typedef struct Sha256 {
|
||||||
|
#ifdef FREESCALE_LTC_SHA
|
||||||
|
ltc_hash_ctx_t ctx;
|
||||||
|
#else
|
||||||
|
word32 buffLen; /* in bytes */
|
||||||
|
word32 loLen; /* length in bytes */
|
||||||
|
word32 hiLen; /* length in bytes */
|
||||||
|
ALIGN16 word32 digest[SHA256_DIGEST_SIZE / sizeof(word32)];
|
||||||
|
ALIGN16 word32 buffer[SHA256_BLOCK_SIZE / sizeof(word32)];
|
||||||
|
#ifdef WOLFSSL_PIC32MZ_HASH
|
||||||
|
pic32mz_desc desc ; /* Crypt Engine descriptor */
|
||||||
|
#endif
|
||||||
|
#endif /* FREESCALE_LTC_SHA */
|
||||||
|
} Sha256;
|
||||||
|
|
||||||
|
#else /* WOLFSSL_TI_HASH */
|
||||||
|
#include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAVE_FIPS */
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_InitSha256(Sha256*);
|
||||||
|
WOLFSSL_API int wc_Sha256Update(Sha256*, const byte*, word32);
|
||||||
|
WOLFSSL_API int wc_Sha256Final(Sha256*, byte*);
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_SHA224
|
||||||
|
|
||||||
|
#ifndef HAVE_FIPS /* avoid redefinition of structs */
|
||||||
|
/* in bytes */
|
||||||
|
enum {
|
||||||
|
SHA224 = 8, /* hash type unique */
|
||||||
|
SHA224_BLOCK_SIZE = SHA256_BLOCK_SIZE,
|
||||||
|
SHA224_DIGEST_SIZE = 28,
|
||||||
|
SHA224_PAD_SIZE = SHA256_PAD_SIZE
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef Sha256 Sha224;
|
||||||
|
#endif /* HAVE_FIPS */
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_InitSha224(Sha224*);
|
||||||
|
WOLFSSL_API int wc_Sha224Update(Sha224*, const byte*, word32);
|
||||||
|
WOLFSSL_API int wc_Sha224Final(Sha224*, byte*);
|
||||||
|
|
||||||
|
#endif /* WOLFSSL_SHA224 */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* NO_SHA256 */
|
||||||
|
#endif /* WOLF_CRYPT_SHA256_H */
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
/* sha512.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_SHA512_H
|
||||||
|
#define WOLF_CRYPT_SHA512_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_SHA512
|
||||||
|
|
||||||
|
/* for fips @wc_fips */
|
||||||
|
#ifdef HAVE_FIPS
|
||||||
|
#define CYASSL_SHA512
|
||||||
|
#if defined(WOLFSSL_SHA384)
|
||||||
|
#define CYASSL_SHA384
|
||||||
|
#endif
|
||||||
|
#include <cyassl/ctaocrypt/sha512.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_FIPS /* avoid redefinition of structs */
|
||||||
|
|
||||||
|
/* in bytes */
|
||||||
|
enum {
|
||||||
|
SHA512 = 4, /* hash type unique */
|
||||||
|
SHA512_BLOCK_SIZE = 128,
|
||||||
|
SHA512_DIGEST_SIZE = 64,
|
||||||
|
SHA512_PAD_SIZE = 112
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Sha512 digest */
|
||||||
|
typedef struct Sha512 {
|
||||||
|
word32 buffLen; /* in bytes */
|
||||||
|
word64 loLen; /* length in bytes */
|
||||||
|
word64 hiLen; /* length in bytes */
|
||||||
|
word64 digest[SHA512_DIGEST_SIZE / sizeof(word64)];
|
||||||
|
word64 buffer[SHA512_BLOCK_SIZE / sizeof(word64)];
|
||||||
|
} Sha512;
|
||||||
|
|
||||||
|
#endif /* HAVE_FIPS */
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_InitSha512(Sha512*);
|
||||||
|
WOLFSSL_API int wc_Sha512Update(Sha512*, const byte*, word32);
|
||||||
|
WOLFSSL_API int wc_Sha512Final(Sha512*, byte*);
|
||||||
|
|
||||||
|
#if defined(WOLFSSL_SHA384)
|
||||||
|
|
||||||
|
#ifndef HAVE_FIPS /* avoid redefinition of structs */
|
||||||
|
/* in bytes */
|
||||||
|
enum {
|
||||||
|
SHA384 = 5, /* hash type unique */
|
||||||
|
SHA384_BLOCK_SIZE = SHA512_BLOCK_SIZE,
|
||||||
|
SHA384_DIGEST_SIZE = 48,
|
||||||
|
SHA384_PAD_SIZE = SHA512_PAD_SIZE
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef Sha512 Sha384;
|
||||||
|
#endif /* HAVE_FIPS */
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_InitSha384(Sha384*);
|
||||||
|
WOLFSSL_API int wc_Sha384Update(Sha384*, const byte*, word32);
|
||||||
|
WOLFSSL_API int wc_Sha384Final(Sha384*, byte*);
|
||||||
|
|
||||||
|
#endif /* WOLFSSL_SHA384 */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLFSSL_SHA512 */
|
||||||
|
#endif /* WOLF_CRYPT_SHA512_H */
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
/* signature.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_SIGNATURE_H
|
||||||
|
#define WOLF_CRYPT_SIGNATURE_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
#include <wolfssl/wolfcrypt/hash.h>
|
||||||
|
#include <wolfssl/wolfcrypt/random.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum wc_SignatureType {
|
||||||
|
WC_SIGNATURE_TYPE_NONE = 0,
|
||||||
|
WC_SIGNATURE_TYPE_ECC = 1,
|
||||||
|
WC_SIGNATURE_TYPE_RSA = 2,
|
||||||
|
WC_SIGNATURE_TYPE_RSA_W_ENC = 3, /* Adds DER header via wc_EncodeSignature */
|
||||||
|
};
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_SignatureGetSize(enum wc_SignatureType sig_type,
|
||||||
|
const void* key, word32 key_len);
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_SignatureVerify(
|
||||||
|
enum wc_HashType hash_type, enum wc_SignatureType sig_type,
|
||||||
|
const byte* data, word32 data_len,
|
||||||
|
const byte* sig, word32 sig_len,
|
||||||
|
const void* key, word32 key_len);
|
||||||
|
|
||||||
|
WOLFSSL_API int wc_SignatureGenerate(
|
||||||
|
enum wc_HashType hash_type, enum wc_SignatureType sig_type,
|
||||||
|
const byte* data, word32 data_len,
|
||||||
|
byte* sig, word32 *sig_len,
|
||||||
|
const void* key, word32 key_len,
|
||||||
|
WC_RNG* rng);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLF_CRYPT_SIGNATURE_H */
|
|
@ -0,0 +1,304 @@
|
||||||
|
/* srp.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WOLFCRYPT_HAVE_SRP
|
||||||
|
|
||||||
|
#ifndef WOLFCRYPT_SRP_H
|
||||||
|
#define WOLFCRYPT_SRP_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
#include <wolfssl/wolfcrypt/sha.h>
|
||||||
|
#include <wolfssl/wolfcrypt/sha256.h>
|
||||||
|
#include <wolfssl/wolfcrypt/sha512.h>
|
||||||
|
#include <wolfssl/wolfcrypt/integer.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Select the largest available hash for the buffer size. */
|
||||||
|
#if defined(WOLFSSL_SHA512)
|
||||||
|
#define SRP_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE
|
||||||
|
#elif defined(WOLFSSL_SHA384)
|
||||||
|
#define SRP_MAX_DIGEST_SIZE SHA384_DIGEST_SIZE
|
||||||
|
#elif !defined(NO_SHA256)
|
||||||
|
#define SRP_MAX_DIGEST_SIZE SHA256_DIGEST_SIZE
|
||||||
|
#elif !defined(NO_SHA)
|
||||||
|
#define SRP_MAX_DIGEST_SIZE SHA_DIGEST_SIZE
|
||||||
|
#else
|
||||||
|
#error "You have to have some kind of SHA hash if you want to use SRP."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Set the minimum number of bits acceptable in an SRP modulus */
|
||||||
|
#define SRP_MODULUS_MIN_BITS 512
|
||||||
|
|
||||||
|
/* Set the minimum number of bits acceptable for private keys (RFC 5054) */
|
||||||
|
#define SRP_PRIVATE_KEY_MIN_BITS 256
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SRP side, client or server.
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
SRP_CLIENT_SIDE = 0,
|
||||||
|
SRP_SERVER_SIDE = 1,
|
||||||
|
} SrpSide;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SRP hash type, SHA[1|256|384|512].
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
SRP_TYPE_SHA = 1,
|
||||||
|
SRP_TYPE_SHA256 = 2,
|
||||||
|
SRP_TYPE_SHA384 = 3,
|
||||||
|
SRP_TYPE_SHA512 = 4,
|
||||||
|
} SrpType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SRP hash struct.
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
byte type;
|
||||||
|
union {
|
||||||
|
#ifndef NO_SHA
|
||||||
|
Sha sha;
|
||||||
|
#endif
|
||||||
|
#ifndef NO_SHA256
|
||||||
|
Sha256 sha256;
|
||||||
|
#endif
|
||||||
|
#ifdef WOLFSSL_SHA384
|
||||||
|
Sha384 sha384;
|
||||||
|
#endif
|
||||||
|
#ifdef WOLFSSL_SHA512
|
||||||
|
Sha512 sha512;
|
||||||
|
#endif
|
||||||
|
} data;
|
||||||
|
} SrpHash;
|
||||||
|
|
||||||
|
typedef struct Srp {
|
||||||
|
SrpSide side; /**< Client or Server, @see SrpSide. */
|
||||||
|
SrpType type; /**< Hash type, @see SrpType. */
|
||||||
|
byte* user; /**< Username, login. */
|
||||||
|
word32 userSz; /**< Username length. */
|
||||||
|
byte* salt; /**< Small salt. */
|
||||||
|
word32 saltSz; /**< Salt length. */
|
||||||
|
mp_int N; /**< Modulus. N = 2q+1, [q, N] are primes.*/
|
||||||
|
mp_int g; /**< Generator. A generator modulo N. */
|
||||||
|
byte k[SRP_MAX_DIGEST_SIZE]; /**< Multiplier parameter. k = H(N, g) */
|
||||||
|
mp_int auth; /**< Client: x = H(salt + H(user:pswd)) */
|
||||||
|
/**< Server: v = g ^ x % N */
|
||||||
|
mp_int priv; /**< Private ephemeral value. */
|
||||||
|
SrpHash client_proof; /**< Client proof. Sent to the Server. */
|
||||||
|
SrpHash server_proof; /**< Server proof. Sent to the Client. */
|
||||||
|
byte* key; /**< Session key. */
|
||||||
|
word32 keySz; /**< Session key length. */
|
||||||
|
int (*keyGenFunc_cb) (struct Srp* srp, byte* secret, word32 size);
|
||||||
|
/**< Function responsible for generating the session key. */
|
||||||
|
/**< It MUST use XMALLOC with type DYNAMIC_TYPE_SRP to allocate the */
|
||||||
|
/**< key buffer for this structure and set keySz to the buffer size. */
|
||||||
|
/**< The default function used by this implementation is a modified */
|
||||||
|
/**< version of t_mgf1 that uses the proper hash function according */
|
||||||
|
/**< to srp->type. */
|
||||||
|
void* heap; /**< heap hint pointer */
|
||||||
|
} Srp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the Srp struct for usage.
|
||||||
|
*
|
||||||
|
* @param[out] srp the Srp structure to be initialized.
|
||||||
|
* @param[in] type the hash type to be used.
|
||||||
|
* @param[in] side the side of the communication.
|
||||||
|
*
|
||||||
|
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
|
||||||
|
*/
|
||||||
|
WOLFSSL_API int wc_SrpInit(Srp* srp, SrpType type, SrpSide side);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Releases the Srp struct resources after usage.
|
||||||
|
*
|
||||||
|
* @param[in,out] srp the Srp structure to be terminated.
|
||||||
|
*/
|
||||||
|
WOLFSSL_API void wc_SrpTerm(Srp* srp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the username.
|
||||||
|
*
|
||||||
|
* This function MUST be called after wc_SrpInit.
|
||||||
|
*
|
||||||
|
* @param[in,out] srp the Srp structure.
|
||||||
|
* @param[in] username the buffer containing the username.
|
||||||
|
* @param[in] size the username size in bytes
|
||||||
|
*
|
||||||
|
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
|
||||||
|
*/
|
||||||
|
WOLFSSL_API int wc_SrpSetUsername(Srp* srp, const byte* username, word32 size);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the srp parameters based on the username.
|
||||||
|
*
|
||||||
|
* This function MUST be called after wc_SrpSetUsername.
|
||||||
|
*
|
||||||
|
* @param[in,out] srp the Srp structure.
|
||||||
|
* @param[in] N the Modulus. N = 2q+1, [q, N] are primes.
|
||||||
|
* @param[in] nSz the N size in bytes.
|
||||||
|
* @param[in] g the Generator modulo N.
|
||||||
|
* @param[in] gSz the g size in bytes
|
||||||
|
* @param[in] salt a small random salt. Specific for each username.
|
||||||
|
* @param[in] saltSz the salt size in bytes
|
||||||
|
*
|
||||||
|
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
|
||||||
|
*/
|
||||||
|
WOLFSSL_API int wc_SrpSetParams(Srp* srp, const byte* N, word32 nSz,
|
||||||
|
const byte* g, word32 gSz,
|
||||||
|
const byte* salt, word32 saltSz);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the password.
|
||||||
|
*
|
||||||
|
* Setting the password does not persists the clear password data in the
|
||||||
|
* srp structure. The client calculates x = H(salt + H(user:pswd)) and stores
|
||||||
|
* it in the auth field.
|
||||||
|
*
|
||||||
|
* This function MUST be called after wc_SrpSetParams and is CLIENT SIDE ONLY.
|
||||||
|
*
|
||||||
|
* @param[in,out] srp the Srp structure.
|
||||||
|
* @param[in] password the buffer containing the password.
|
||||||
|
* @param[in] size the password size in bytes.
|
||||||
|
*
|
||||||
|
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
|
||||||
|
*/
|
||||||
|
WOLFSSL_API int wc_SrpSetPassword(Srp* srp, const byte* password, word32 size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the verifier.
|
||||||
|
*
|
||||||
|
* This function MUST be called after wc_SrpSetParams and is SERVER SIDE ONLY.
|
||||||
|
*
|
||||||
|
* @param[in,out] srp the Srp structure.
|
||||||
|
* @param[in] verifier the buffer containing the verifier.
|
||||||
|
* @param[in] size the verifier size in bytes.
|
||||||
|
*
|
||||||
|
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
|
||||||
|
*/
|
||||||
|
WOLFSSL_API int wc_SrpSetVerifier(Srp* srp, const byte* verifier, word32 size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the verifier.
|
||||||
|
*
|
||||||
|
* The client calculates the verifier with v = g ^ x % N.
|
||||||
|
* This function MAY be called after wc_SrpSetPassword and is CLIENT SIDE ONLY.
|
||||||
|
*
|
||||||
|
* @param[in,out] srp the Srp structure.
|
||||||
|
* @param[out] verifier the buffer to write the verifier.
|
||||||
|
* @param[in,out] size the buffer size in bytes. Will be updated with the
|
||||||
|
* verifier size.
|
||||||
|
*
|
||||||
|
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
|
||||||
|
*/
|
||||||
|
WOLFSSL_API int wc_SrpGetVerifier(Srp* srp, byte* verifier, word32* size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the private ephemeral value.
|
||||||
|
*
|
||||||
|
* The private ephemeral value is known as:
|
||||||
|
* a at the client side. a = random()
|
||||||
|
* b at the server side. b = random()
|
||||||
|
* This function is handy for unit test cases or if the developer wants to use
|
||||||
|
* an external random source to set the ephemeral value.
|
||||||
|
* This function MAY be called before wc_SrpGetPublic.
|
||||||
|
*
|
||||||
|
* @param[in,out] srp the Srp structure.
|
||||||
|
* @param[in] priv the ephemeral value.
|
||||||
|
* @param[in] size the private size in bytes.
|
||||||
|
*
|
||||||
|
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
|
||||||
|
*/
|
||||||
|
WOLFSSL_API int wc_SrpSetPrivate(Srp* srp, const byte* priv, word32 size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the public ephemeral value.
|
||||||
|
*
|
||||||
|
* The public ephemeral value is known as:
|
||||||
|
* A at the client side. A = g ^ a % N
|
||||||
|
* B at the server side. B = (k * v + (g ˆ b % N)) % N
|
||||||
|
* This function MUST be called after wc_SrpSetPassword or wc_SrpSetVerifier.
|
||||||
|
*
|
||||||
|
* @param[in,out] srp the Srp structure.
|
||||||
|
* @param[out] pub the buffer to write the public ephemeral value.
|
||||||
|
* @param[in,out] size the the buffer size in bytes. Will be updated with
|
||||||
|
* the ephemeral value size.
|
||||||
|
*
|
||||||
|
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
|
||||||
|
*/
|
||||||
|
WOLFSSL_API int wc_SrpGetPublic(Srp* srp, byte* pub, word32* size);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes the session key.
|
||||||
|
*
|
||||||
|
* The key can be accessed at srp->key after success.
|
||||||
|
*
|
||||||
|
* @param[in,out] srp the Srp structure.
|
||||||
|
* @param[in] clientPubKey the client's public ephemeral value.
|
||||||
|
* @param[in] clientPubKeySz the client's public ephemeral value size.
|
||||||
|
* @param[in] serverPubKey the server's public ephemeral value.
|
||||||
|
* @param[in] serverPubKeySz the server's public ephemeral value size.
|
||||||
|
*
|
||||||
|
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
|
||||||
|
*/
|
||||||
|
WOLFSSL_API int wc_SrpComputeKey(Srp* srp,
|
||||||
|
byte* clientPubKey, word32 clientPubKeySz,
|
||||||
|
byte* serverPubKey, word32 serverPubKeySz);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the proof.
|
||||||
|
*
|
||||||
|
* This function MUST be called after wc_SrpComputeKey.
|
||||||
|
*
|
||||||
|
* @param[in,out] srp the Srp structure.
|
||||||
|
* @param[out] proof the buffer to write the proof.
|
||||||
|
* @param[in,out] size the buffer size in bytes. Will be updated with the
|
||||||
|
* proof size.
|
||||||
|
*
|
||||||
|
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
|
||||||
|
*/
|
||||||
|
WOLFSSL_API int wc_SrpGetProof(Srp* srp, byte* proof, word32* size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies the peers proof.
|
||||||
|
*
|
||||||
|
* This function MUST be called before wc_SrpGetSessionKey.
|
||||||
|
*
|
||||||
|
* @param[in,out] srp the Srp structure.
|
||||||
|
* @param[in] proof the peers proof.
|
||||||
|
* @param[in] size the proof size in bytes.
|
||||||
|
*
|
||||||
|
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
|
||||||
|
*/
|
||||||
|
WOLFSSL_API int wc_SrpVerifyPeersProof(Srp* srp, byte* proof, word32 size);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLFCRYPT_SRP_H */
|
||||||
|
#endif /* WOLFCRYPT_HAVE_SRP */
|
|
@ -0,0 +1,711 @@
|
||||||
|
/* tfm.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Based on public domain TomsFastMath 0.10 by Tom St Denis, tomstdenis@iahu.ca,
|
||||||
|
* http://math.libtomcrypt.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edited by Moisés Guimarães (moises.guimaraes@phoebus.com.br)
|
||||||
|
* to fit CyaSSL's needs.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_TFM_H
|
||||||
|
#define WOLF_CRYPT_TFM_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
#ifndef CHAR_BIT
|
||||||
|
#include <limits.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/random.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MIN
|
||||||
|
#define MIN(x,y) ((x)<(y)?(x):(y))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAX
|
||||||
|
#define MAX(x,y) ((x)>(y)?(x):(y))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef NO_64BIT
|
||||||
|
/* autodetect x86-64 and make sure we are using 64-bit digits with x86-64 asm */
|
||||||
|
#if defined(__x86_64__)
|
||||||
|
#if defined(TFM_X86) || defined(TFM_SSE2) || defined(TFM_ARM)
|
||||||
|
#error x86-64 detected, x86-32/SSE2/ARM optimizations are not valid!
|
||||||
|
#endif
|
||||||
|
#if !defined(TFM_X86_64) && !defined(TFM_NO_ASM)
|
||||||
|
#define TFM_X86_64
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#if defined(TFM_X86_64)
|
||||||
|
#if !defined(FP_64BIT)
|
||||||
|
#define FP_64BIT
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
/* use 64-bit digit even if not using asm on x86_64 */
|
||||||
|
#if defined(__x86_64__) && !defined(FP_64BIT)
|
||||||
|
#define FP_64BIT
|
||||||
|
#endif
|
||||||
|
/* if intel compiler doesn't provide 128 bit type don't turn on 64bit */
|
||||||
|
#if defined(FP_64BIT) && defined(__INTEL_COMPILER) && !defined(HAVE___UINT128_T)
|
||||||
|
#undef FP_64BIT
|
||||||
|
#undef TFM_X86_64
|
||||||
|
#endif
|
||||||
|
#endif /* NO_64BIT */
|
||||||
|
|
||||||
|
/* try to detect x86-32 */
|
||||||
|
#if defined(__i386__) && !defined(TFM_SSE2)
|
||||||
|
#if defined(TFM_X86_64) || defined(TFM_ARM)
|
||||||
|
#error x86-32 detected, x86-64/ARM optimizations are not valid!
|
||||||
|
#endif
|
||||||
|
#if !defined(TFM_X86) && !defined(TFM_NO_ASM)
|
||||||
|
#define TFM_X86
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* make sure we're 32-bit for x86-32/sse/arm/ppc32 */
|
||||||
|
#if (defined(TFM_X86) || defined(TFM_SSE2) || defined(TFM_ARM) || defined(TFM_PPC32)) && defined(FP_64BIT)
|
||||||
|
#warning x86-32, SSE2 and ARM, PPC32 optimizations require 32-bit digits (undefining)
|
||||||
|
#undef FP_64BIT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* multi asms? */
|
||||||
|
#ifdef TFM_X86
|
||||||
|
#define TFM_ASM
|
||||||
|
#endif
|
||||||
|
#ifdef TFM_X86_64
|
||||||
|
#ifdef TFM_ASM
|
||||||
|
#error TFM_ASM already defined!
|
||||||
|
#endif
|
||||||
|
#define TFM_ASM
|
||||||
|
#endif
|
||||||
|
#ifdef TFM_SSE2
|
||||||
|
#ifdef TFM_ASM
|
||||||
|
#error TFM_ASM already defined!
|
||||||
|
#endif
|
||||||
|
#define TFM_ASM
|
||||||
|
#endif
|
||||||
|
#ifdef TFM_ARM
|
||||||
|
#ifdef TFM_ASM
|
||||||
|
#error TFM_ASM already defined!
|
||||||
|
#endif
|
||||||
|
#define TFM_ASM
|
||||||
|
#endif
|
||||||
|
#ifdef TFM_PPC32
|
||||||
|
#ifdef TFM_ASM
|
||||||
|
#error TFM_ASM already defined!
|
||||||
|
#endif
|
||||||
|
#define TFM_ASM
|
||||||
|
#endif
|
||||||
|
#ifdef TFM_PPC64
|
||||||
|
#ifdef TFM_ASM
|
||||||
|
#error TFM_ASM already defined!
|
||||||
|
#endif
|
||||||
|
#define TFM_ASM
|
||||||
|
#endif
|
||||||
|
#ifdef TFM_AVR32
|
||||||
|
#ifdef TFM_ASM
|
||||||
|
#error TFM_ASM already defined!
|
||||||
|
#endif
|
||||||
|
#define TFM_ASM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* we want no asm? */
|
||||||
|
#ifdef TFM_NO_ASM
|
||||||
|
#undef TFM_X86
|
||||||
|
#undef TFM_X86_64
|
||||||
|
#undef TFM_SSE2
|
||||||
|
#undef TFM_ARM
|
||||||
|
#undef TFM_PPC32
|
||||||
|
#undef TFM_PPC64
|
||||||
|
#undef TFM_AVR32
|
||||||
|
#undef TFM_ASM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ECC helpers */
|
||||||
|
#ifdef TFM_ECC192
|
||||||
|
#ifdef FP_64BIT
|
||||||
|
#define TFM_MUL3
|
||||||
|
#define TFM_SQR3
|
||||||
|
#else
|
||||||
|
#define TFM_MUL6
|
||||||
|
#define TFM_SQR6
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TFM_ECC224
|
||||||
|
#ifdef FP_64BIT
|
||||||
|
#define TFM_MUL4
|
||||||
|
#define TFM_SQR4
|
||||||
|
#else
|
||||||
|
#define TFM_MUL7
|
||||||
|
#define TFM_SQR7
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TFM_ECC256
|
||||||
|
#ifdef FP_64BIT
|
||||||
|
#define TFM_MUL4
|
||||||
|
#define TFM_SQR4
|
||||||
|
#else
|
||||||
|
#define TFM_MUL8
|
||||||
|
#define TFM_SQR8
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TFM_ECC384
|
||||||
|
#ifdef FP_64BIT
|
||||||
|
#define TFM_MUL6
|
||||||
|
#define TFM_SQR6
|
||||||
|
#else
|
||||||
|
#define TFM_MUL12
|
||||||
|
#define TFM_SQR12
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TFM_ECC521
|
||||||
|
#ifdef FP_64BIT
|
||||||
|
#define TFM_MUL9
|
||||||
|
#define TFM_SQR9
|
||||||
|
#else
|
||||||
|
#define TFM_MUL17
|
||||||
|
#define TFM_SQR17
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* allow user to define on fp_digit, fp_word types */
|
||||||
|
#ifndef WOLFSSL_BIGINT_TYPES
|
||||||
|
|
||||||
|
/* some default configurations.
|
||||||
|
*/
|
||||||
|
#if defined(FP_64BIT)
|
||||||
|
/* for GCC only on supported platforms */
|
||||||
|
typedef unsigned long long fp_digit; /* 64bit, 128 uses mode(TI) below */
|
||||||
|
#define SIZEOF_FP_DIGIT 8
|
||||||
|
typedef unsigned long fp_word __attribute__ ((mode(TI)));
|
||||||
|
#else
|
||||||
|
|
||||||
|
#ifndef NO_64BIT
|
||||||
|
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||||
|
typedef unsigned __int64 ulong64;
|
||||||
|
#else
|
||||||
|
typedef unsigned long long ulong64;
|
||||||
|
#endif
|
||||||
|
typedef unsigned int fp_digit;
|
||||||
|
#define SIZEOF_FP_DIGIT 4
|
||||||
|
typedef ulong64 fp_word;
|
||||||
|
#define FP_32BIT
|
||||||
|
#else
|
||||||
|
/* some procs like coldfire prefer not to place multiply into 64bit type
|
||||||
|
even though it exists */
|
||||||
|
typedef unsigned short fp_digit;
|
||||||
|
#define SIZEOF_FP_DIGIT 2
|
||||||
|
typedef unsigned int fp_word;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLFSSL_BIGINT_TYPES */
|
||||||
|
|
||||||
|
/* # of digits this is */
|
||||||
|
#define DIGIT_BIT ((CHAR_BIT) * SIZEOF_FP_DIGIT)
|
||||||
|
|
||||||
|
/* Max size of any number in bits. Basically the largest size you will be
|
||||||
|
* multiplying should be half [or smaller] of FP_MAX_SIZE-four_digit
|
||||||
|
*
|
||||||
|
* It defaults to 4096-bits [allowing multiplications up to 2048x2048 bits ]
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef FP_MAX_BITS
|
||||||
|
#define FP_MAX_BITS 4096
|
||||||
|
#endif
|
||||||
|
#define FP_MAX_SIZE (FP_MAX_BITS+(8*DIGIT_BIT))
|
||||||
|
|
||||||
|
/* will this lib work? */
|
||||||
|
#if (CHAR_BIT & 7)
|
||||||
|
#error CHAR_BIT must be a multiple of eight.
|
||||||
|
#endif
|
||||||
|
#if FP_MAX_BITS % CHAR_BIT
|
||||||
|
#error FP_MAX_BITS must be a multiple of CHAR_BIT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define FP_MASK (fp_digit)(-1)
|
||||||
|
#define FP_SIZE (FP_MAX_SIZE/DIGIT_BIT)
|
||||||
|
|
||||||
|
/* signs */
|
||||||
|
#define FP_ZPOS 0
|
||||||
|
#define FP_NEG 1
|
||||||
|
|
||||||
|
/* return codes */
|
||||||
|
#define FP_OKAY 0
|
||||||
|
#define FP_VAL -1
|
||||||
|
#define FP_MEM -2
|
||||||
|
#define FP_NOT_INF -3
|
||||||
|
|
||||||
|
/* equalities */
|
||||||
|
#define FP_LT -1 /* less than */
|
||||||
|
#define FP_EQ 0 /* equal to */
|
||||||
|
#define FP_GT 1 /* greater than */
|
||||||
|
|
||||||
|
/* replies */
|
||||||
|
#define FP_YES 1 /* yes response */
|
||||||
|
#define FP_NO 0 /* no response */
|
||||||
|
|
||||||
|
/* a FP type */
|
||||||
|
typedef struct {
|
||||||
|
int used,
|
||||||
|
sign;
|
||||||
|
#ifdef ALT_ECC_SIZE
|
||||||
|
int size;
|
||||||
|
#endif
|
||||||
|
fp_digit dp[FP_SIZE];
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
byte *dpraw; /* Used for hardware crypto */
|
||||||
|
#endif
|
||||||
|
} fp_int;
|
||||||
|
|
||||||
|
/* externally define this symbol to ignore the default settings, useful for changing the build from the make process */
|
||||||
|
#ifndef TFM_ALREADY_SET
|
||||||
|
|
||||||
|
/* do we want the large set of small multiplications ?
|
||||||
|
Enable these if you are going to be doing a lot of small (<= 16 digit) multiplications say in ECC
|
||||||
|
Or if you're on a 64-bit machine doing RSA as a 1024-bit integer == 16 digits ;-)
|
||||||
|
*/
|
||||||
|
/* need to refactor the function */
|
||||||
|
/*#define TFM_SMALL_SET */
|
||||||
|
|
||||||
|
/* do we want huge code
|
||||||
|
Enable these if you are doing 20, 24, 28, 32, 48, 64 digit multiplications (useful for RSA)
|
||||||
|
Less important on 64-bit machines as 32 digits == 2048 bits
|
||||||
|
*/
|
||||||
|
#if 0
|
||||||
|
#define TFM_MUL3
|
||||||
|
#define TFM_MUL4
|
||||||
|
#define TFM_MUL6
|
||||||
|
#define TFM_MUL7
|
||||||
|
#define TFM_MUL8
|
||||||
|
#define TFM_MUL9
|
||||||
|
#define TFM_MUL12
|
||||||
|
#define TFM_MUL17
|
||||||
|
#endif
|
||||||
|
#ifdef TFM_HUGE_SET
|
||||||
|
#define TFM_MUL20
|
||||||
|
#define TFM_MUL24
|
||||||
|
#define TFM_MUL28
|
||||||
|
#define TFM_MUL32
|
||||||
|
#if (FP_MAX_BITS >= 6144) && defined(FP_64BIT)
|
||||||
|
#define TFM_MUL48
|
||||||
|
#endif
|
||||||
|
#if (FP_MAX_BITS >= 8192) && defined(FP_64BIT)
|
||||||
|
#define TFM_MUL64
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#define TFM_SQR3
|
||||||
|
#define TFM_SQR4
|
||||||
|
#define TFM_SQR6
|
||||||
|
#define TFM_SQR7
|
||||||
|
#define TFM_SQR8
|
||||||
|
#define TFM_SQR9
|
||||||
|
#define TFM_SQR12
|
||||||
|
#define TFM_SQR17
|
||||||
|
#endif
|
||||||
|
#ifdef TFM_HUGE_SET
|
||||||
|
#define TFM_SQR20
|
||||||
|
#define TFM_SQR24
|
||||||
|
#define TFM_SQR28
|
||||||
|
#define TFM_SQR32
|
||||||
|
#define TFM_SQR48
|
||||||
|
#define TFM_SQR64
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Optional math checks (enable WOLFSSL_DEBUG_MATH to print info) */
|
||||||
|
/* #define TFM_CHECK */
|
||||||
|
|
||||||
|
/* Is the target a P4 Prescott
|
||||||
|
*/
|
||||||
|
/* #define TFM_PRESCOTT */
|
||||||
|
|
||||||
|
/* Do we want timing resistant fp_exptmod() ?
|
||||||
|
* This makes it slower but also timing invariant with respect to the exponent
|
||||||
|
*/
|
||||||
|
/* #define TFM_TIMING_RESISTANT */
|
||||||
|
|
||||||
|
#endif /* TFM_ALREADY_SET */
|
||||||
|
|
||||||
|
/* functions */
|
||||||
|
|
||||||
|
/* returns a TFM ident string useful for debugging... */
|
||||||
|
/*const char *fp_ident(void);*/
|
||||||
|
|
||||||
|
/* initialize [or zero] an fp int */
|
||||||
|
#ifdef ALT_ECC_SIZE
|
||||||
|
void fp_init(fp_int *a);
|
||||||
|
void fp_zero(fp_int *a);
|
||||||
|
void fp_clear(fp_int *a); /* uses ForceZero to clear sensitive memory */
|
||||||
|
#else
|
||||||
|
#define fp_init(a) (void)XMEMSET((a), 0, sizeof(fp_int))
|
||||||
|
#define fp_zero(a) fp_init(a)
|
||||||
|
#define fp_clear(a) ForceZero((a), sizeof(fp_int));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* zero/even/odd ? */
|
||||||
|
#define fp_iszero(a) (((a)->used == 0) ? FP_YES : FP_NO)
|
||||||
|
#define fp_isone(a) \
|
||||||
|
((((a)->used == 1) && ((a)->dp[0] == 1)) ? FP_YES : FP_NO)
|
||||||
|
#define fp_iseven(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 0)) ? FP_YES : FP_NO)
|
||||||
|
#define fp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? FP_YES : FP_NO)
|
||||||
|
#define fp_isneg(a) (((a)->sign != 0) ? FP_YES : FP_NO)
|
||||||
|
|
||||||
|
/* set to a small digit */
|
||||||
|
void fp_set(fp_int *a, fp_digit b);
|
||||||
|
|
||||||
|
/* check if a bit is set */
|
||||||
|
int fp_is_bit_set(fp_int *a, fp_digit b);
|
||||||
|
/* set the b bit to 1 */
|
||||||
|
int fp_set_bit (fp_int * a, fp_digit b);
|
||||||
|
|
||||||
|
/* copy from a to b */
|
||||||
|
#ifndef ALT_ECC_SIZE
|
||||||
|
#define fp_copy(a, b) (void)(((a) != (b)) ? ((void)XMEMCPY((b), (a), sizeof(fp_int))) : (void)0)
|
||||||
|
#define fp_init_copy(a, b) fp_copy(b, a)
|
||||||
|
#else
|
||||||
|
void fp_copy(fp_int *a, fp_int *b);
|
||||||
|
void fp_init_copy(fp_int *a, fp_int *b);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* clamp digits */
|
||||||
|
#define fp_clamp(a) { while ((a)->used && (a)->dp[(a)->used-1] == 0) --((a)->used); (a)->sign = (a)->used ? (a)->sign : FP_ZPOS; }
|
||||||
|
|
||||||
|
/* negate and absolute */
|
||||||
|
#define fp_neg(a, b) { fp_copy(a, b); (b)->sign ^= 1; fp_clamp(b); }
|
||||||
|
#define fp_abs(a, b) { fp_copy(a, b); (b)->sign = 0; }
|
||||||
|
|
||||||
|
/* right shift x digits */
|
||||||
|
void fp_rshd(fp_int *a, int x);
|
||||||
|
|
||||||
|
/* right shift x bits */
|
||||||
|
void fp_rshb(fp_int *a, int x);
|
||||||
|
|
||||||
|
/* left shift x digits */
|
||||||
|
void fp_lshd(fp_int *a, int x);
|
||||||
|
|
||||||
|
/* signed comparison */
|
||||||
|
int fp_cmp(fp_int *a, fp_int *b);
|
||||||
|
|
||||||
|
/* unsigned comparison */
|
||||||
|
int fp_cmp_mag(fp_int *a, fp_int *b);
|
||||||
|
|
||||||
|
/* power of 2 operations */
|
||||||
|
void fp_div_2d(fp_int *a, int b, fp_int *c, fp_int *d);
|
||||||
|
void fp_mod_2d(fp_int *a, int b, fp_int *c);
|
||||||
|
void fp_mul_2d(fp_int *a, int b, fp_int *c);
|
||||||
|
void fp_2expt (fp_int *a, int b);
|
||||||
|
void fp_mul_2(fp_int *a, fp_int *c);
|
||||||
|
void fp_div_2(fp_int *a, fp_int *c);
|
||||||
|
|
||||||
|
/* Counts the number of lsbs which are zero before the first zero bit */
|
||||||
|
int fp_cnt_lsb(fp_int *a);
|
||||||
|
|
||||||
|
/* c = a + b */
|
||||||
|
void fp_add(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
|
||||||
|
/* c = a - b */
|
||||||
|
void fp_sub(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
|
||||||
|
/* c = a * b */
|
||||||
|
void fp_mul(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
|
||||||
|
/* b = a*a */
|
||||||
|
void fp_sqr(fp_int *a, fp_int *b);
|
||||||
|
|
||||||
|
/* a/b => cb + d == a */
|
||||||
|
int fp_div(fp_int *a, fp_int *b, fp_int *c, fp_int *d);
|
||||||
|
|
||||||
|
/* c = a mod b, 0 <= c < b */
|
||||||
|
int fp_mod(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
|
||||||
|
/* compare against a single digit */
|
||||||
|
int fp_cmp_d(fp_int *a, fp_digit b);
|
||||||
|
|
||||||
|
/* c = a + b */
|
||||||
|
void fp_add_d(fp_int *a, fp_digit b, fp_int *c);
|
||||||
|
|
||||||
|
/* c = a - b */
|
||||||
|
void fp_sub_d(fp_int *a, fp_digit b, fp_int *c);
|
||||||
|
|
||||||
|
/* c = a * b */
|
||||||
|
void fp_mul_d(fp_int *a, fp_digit b, fp_int *c);
|
||||||
|
|
||||||
|
/* a/b => cb + d == a */
|
||||||
|
/*int fp_div_d(fp_int *a, fp_digit b, fp_int *c, fp_digit *d);*/
|
||||||
|
|
||||||
|
/* c = a mod b, 0 <= c < b */
|
||||||
|
/*int fp_mod_d(fp_int *a, fp_digit b, fp_digit *c);*/
|
||||||
|
|
||||||
|
/* ---> number theory <--- */
|
||||||
|
/* d = a + b (mod c) */
|
||||||
|
/*int fp_addmod(fp_int *a, fp_int *b, fp_int *c, fp_int *d);*/
|
||||||
|
|
||||||
|
/* d = a - b (mod c) */
|
||||||
|
/*int fp_submod(fp_int *a, fp_int *b, fp_int *c, fp_int *d);*/
|
||||||
|
|
||||||
|
/* d = a * b (mod c) */
|
||||||
|
int fp_mulmod(fp_int *a, fp_int *b, fp_int *c, fp_int *d);
|
||||||
|
|
||||||
|
/* d = a - b (mod c) */
|
||||||
|
int fp_submod(fp_int *a, fp_int *b, fp_int *c, fp_int *d);
|
||||||
|
|
||||||
|
/* d = a + b (mod c) */
|
||||||
|
int fp_addmod(fp_int *a, fp_int *b, fp_int *c, fp_int *d);
|
||||||
|
|
||||||
|
/* c = a * a (mod b) */
|
||||||
|
int fp_sqrmod(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
|
||||||
|
/* c = 1/a (mod b) */
|
||||||
|
int fp_invmod(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
|
||||||
|
/* c = (a, b) */
|
||||||
|
/*void fp_gcd(fp_int *a, fp_int *b, fp_int *c);*/
|
||||||
|
|
||||||
|
/* c = [a, b] */
|
||||||
|
/*void fp_lcm(fp_int *a, fp_int *b, fp_int *c);*/
|
||||||
|
|
||||||
|
/* setups the montgomery reduction */
|
||||||
|
int fp_montgomery_setup(fp_int *a, fp_digit *mp);
|
||||||
|
|
||||||
|
/* computes a = B**n mod b without division or multiplication useful for
|
||||||
|
* normalizing numbers in a Montgomery system.
|
||||||
|
*/
|
||||||
|
void fp_montgomery_calc_normalization(fp_int *a, fp_int *b);
|
||||||
|
|
||||||
|
/* computes x/R == x (mod N) via Montgomery Reduction */
|
||||||
|
void fp_montgomery_reduce(fp_int *a, fp_int *m, fp_digit mp);
|
||||||
|
|
||||||
|
/* d = a**b (mod c) */
|
||||||
|
int fp_exptmod(fp_int *a, fp_int *b, fp_int *c, fp_int *d);
|
||||||
|
|
||||||
|
/* primality stuff */
|
||||||
|
|
||||||
|
/* perform a Miller-Rabin test of a to the base b and store result in "result" */
|
||||||
|
/*void fp_prime_miller_rabin (fp_int * a, fp_int * b, int *result);*/
|
||||||
|
|
||||||
|
#define FP_PRIME_SIZE 256
|
||||||
|
/* 256 trial divisions + 8 Miller-Rabins, returns FP_YES if probable prime */
|
||||||
|
/*int fp_isprime(fp_int *a);*/
|
||||||
|
/* extended version of fp_isprime, do 't' Miller-Rabins instead of only 8 */
|
||||||
|
/*int fp_isprime_ex(fp_int *a, int t);*/
|
||||||
|
|
||||||
|
/* Primality generation flags */
|
||||||
|
/*#define TFM_PRIME_BBS 0x0001 */ /* BBS style prime */
|
||||||
|
/*#define TFM_PRIME_SAFE 0x0002 */ /* Safe prime (p-1)/2 == prime */
|
||||||
|
/*#define TFM_PRIME_2MSB_OFF 0x0004 */ /* force 2nd MSB to 0 */
|
||||||
|
/*#define TFM_PRIME_2MSB_ON 0x0008 */ /* force 2nd MSB to 1 */
|
||||||
|
|
||||||
|
/* callback for fp_prime_random, should fill dst with random bytes and return how many read [up to len] */
|
||||||
|
/*typedef int tfm_prime_callback(unsigned char *dst, int len, void *dat);*/
|
||||||
|
|
||||||
|
/*#define fp_prime_random(a, t, size, bbs, cb, dat) fp_prime_random_ex(a, t, ((size) * 8) + 1, (bbs==1)?TFM_PRIME_BBS:0, cb, dat)*/
|
||||||
|
|
||||||
|
/*int fp_prime_random_ex(fp_int *a, int t, int size, int flags, tfm_prime_callback cb, void *dat);*/
|
||||||
|
|
||||||
|
/* radix conversions */
|
||||||
|
int fp_count_bits(fp_int *a);
|
||||||
|
int fp_leading_bit(fp_int *a);
|
||||||
|
|
||||||
|
int fp_unsigned_bin_size(fp_int *a);
|
||||||
|
void fp_read_unsigned_bin(fp_int *a, const unsigned char *b, int c);
|
||||||
|
void fp_to_unsigned_bin(fp_int *a, unsigned char *b);
|
||||||
|
int fp_to_unsigned_bin_at_pos(int x, fp_int *t, unsigned char *b);
|
||||||
|
|
||||||
|
/*int fp_signed_bin_size(fp_int *a);*/
|
||||||
|
/*void fp_read_signed_bin(fp_int *a, const unsigned char *b, int c);*/
|
||||||
|
/*void fp_to_signed_bin(fp_int *a, unsigned char *b);*/
|
||||||
|
|
||||||
|
/*int fp_read_radix(fp_int *a, char *str, int radix);*/
|
||||||
|
/*int fp_toradix(fp_int *a, char *str, int radix);*/
|
||||||
|
/*int fp_toradix_n(fp_int * a, char *str, int radix, int maxlen);*/
|
||||||
|
|
||||||
|
|
||||||
|
/* VARIOUS LOW LEVEL STUFFS */
|
||||||
|
void s_fp_add(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
void s_fp_sub(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
void fp_reverse(unsigned char *s, int len);
|
||||||
|
|
||||||
|
void fp_mul_comba(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
|
||||||
|
void fp_mul_comba_small(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
void fp_mul_comba3(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
void fp_mul_comba4(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
void fp_mul_comba6(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
void fp_mul_comba7(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
void fp_mul_comba8(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
void fp_mul_comba9(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
void fp_mul_comba12(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
void fp_mul_comba17(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
void fp_mul_comba20(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
void fp_mul_comba24(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
void fp_mul_comba28(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
void fp_mul_comba32(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
void fp_mul_comba48(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
void fp_mul_comba64(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
void fp_sqr_comba(fp_int *a, fp_int *b);
|
||||||
|
void fp_sqr_comba_small(fp_int *a, fp_int *b);
|
||||||
|
void fp_sqr_comba3(fp_int *a, fp_int *b);
|
||||||
|
void fp_sqr_comba4(fp_int *a, fp_int *b);
|
||||||
|
void fp_sqr_comba6(fp_int *a, fp_int *b);
|
||||||
|
void fp_sqr_comba7(fp_int *a, fp_int *b);
|
||||||
|
void fp_sqr_comba8(fp_int *a, fp_int *b);
|
||||||
|
void fp_sqr_comba9(fp_int *a, fp_int *b);
|
||||||
|
void fp_sqr_comba12(fp_int *a, fp_int *b);
|
||||||
|
void fp_sqr_comba17(fp_int *a, fp_int *b);
|
||||||
|
void fp_sqr_comba20(fp_int *a, fp_int *b);
|
||||||
|
void fp_sqr_comba24(fp_int *a, fp_int *b);
|
||||||
|
void fp_sqr_comba28(fp_int *a, fp_int *b);
|
||||||
|
void fp_sqr_comba32(fp_int *a, fp_int *b);
|
||||||
|
void fp_sqr_comba48(fp_int *a, fp_int *b);
|
||||||
|
void fp_sqr_comba64(fp_int *a, fp_int *b);
|
||||||
|
|
||||||
|
/*extern const char *fp_s_rmap;*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by wolfSSL
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Types */
|
||||||
|
typedef fp_digit mp_digit;
|
||||||
|
typedef fp_word mp_word;
|
||||||
|
typedef fp_int mp_int;
|
||||||
|
|
||||||
|
/* Constants */
|
||||||
|
#define MP_LT FP_LT /* less than */
|
||||||
|
#define MP_EQ FP_EQ /* equal to */
|
||||||
|
#define MP_GT FP_GT /* greater than */
|
||||||
|
#define MP_VAL FP_VAL /* invalid */
|
||||||
|
#define MP_MEM FP_MEM /* memory error */
|
||||||
|
#define MP_NOT_INF FP_NOT_INF /* point not at infinity */
|
||||||
|
#define MP_OKAY FP_OKAY /* ok result */
|
||||||
|
#define MP_NO FP_NO /* yes/no result */
|
||||||
|
#define MP_YES FP_YES /* yes/no result */
|
||||||
|
|
||||||
|
/* Prototypes */
|
||||||
|
#define mp_zero(a) fp_zero(a)
|
||||||
|
#define mp_isone(a) fp_isone(a)
|
||||||
|
#define mp_iseven(a) fp_iseven(a)
|
||||||
|
#define mp_isneg(a) fp_isneg(a)
|
||||||
|
int mp_init (mp_int * a);
|
||||||
|
void mp_clear (mp_int * a);
|
||||||
|
#define mp_forcezero(a) fp_clear(a)
|
||||||
|
int mp_init_multi(mp_int* a, mp_int* b, mp_int* c, mp_int* d, mp_int* e, mp_int* f);
|
||||||
|
|
||||||
|
int mp_add (mp_int * a, mp_int * b, mp_int * c);
|
||||||
|
int mp_sub (mp_int * a, mp_int * b, mp_int * c);
|
||||||
|
int mp_add_d (mp_int * a, mp_digit b, mp_int * c);
|
||||||
|
|
||||||
|
int mp_mul (mp_int * a, mp_int * b, mp_int * c);
|
||||||
|
int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d);
|
||||||
|
int mp_submod (mp_int* a, mp_int* b, mp_int* c, mp_int* d);
|
||||||
|
int mp_addmod (mp_int* a, mp_int* b, mp_int* c, mp_int* d);
|
||||||
|
int mp_mod(mp_int *a, mp_int *b, mp_int *c);
|
||||||
|
int mp_invmod(mp_int *a, mp_int *b, mp_int *c);
|
||||||
|
int mp_exptmod (mp_int * g, mp_int * x, mp_int * p, mp_int * y);
|
||||||
|
int mp_mul_2d(mp_int *a, int b, mp_int *c);
|
||||||
|
|
||||||
|
|
||||||
|
int mp_cmp(mp_int *a, mp_int *b);
|
||||||
|
int mp_cmp_d(mp_int *a, mp_digit b);
|
||||||
|
|
||||||
|
int mp_unsigned_bin_size(mp_int * a);
|
||||||
|
int mp_read_unsigned_bin (mp_int * a, const unsigned char *b, int c);
|
||||||
|
int mp_to_unsigned_bin (mp_int * a, unsigned char *b);
|
||||||
|
|
||||||
|
int mp_sub_d(fp_int *a, fp_digit b, fp_int *c);
|
||||||
|
int mp_copy(fp_int* a, fp_int* b);
|
||||||
|
int mp_isodd(mp_int* a);
|
||||||
|
int mp_iszero(mp_int* a);
|
||||||
|
int mp_count_bits(mp_int *a);
|
||||||
|
int mp_leading_bit(mp_int *a);
|
||||||
|
int mp_set_int(mp_int *a, mp_digit b);
|
||||||
|
int mp_is_bit_set (mp_int * a, mp_digit b);
|
||||||
|
int mp_set_bit (mp_int * a, mp_digit b);
|
||||||
|
void mp_rshb(mp_int *a, int x);
|
||||||
|
int mp_toradix (mp_int *a, char *str, int radix);
|
||||||
|
int mp_radix_size (mp_int * a, int radix, int *size);
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_DEBUG_MATH
|
||||||
|
void mp_dump(const char* desc, mp_int* a, byte verbose);
|
||||||
|
#else
|
||||||
|
#define mp_dump(desc, a, verbose)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_ECC
|
||||||
|
int mp_read_radix(mp_int* a, const char* str, int radix);
|
||||||
|
void mp_set(fp_int *a, fp_digit b);
|
||||||
|
int mp_sqr(fp_int *a, fp_int *b);
|
||||||
|
int mp_montgomery_reduce(fp_int *a, fp_int *m, fp_digit mp);
|
||||||
|
int mp_montgomery_setup(fp_int *a, fp_digit *rho);
|
||||||
|
int mp_div_2(fp_int * a, fp_int * b);
|
||||||
|
int mp_init_copy(fp_int * a, fp_int * b);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
|
||||||
|
int mp_sqrmod(mp_int* a, mp_int* b, mp_int* c);
|
||||||
|
int mp_montgomery_calc_normalization(mp_int *a, mp_int *b);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_KEY_GEN
|
||||||
|
int mp_gcd(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
int mp_lcm(fp_int *a, fp_int *b, fp_int *c);
|
||||||
|
int mp_prime_is_prime(mp_int* a, int t, int* result);
|
||||||
|
int mp_rand_prime(mp_int* N, int len, WC_RNG* rng, void* heap);
|
||||||
|
int mp_exch(mp_int *a, mp_int *b);
|
||||||
|
#endif /* WOLFSSL_KEY_GEN */
|
||||||
|
|
||||||
|
int mp_cnt_lsb(fp_int *a);
|
||||||
|
int mp_div_2d(fp_int *a, int b, fp_int *c, fp_int *d);
|
||||||
|
int mp_mod_d(fp_int* a, fp_digit b, fp_digit* c);
|
||||||
|
int mp_lshd (mp_int * a, int b);
|
||||||
|
|
||||||
|
WOLFSSL_API word32 CheckRunTimeFastMath(void);
|
||||||
|
|
||||||
|
/* If user uses RSA, DH, DSA, or ECC math lib directly then fast math FP_SIZE
|
||||||
|
must match, return 1 if a match otherwise 0 */
|
||||||
|
#define CheckFastMathSettings() (FP_SIZE == CheckRunTimeFastMath())
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLF_CRYPT_TFM_H */
|
||||||
|
|
|
@ -0,0 +1,421 @@
|
||||||
|
/* types.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_TYPES_H
|
||||||
|
#define WOLF_CRYPT_TYPES_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/settings.h>
|
||||||
|
#include <wolfssl/wolfcrypt/wc_port.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(WORDS_BIGENDIAN)
|
||||||
|
#define BIG_ENDIAN_ORDER
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef BIG_ENDIAN_ORDER
|
||||||
|
#define LITTLE_ENDIAN_ORDER
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_TYPES
|
||||||
|
#ifndef byte
|
||||||
|
typedef unsigned char byte;
|
||||||
|
#endif
|
||||||
|
typedef unsigned short word16;
|
||||||
|
typedef unsigned int word32;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* try to set SIZEOF_LONG or LONG_LONG if user didn't */
|
||||||
|
#if !defined(_MSC_VER) && !defined(__BCPLUSPLUS__)
|
||||||
|
#if !defined(SIZEOF_LONG_LONG) && !defined(SIZEOF_LONG)
|
||||||
|
#if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) \
|
||||||
|
|| defined(__mips64) || defined(__x86_64__))
|
||||||
|
/* long should be 64bit */
|
||||||
|
#define SIZEOF_LONG 8
|
||||||
|
#elif defined(__i386__) || defined(__CORTEX_M3__)
|
||||||
|
/* long long should be 64bit */
|
||||||
|
#define SIZEOF_LONG_LONG 8
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) || defined(__BCPLUSPLUS__)
|
||||||
|
#define WORD64_AVAILABLE
|
||||||
|
#define W64LIT(x) x##ui64
|
||||||
|
typedef unsigned __int64 word64;
|
||||||
|
#elif defined(SIZEOF_LONG) && SIZEOF_LONG == 8
|
||||||
|
#define WORD64_AVAILABLE
|
||||||
|
#define W64LIT(x) x##LL
|
||||||
|
typedef unsigned long word64;
|
||||||
|
#elif defined(SIZEOF_LONG_LONG) && SIZEOF_LONG_LONG == 8
|
||||||
|
#define WORD64_AVAILABLE
|
||||||
|
#define W64LIT(x) x##LL
|
||||||
|
typedef unsigned long long word64;
|
||||||
|
#elif defined(__SIZEOF_LONG_LONG__) && __SIZEOF_LONG_LONG__ == 8
|
||||||
|
#define WORD64_AVAILABLE
|
||||||
|
#define W64LIT(x) x##LL
|
||||||
|
typedef unsigned long long word64;
|
||||||
|
#else
|
||||||
|
#define MP_16BIT /* for mp_int, mp_word needs to be twice as big as
|
||||||
|
mp_digit, no 64 bit type so make mp_digit 16 bit */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* These platforms have 64-bit CPU registers. */
|
||||||
|
#if (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \
|
||||||
|
defined(__mips64) || defined(__x86_64__) || defined(_M_X64)) || \
|
||||||
|
defined(__aarch64__)
|
||||||
|
typedef word64 wolfssl_word;
|
||||||
|
#define WC_64BIT_CPU
|
||||||
|
#else
|
||||||
|
typedef word32 wolfssl_word;
|
||||||
|
#ifdef WORD64_AVAILABLE
|
||||||
|
#define WOLFCRYPT_SLOW_WORD64
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
enum {
|
||||||
|
WOLFSSL_WORD_SIZE = sizeof(wolfssl_word),
|
||||||
|
WOLFSSL_BIT_SIZE = 8,
|
||||||
|
WOLFSSL_WORD_BITS = WOLFSSL_WORD_SIZE * WOLFSSL_BIT_SIZE
|
||||||
|
};
|
||||||
|
|
||||||
|
#define WOLFSSL_MAX_16BIT 0xffffU
|
||||||
|
|
||||||
|
/* use inlining if compiler allows */
|
||||||
|
#ifndef INLINE
|
||||||
|
#ifndef NO_INLINE
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define INLINE __inline
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
#ifdef WOLFSSL_VXWORKS
|
||||||
|
#define INLINE __inline__
|
||||||
|
#else
|
||||||
|
#define INLINE inline
|
||||||
|
#endif
|
||||||
|
#elif defined(__IAR_SYSTEMS_ICC__)
|
||||||
|
#define INLINE inline
|
||||||
|
#elif defined(THREADX)
|
||||||
|
#define INLINE _Inline
|
||||||
|
#else
|
||||||
|
#define INLINE
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define INLINE
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* set up rotate style */
|
||||||
|
#if (defined(_MSC_VER) || defined(__BCPLUSPLUS__)) && !defined(WOLFSSL_SGX)
|
||||||
|
#define INTEL_INTRINSICS
|
||||||
|
#define FAST_ROTATE
|
||||||
|
#elif defined(__MWERKS__) && TARGET_CPU_PPC
|
||||||
|
#define PPC_INTRINSICS
|
||||||
|
#define FAST_ROTATE
|
||||||
|
#elif defined(__GNUC__) && defined(__i386__)
|
||||||
|
/* GCC does peephole optimizations which should result in using rotate
|
||||||
|
instructions */
|
||||||
|
#define FAST_ROTATE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* set up thread local storage if available */
|
||||||
|
#ifdef HAVE_THREAD_LS
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#define THREAD_LS_T __declspec(thread)
|
||||||
|
/* Thread local storage only in FreeRTOS v8.2.1 and higher */
|
||||||
|
#elif defined(FREERTOS)
|
||||||
|
#define THREAD_LS_T
|
||||||
|
#else
|
||||||
|
#define THREAD_LS_T __thread
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define THREAD_LS_T
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Micrium will use Visual Studio for compilation but not the Win32 API */
|
||||||
|
#if defined(_WIN32) && !defined(MICRIUM) && !defined(FREERTOS) && \
|
||||||
|
!defined(FREERTOS_TCP) && !defined(EBSNET) && !defined(WOLFSSL_UTASKER)
|
||||||
|
#define USE_WINDOWS_API
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* idea to add global alloc override by Moises Guimaraes */
|
||||||
|
/* default to libc stuff */
|
||||||
|
/* XREALLOC is used once in normal math lib, not in fast math lib */
|
||||||
|
/* XFREE on some embeded systems doesn't like free(0) so test */
|
||||||
|
#if defined(HAVE_IO_POOL)
|
||||||
|
WOLFSSL_API void* XMALLOC(size_t n, void* heap, int type);
|
||||||
|
WOLFSSL_API void* XREALLOC(void *p, size_t n, void* heap, int type);
|
||||||
|
WOLFSSL_API void XFREE(void *p, void* heap, int type);
|
||||||
|
#elif defined(XMALLOC_USER)
|
||||||
|
/* prototypes for user heap override functions */
|
||||||
|
#include <stddef.h> /* for size_t */
|
||||||
|
extern void *XMALLOC(size_t n, void* heap, int type);
|
||||||
|
extern void *XREALLOC(void *p, size_t n, void* heap, int type);
|
||||||
|
extern void XFREE(void *p, void* heap, int type);
|
||||||
|
#elif defined(NO_WOLFSSL_MEMORY)
|
||||||
|
/* just use plain C stdlib stuff if desired */
|
||||||
|
#include <stdlib.h>
|
||||||
|
#define XMALLOC(s, h, t) ((void)h, (void)t, malloc((s)))
|
||||||
|
#define XFREE(p, h, t) {void* xp = (p); if((xp)) free((xp));}
|
||||||
|
#define XREALLOC(p, n, h, t) realloc((p), (n))
|
||||||
|
#elif !defined(MICRIUM_MALLOC) && !defined(EBSNET) \
|
||||||
|
&& !defined(WOLFSSL_SAFERTOS) && !defined(FREESCALE_MQX) \
|
||||||
|
&& !defined(FREESCALE_KSDK_MQX) && !defined(FREESCALE_FREE_RTOS) \
|
||||||
|
&& !defined(WOLFSSL_LEANPSK) && !defined(FREERTOS) && !defined(FREERTOS_TCP)\
|
||||||
|
&& !defined(WOLFSSL_uITRON4) && !defined(WOLFSSL_uTKERNEL2)
|
||||||
|
/* default C runtime, can install different routines at runtime via cbs */
|
||||||
|
#include <wolfssl/wolfcrypt/memory.h>
|
||||||
|
#ifdef WOLFSSL_STATIC_MEMORY
|
||||||
|
#ifdef WOLFSSL_DEBUG_MEMORY
|
||||||
|
#define XMALLOC(s, h, t) wolfSSL_Malloc((s), (h), (t), __func__, __LINE__)
|
||||||
|
#define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp), (h), (t), __func__, __LINE__);}
|
||||||
|
#define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n), (h), (t), __func__, __LINE__)
|
||||||
|
#else
|
||||||
|
#define XMALLOC(s, h, t) wolfSSL_Malloc((s), (h), (t))
|
||||||
|
#define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp), (h), (t));}
|
||||||
|
#define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n), (h), (t))
|
||||||
|
#endif /* WOLFSSL_DEBUG_MEMORY */
|
||||||
|
#else
|
||||||
|
#ifdef WOLFSSL_DEBUG_MEMORY
|
||||||
|
#define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s), __func__, __LINE__))
|
||||||
|
#define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp), __func__, __LINE__);}
|
||||||
|
#define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n), __func__, __LINE__)
|
||||||
|
#else
|
||||||
|
#define XMALLOC(s, h, t) ((void)h, (void)t, wolfSSL_Malloc((s)))
|
||||||
|
#define XFREE(p, h, t) {void* xp = (p); if((xp)) wolfSSL_Free((xp));}
|
||||||
|
#define XREALLOC(p, n, h, t) wolfSSL_Realloc((p), (n))
|
||||||
|
#endif /* WOLFSSL_DEBUG_MEMORY */
|
||||||
|
#endif /* WOLFSSL_STATIC_MEMORY */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef STRING_USER
|
||||||
|
#include <string.h>
|
||||||
|
char* mystrnstr(const char* s1, const char* s2, unsigned int n);
|
||||||
|
|
||||||
|
#define XMEMCPY(d,s,l) memcpy((d),(s),(l))
|
||||||
|
#define XMEMSET(b,c,l) memset((b),(c),(l))
|
||||||
|
#define XMEMCMP(s1,s2,n) memcmp((s1),(s2),(n))
|
||||||
|
#define XMEMMOVE(d,s,l) memmove((d),(s),(l))
|
||||||
|
|
||||||
|
#define XSTRLEN(s1) strlen((s1))
|
||||||
|
#define XSTRNCPY(s1,s2,n) strncpy((s1),(s2),(n))
|
||||||
|
/* strstr, strncmp, and strncat only used by wolfSSL proper,
|
||||||
|
* not required for wolfCrypt only */
|
||||||
|
#define XSTRSTR(s1,s2) strstr((s1),(s2))
|
||||||
|
#define XSTRNSTR(s1,s2,n) mystrnstr((s1),(s2),(n))
|
||||||
|
#define XSTRNCMP(s1,s2,n) strncmp((s1),(s2),(n))
|
||||||
|
#define XSTRNCAT(s1,s2,n) strncat((s1),(s2),(n))
|
||||||
|
#ifndef USE_WINDOWS_API
|
||||||
|
#define XSTRNCASECMP(s1,s2,n) strncasecmp((s1),(s2),(n))
|
||||||
|
#else
|
||||||
|
#define XSTRNCASECMP(s1,s2,n) _strnicmp((s1),(s2),(n))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(WOLFSSL_MYSQL_COMPATIBLE)
|
||||||
|
#ifndef USE_WINDOWS_API
|
||||||
|
#define XSNPRINTF snprintf
|
||||||
|
#else
|
||||||
|
#define XSNPRINTF _snprintf
|
||||||
|
#endif
|
||||||
|
#endif /* WOLFSSL_MYSQL_COMPATIBLE */
|
||||||
|
|
||||||
|
#if defined(WOLFSSL_CERT_EXT) || defined(HAVE_ALPN)
|
||||||
|
/* use only Thread Safe version of strtok */
|
||||||
|
#ifndef USE_WINDOWS_API
|
||||||
|
#define XSTRTOK strtok_r
|
||||||
|
#else
|
||||||
|
#define XSTRTOK strtok_s
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic warning "-Wcpp"
|
||||||
|
#warning "MinGW may be missing strtok_s. You can find a public domain implementation here: https://github.com/fletcher/MultiMarkdown-4/blob/master/strtok.c"
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CTYPE_USER
|
||||||
|
#include <ctype.h>
|
||||||
|
#if defined(HAVE_ECC) || defined(HAVE_OCSP) || defined(WOLFSSL_KEY_GEN)
|
||||||
|
#define XTOUPPER(c) toupper((c))
|
||||||
|
#define XISALPHA(c) isalpha((c))
|
||||||
|
#endif
|
||||||
|
/* needed by wolfSSL_check_domain_name() */
|
||||||
|
#define XTOLOWER(c) tolower((c))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* memory allocation types for user hints */
|
||||||
|
enum {
|
||||||
|
DYNAMIC_TYPE_CA = 1,
|
||||||
|
DYNAMIC_TYPE_CERT = 2,
|
||||||
|
DYNAMIC_TYPE_KEY = 3,
|
||||||
|
DYNAMIC_TYPE_FILE = 4,
|
||||||
|
DYNAMIC_TYPE_SUBJECT_CN = 5,
|
||||||
|
DYNAMIC_TYPE_PUBLIC_KEY = 6,
|
||||||
|
DYNAMIC_TYPE_SIGNER = 7,
|
||||||
|
DYNAMIC_TYPE_NONE = 8,
|
||||||
|
DYNAMIC_TYPE_BIGINT = 9,
|
||||||
|
DYNAMIC_TYPE_RSA = 10,
|
||||||
|
DYNAMIC_TYPE_METHOD = 11,
|
||||||
|
DYNAMIC_TYPE_OUT_BUFFER = 12,
|
||||||
|
DYNAMIC_TYPE_IN_BUFFER = 13,
|
||||||
|
DYNAMIC_TYPE_INFO = 14,
|
||||||
|
DYNAMIC_TYPE_DH = 15,
|
||||||
|
DYNAMIC_TYPE_DOMAIN = 16,
|
||||||
|
DYNAMIC_TYPE_SSL = 17,
|
||||||
|
DYNAMIC_TYPE_CTX = 18,
|
||||||
|
DYNAMIC_TYPE_WRITEV = 19,
|
||||||
|
DYNAMIC_TYPE_OPENSSL = 20,
|
||||||
|
DYNAMIC_TYPE_DSA = 21,
|
||||||
|
DYNAMIC_TYPE_CRL = 22,
|
||||||
|
DYNAMIC_TYPE_REVOKED = 23,
|
||||||
|
DYNAMIC_TYPE_CRL_ENTRY = 24,
|
||||||
|
DYNAMIC_TYPE_CERT_MANAGER = 25,
|
||||||
|
DYNAMIC_TYPE_CRL_MONITOR = 26,
|
||||||
|
DYNAMIC_TYPE_OCSP_STATUS = 27,
|
||||||
|
DYNAMIC_TYPE_OCSP_ENTRY = 28,
|
||||||
|
DYNAMIC_TYPE_ALTNAME = 29,
|
||||||
|
DYNAMIC_TYPE_SUITES = 30,
|
||||||
|
DYNAMIC_TYPE_CIPHER = 31,
|
||||||
|
DYNAMIC_TYPE_RNG = 32,
|
||||||
|
DYNAMIC_TYPE_ARRAYS = 33,
|
||||||
|
DYNAMIC_TYPE_DTLS_POOL = 34,
|
||||||
|
DYNAMIC_TYPE_SOCKADDR = 35,
|
||||||
|
DYNAMIC_TYPE_LIBZ = 36,
|
||||||
|
DYNAMIC_TYPE_ECC = 37,
|
||||||
|
DYNAMIC_TYPE_TMP_BUFFER = 38,
|
||||||
|
DYNAMIC_TYPE_DTLS_MSG = 39,
|
||||||
|
DYNAMIC_TYPE_ASYNC_TMP = 40,
|
||||||
|
DYNAMIC_TYPE_ASYNC_RSA = 41,
|
||||||
|
DYNAMIC_TYPE_X509 = 42,
|
||||||
|
DYNAMIC_TYPE_TLSX = 43,
|
||||||
|
DYNAMIC_TYPE_OCSP = 44,
|
||||||
|
DYNAMIC_TYPE_SIGNATURE = 45,
|
||||||
|
DYNAMIC_TYPE_HASHES = 46,
|
||||||
|
DYNAMIC_TYPE_SRP = 47,
|
||||||
|
DYNAMIC_TYPE_COOKIE_PWD = 48,
|
||||||
|
DYNAMIC_TYPE_USER_CRYPTO = 49,
|
||||||
|
DYNAMIC_TYPE_OCSP_REQUEST = 50,
|
||||||
|
DYNAMIC_TYPE_X509_EXT = 51,
|
||||||
|
DYNAMIC_TYPE_X509_STORE = 52,
|
||||||
|
DYNAMIC_TYPE_X509_CTX = 53,
|
||||||
|
DYNAMIC_TYPE_URL = 54,
|
||||||
|
DYNAMIC_TYPE_DTLS_FRAG = 55,
|
||||||
|
DYNAMIC_TYPE_DTLS_BUFFER = 56,
|
||||||
|
DYNAMIC_TYPE_SESSION_TICK = 57,
|
||||||
|
DYNAMIC_TYPE_PKCS = 58,
|
||||||
|
DYNAMIC_TYPE_MUTEX = 59,
|
||||||
|
DYNAMIC_TYPE_PKCS7 = 60
|
||||||
|
};
|
||||||
|
|
||||||
|
/* max error buffer string size */
|
||||||
|
enum {
|
||||||
|
WOLFSSL_MAX_ERROR_SZ = 80
|
||||||
|
};
|
||||||
|
|
||||||
|
/* stack protection */
|
||||||
|
enum {
|
||||||
|
MIN_STACK_BUFFER = 8
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* settings detection for compile vs runtime math incompatibilities */
|
||||||
|
enum {
|
||||||
|
#if !defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG)
|
||||||
|
CTC_SETTINGS = 0x0
|
||||||
|
#elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
|
||||||
|
CTC_SETTINGS = 0x1
|
||||||
|
#elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 8)
|
||||||
|
CTC_SETTINGS = 0x2
|
||||||
|
#elif !defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 4)
|
||||||
|
CTC_SETTINGS = 0x4
|
||||||
|
#elif defined(USE_FAST_MATH) && !defined(SIZEOF_LONG) && !defined(SIZEOF_LONG_LONG)
|
||||||
|
CTC_SETTINGS = 0x8
|
||||||
|
#elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
|
||||||
|
CTC_SETTINGS = 0x10
|
||||||
|
#elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 8)
|
||||||
|
CTC_SETTINGS = 0x20
|
||||||
|
#elif defined(USE_FAST_MATH) && defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 4)
|
||||||
|
CTC_SETTINGS = 0x40
|
||||||
|
#else
|
||||||
|
#error "bad math long / long long settings"
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
WOLFSSL_API word32 CheckRunTimeSettings(void);
|
||||||
|
|
||||||
|
/* If user uses RSA, DH, DSA, or ECC math lib directly then fast math and long
|
||||||
|
types need to match at compile time and run time, CheckCtcSettings will
|
||||||
|
return 1 if a match otherwise 0 */
|
||||||
|
#define CheckCtcSettings() (CTC_SETTINGS == CheckRunTimeSettings())
|
||||||
|
|
||||||
|
/* invalid device id */
|
||||||
|
#define INVALID_DEVID -2
|
||||||
|
|
||||||
|
|
||||||
|
/* AESNI requires alignment and ARMASM gains some performance from it */
|
||||||
|
#if defined(WOLFSSL_AESNI) || defined(WOLFSSL_ARMASM)
|
||||||
|
#if !defined (ALIGN16)
|
||||||
|
#if defined (__GNUC__)
|
||||||
|
#define ALIGN16 __attribute__ ( (aligned (16)))
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
/* disable align warning, we want alignment ! */
|
||||||
|
#pragma warning(disable: 4324)
|
||||||
|
#define ALIGN16 __declspec (align (16))
|
||||||
|
#else
|
||||||
|
#define ALIGN16
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#ifndef ALIGN16
|
||||||
|
#define ALIGN16
|
||||||
|
#endif
|
||||||
|
#endif /* WOLFSSL_AESNI or WOLFSSL_ARMASM */
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_RIOT_OS
|
||||||
|
#define EXIT_TEST(ret) exit(ret)
|
||||||
|
#else
|
||||||
|
#define EXIT_TEST(ret) return ret
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLF_CRYPT_TYPES_H */
|
|
@ -0,0 +1,76 @@
|
||||||
|
/* visibility.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* Visibility control macros */
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_VISIBILITY_H
|
||||||
|
#define WOLF_CRYPT_VISIBILITY_H
|
||||||
|
|
||||||
|
|
||||||
|
/* for compatibility and so that fips is using same name of macro @wc_fips */
|
||||||
|
#ifdef HAVE_FIPS
|
||||||
|
#include <cyassl/ctaocrypt/visibility.h>
|
||||||
|
#define WOLFSSL_API CYASSL_API
|
||||||
|
#define WOLFSSL_LOCAL CYASSL_LOCAL
|
||||||
|
#else
|
||||||
|
|
||||||
|
/* WOLFSSL_API is used for the public API symbols.
|
||||||
|
It either imports or exports (or does nothing for static builds)
|
||||||
|
|
||||||
|
WOLFSSL_LOCAL is used for non-API symbols (private).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(BUILDING_WOLFSSL)
|
||||||
|
#if defined(HAVE_VISIBILITY) && HAVE_VISIBILITY
|
||||||
|
#define WOLFSSL_API __attribute__ ((visibility("default")))
|
||||||
|
#define WOLFSSL_LOCAL __attribute__ ((visibility("hidden")))
|
||||||
|
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
|
||||||
|
#define WOLFSSL_API __global
|
||||||
|
#define WOLFSSL_LOCAL __hidden
|
||||||
|
#elif defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
|
#if defined(WOLFSSL_DLL)
|
||||||
|
#define WOLFSSL_API __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define WOLFSSL_API
|
||||||
|
#endif
|
||||||
|
#define WOLFSSL_LOCAL
|
||||||
|
#else
|
||||||
|
#define WOLFSSL_API
|
||||||
|
#define WOLFSSL_LOCAL
|
||||||
|
#endif /* HAVE_VISIBILITY */
|
||||||
|
#else /* BUILDING_WOLFSSL */
|
||||||
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
|
#if defined(WOLFSSL_DLL)
|
||||||
|
#define WOLFSSL_API __declspec(dllimport)
|
||||||
|
#else
|
||||||
|
#define WOLFSSL_API
|
||||||
|
#endif
|
||||||
|
#define WOLFSSL_LOCAL
|
||||||
|
#else
|
||||||
|
#define WOLFSSL_API
|
||||||
|
#define WOLFSSL_LOCAL
|
||||||
|
#endif
|
||||||
|
#endif /* BUILDING_WOLFSSL */
|
||||||
|
|
||||||
|
#endif /* HAVE_FIPS */
|
||||||
|
#endif /* WOLF_CRYPT_VISIBILITY_H */
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
/* wc_encrypt.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_ENCRYPT_H
|
||||||
|
#define WOLF_CRYPT_ENCRYPT_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/types.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NO_AES
|
||||||
|
WOLFSSL_API int wc_AesCbcEncryptWithKey(byte* out, const byte* in, word32 inSz,
|
||||||
|
const byte* key, word32 keySz,
|
||||||
|
const byte* iv);
|
||||||
|
WOLFSSL_API int wc_AesCbcDecryptWithKey(byte* out, const byte* in, word32 inSz,
|
||||||
|
const byte* key, word32 keySz,
|
||||||
|
const byte* iv);
|
||||||
|
#endif /* !NO_AES */
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef NO_DES3
|
||||||
|
WOLFSSL_API int wc_Des_CbcDecryptWithKey(byte* out,
|
||||||
|
const byte* in, word32 sz,
|
||||||
|
const byte* key, const byte* iv);
|
||||||
|
WOLFSSL_API int wc_Des_CbcEncryptWithKey(byte* out,
|
||||||
|
const byte* in, word32 sz,
|
||||||
|
const byte* key, const byte* iv);
|
||||||
|
WOLFSSL_API int wc_Des3_CbcEncryptWithKey(byte* out,
|
||||||
|
const byte* in, word32 sz,
|
||||||
|
const byte* key, const byte* iv);
|
||||||
|
WOLFSSL_API int wc_Des3_CbcDecryptWithKey(byte* out,
|
||||||
|
const byte* in, word32 sz,
|
||||||
|
const byte* key, const byte* iv);
|
||||||
|
#endif /* !NO_DES3 */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLF_CRYPT_ENCRYPT_H */
|
||||||
|
|
|
@ -0,0 +1,278 @@
|
||||||
|
/* wc_port.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WOLF_CRYPT_PORT_H
|
||||||
|
#define WOLF_CRYPT_PORT_H
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/visibility.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef USE_WINDOWS_API
|
||||||
|
#ifdef WOLFSSL_GAME_BUILD
|
||||||
|
#include "system/xtl.h"
|
||||||
|
#else
|
||||||
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#endif
|
||||||
|
#ifndef WOLFCRYPT_ONLY
|
||||||
|
#if defined(_WIN32_WCE) || defined(WIN32_LEAN_AND_MEAN)
|
||||||
|
/* On WinCE winsock2.h must be included before windows.h */
|
||||||
|
#include <winsock2.h>
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
#endif /* WOLFCRYPT_ONLY */
|
||||||
|
#elif defined(THREADX)
|
||||||
|
#ifndef SINGLE_THREADED
|
||||||
|
#include "tx_api.h"
|
||||||
|
#endif
|
||||||
|
#elif defined(MICRIUM)
|
||||||
|
/* do nothing, just don't pick Unix */
|
||||||
|
#elif defined(FREERTOS) || defined(FREERTOS_TCP) || defined(WOLFSSL_SAFERTOS)
|
||||||
|
/* do nothing */
|
||||||
|
#elif defined(EBSNET)
|
||||||
|
/* do nothing */
|
||||||
|
#elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
|
||||||
|
/* do nothing */
|
||||||
|
#elif defined(FREESCALE_FREE_RTOS)
|
||||||
|
#include "fsl_os_abstraction.h"
|
||||||
|
#elif defined(WOLFSSL_uITRON4)
|
||||||
|
#include "kernel.h"
|
||||||
|
#elif defined(WOLFSSL_uTKERNEL2)
|
||||||
|
#include "tk/tkernel.h"
|
||||||
|
#elif defined(WOLFSSL_MDK_ARM)
|
||||||
|
#if defined(WOLFSSL_MDK5)
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
#else
|
||||||
|
#include <rtl.h>
|
||||||
|
#endif
|
||||||
|
#elif defined(WOLFSSL_CMSIS_RTOS)
|
||||||
|
#include "cmsis_os.h"
|
||||||
|
#elif defined(WOLFSSL_TIRTOS)
|
||||||
|
#include <ti/sysbios/BIOS.h>
|
||||||
|
#include <ti/sysbios/knl/Semaphore.h>
|
||||||
|
#elif defined(WOLFSSL_FROSTED)
|
||||||
|
#include <semaphore.h>
|
||||||
|
#else
|
||||||
|
#ifndef SINGLE_THREADED
|
||||||
|
#define WOLFSSL_PTHREADS
|
||||||
|
#include <pthread.h>
|
||||||
|
#endif
|
||||||
|
#if defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS)
|
||||||
|
#include <unistd.h> /* for close of BIO */
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* For FIPS keep the function names the same */
|
||||||
|
#ifdef HAVE_FIPS
|
||||||
|
#define wc_InitMutex InitMutex
|
||||||
|
#define wc_FreeMutex FreeMutex
|
||||||
|
#define wc_LockMutex LockMutex
|
||||||
|
#define wc_UnLockMutex UnLockMutex
|
||||||
|
#endif /* HAVE_FIPS */
|
||||||
|
|
||||||
|
#ifdef SINGLE_THREADED
|
||||||
|
typedef int wolfSSL_Mutex;
|
||||||
|
#else /* MULTI_THREADED */
|
||||||
|
/* FREERTOS comes first to enable use of FreeRTOS Windows simulator only */
|
||||||
|
#if defined(FREERTOS)
|
||||||
|
typedef xSemaphoreHandle wolfSSL_Mutex;
|
||||||
|
#elif defined(FREERTOS_TCP)
|
||||||
|
#include "FreeRTOS.h"
|
||||||
|
#include "semphr.h"
|
||||||
|
typedef SemaphoreHandle_t wolfSSL_Mutex;
|
||||||
|
#elif defined(WOLFSSL_SAFERTOS)
|
||||||
|
typedef struct wolfSSL_Mutex {
|
||||||
|
signed char mutexBuffer[portQUEUE_OVERHEAD_BYTES];
|
||||||
|
xSemaphoreHandle mutex;
|
||||||
|
} wolfSSL_Mutex;
|
||||||
|
#elif defined(USE_WINDOWS_API)
|
||||||
|
typedef CRITICAL_SECTION wolfSSL_Mutex;
|
||||||
|
#elif defined(WOLFSSL_PTHREADS)
|
||||||
|
typedef pthread_mutex_t wolfSSL_Mutex;
|
||||||
|
#elif defined(THREADX)
|
||||||
|
typedef TX_MUTEX wolfSSL_Mutex;
|
||||||
|
#elif defined(MICRIUM)
|
||||||
|
typedef OS_MUTEX wolfSSL_Mutex;
|
||||||
|
#elif defined(EBSNET)
|
||||||
|
typedef RTP_MUTEX wolfSSL_Mutex;
|
||||||
|
#elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
|
||||||
|
typedef MUTEX_STRUCT wolfSSL_Mutex;
|
||||||
|
#elif defined(FREESCALE_FREE_RTOS)
|
||||||
|
typedef mutex_t wolfSSL_Mutex;
|
||||||
|
#elif defined(WOLFSSL_uITRON4)
|
||||||
|
typedef struct wolfSSL_Mutex {
|
||||||
|
T_CSEM sem ;
|
||||||
|
ID id ;
|
||||||
|
} wolfSSL_Mutex;
|
||||||
|
#elif defined(WOLFSSL_uTKERNEL2)
|
||||||
|
typedef struct wolfSSL_Mutex {
|
||||||
|
T_CSEM sem ;
|
||||||
|
ID id ;
|
||||||
|
} wolfSSL_Mutex;
|
||||||
|
#elif defined(WOLFSSL_MDK_ARM)
|
||||||
|
#if defined(WOLFSSL_CMSIS_RTOS)
|
||||||
|
typedef osMutexId wolfSSL_Mutex;
|
||||||
|
#else
|
||||||
|
typedef OS_MUT wolfSSL_Mutex;
|
||||||
|
#endif
|
||||||
|
#elif defined(WOLFSSL_CMSIS_RTOS)
|
||||||
|
typedef osMutexId wolfSSL_Mutex;
|
||||||
|
#elif defined(WOLFSSL_TIRTOS)
|
||||||
|
typedef ti_sysbios_knl_Semaphore_Handle wolfSSL_Mutex;
|
||||||
|
#elif defined(WOLFSSL_FROSTED)
|
||||||
|
typedef mutex_t * wolfSSL_Mutex;
|
||||||
|
#else
|
||||||
|
#error Need a mutex type in multithreaded mode
|
||||||
|
#endif /* USE_WINDOWS_API */
|
||||||
|
#endif /* SINGLE_THREADED */
|
||||||
|
|
||||||
|
/* Enable crypt HW mutex for Freescale MMCAU */
|
||||||
|
#if defined(FREESCALE_MMCAU)
|
||||||
|
#ifndef WOLFSSL_CRYPT_HW_MUTEX
|
||||||
|
#define WOLFSSL_CRYPT_HW_MUTEX 1
|
||||||
|
#endif
|
||||||
|
#endif /* FREESCALE_MMCAU */
|
||||||
|
|
||||||
|
#ifndef WOLFSSL_CRYPT_HW_MUTEX
|
||||||
|
#define WOLFSSL_CRYPT_HW_MUTEX 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if WOLFSSL_CRYPT_HW_MUTEX
|
||||||
|
/* wolfSSL_CryptHwMutexInit is called on first wolfSSL_CryptHwMutexLock,
|
||||||
|
however it's recommended to call this directly on Hw init to avoid possible
|
||||||
|
race condition where two calls to wolfSSL_CryptHwMutexLock are made at
|
||||||
|
the same time. */
|
||||||
|
int wolfSSL_CryptHwMutexInit(void);
|
||||||
|
int wolfSSL_CryptHwMutexLock(void);
|
||||||
|
int wolfSSL_CryptHwMutexUnLock(void);
|
||||||
|
#else
|
||||||
|
/* Define stubs, since HW mutex is disabled */
|
||||||
|
#define wolfSSL_CryptHwMutexInit() 0 /* Success */
|
||||||
|
#define wolfSSL_CryptHwMutexLock() 0 /* Success */
|
||||||
|
#define wolfSSL_CryptHwMutexUnLock() 0 /* Success */
|
||||||
|
#endif /* WOLFSSL_CRYPT_HW_MUTEX */
|
||||||
|
|
||||||
|
/* Mutex functions */
|
||||||
|
WOLFSSL_API int wc_InitMutex(wolfSSL_Mutex*);
|
||||||
|
WOLFSSL_API wolfSSL_Mutex* wc_InitAndAllocMutex(void);
|
||||||
|
WOLFSSL_API int wc_FreeMutex(wolfSSL_Mutex*);
|
||||||
|
WOLFSSL_API int wc_LockMutex(wolfSSL_Mutex*);
|
||||||
|
WOLFSSL_API int wc_UnLockMutex(wolfSSL_Mutex*);
|
||||||
|
|
||||||
|
/* main crypto initialization function */
|
||||||
|
WOLFSSL_API int wolfCrypt_Init(void);
|
||||||
|
|
||||||
|
/* filesystem abstraction layer, used by ssl.c */
|
||||||
|
#ifndef NO_FILESYSTEM
|
||||||
|
|
||||||
|
#if defined(EBSNET)
|
||||||
|
#define XFILE int
|
||||||
|
#define XFOPEN(NAME, MODE) vf_open((const char *)NAME, VO_RDONLY, 0);
|
||||||
|
#define XFSEEK vf_lseek
|
||||||
|
#define XFTELL vf_tell
|
||||||
|
#define XREWIND vf_rewind
|
||||||
|
#define XFREAD(BUF, SZ, AMT, FD) vf_read(FD, BUF, SZ*AMT)
|
||||||
|
#define XFWRITE(BUF, SZ, AMT, FD) vf_write(FD, BUF, SZ*AMT)
|
||||||
|
#define XFCLOSE vf_close
|
||||||
|
#define XSEEK_END VSEEK_END
|
||||||
|
#define XBADFILE -1
|
||||||
|
#elif defined(LSR_FS)
|
||||||
|
#include <fs.h>
|
||||||
|
#define XFILE struct fs_file*
|
||||||
|
#define XFOPEN(NAME, MODE) fs_open((char*)NAME);
|
||||||
|
#define XFSEEK(F, O, W) (void)F
|
||||||
|
#define XFTELL(F) (F)->len
|
||||||
|
#define XREWIND(F) (void)F
|
||||||
|
#define XFREAD(BUF, SZ, AMT, F) fs_read(F, (char*)BUF, SZ*AMT)
|
||||||
|
#define XFWRITE(BUF, SZ, AMT, F) fs_write(F, (char*)BUF, SZ*AMT)
|
||||||
|
#define XFCLOSE fs_close
|
||||||
|
#define XSEEK_END 0
|
||||||
|
#define XBADFILE NULL
|
||||||
|
#elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
|
||||||
|
#define XFILE MQX_FILE_PTR
|
||||||
|
#define XFOPEN fopen
|
||||||
|
#define XFSEEK fseek
|
||||||
|
#define XFTELL ftell
|
||||||
|
#define XREWIND(F) fseek(F, 0, IO_SEEK_SET)
|
||||||
|
#define XFREAD fread
|
||||||
|
#define XFWRITE fwrite
|
||||||
|
#define XFCLOSE fclose
|
||||||
|
#define XSEEK_END IO_SEEK_END
|
||||||
|
#define XBADFILE NULL
|
||||||
|
#elif defined(MICRIUM)
|
||||||
|
#include <fs.h>
|
||||||
|
#define XFILE FS_FILE*
|
||||||
|
#define XFOPEN fs_fopen
|
||||||
|
#define XFSEEK fs_fseek
|
||||||
|
#define XFTELL fs_ftell
|
||||||
|
#define XREWIND fs_rewind
|
||||||
|
#define XFREAD fs_fread
|
||||||
|
#define XFWRITE fs_fwrite
|
||||||
|
#define XFCLOSE fs_fclose
|
||||||
|
#define XSEEK_END FS_SEEK_END
|
||||||
|
#define XBADFILE NULL
|
||||||
|
#else
|
||||||
|
/* stdio, default case */
|
||||||
|
#include <stdio.h>
|
||||||
|
#define XFILE FILE*
|
||||||
|
#if defined(WOLFSSL_MDK_ARM)
|
||||||
|
extern FILE * wolfSSL_fopen(const char *name, const char *mode) ;
|
||||||
|
#define XFOPEN wolfSSL_fopen
|
||||||
|
#else
|
||||||
|
#define XFOPEN fopen
|
||||||
|
#endif
|
||||||
|
#define XFSEEK fseek
|
||||||
|
#define XFTELL ftell
|
||||||
|
#define XREWIND rewind
|
||||||
|
#define XFREAD fread
|
||||||
|
#define XFWRITE fwrite
|
||||||
|
#define XFCLOSE fclose
|
||||||
|
#define XSEEK_END SEEK_END
|
||||||
|
#define XBADFILE NULL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* NO_FILESYSTEM */
|
||||||
|
|
||||||
|
|
||||||
|
/* Windows API defines its own min() macro. */
|
||||||
|
#if defined(USE_WINDOWS_API)
|
||||||
|
#if defined(min) || defined(WOLFSSL_MYSQL_COMPATIBLE)
|
||||||
|
#define WOLFSSL_HAVE_MIN
|
||||||
|
#endif /* min */
|
||||||
|
#if defined(max) || defined(WOLFSSL_MYSQL_COMPATIBLE)
|
||||||
|
#define WOLFSSL_HAVE_MAX
|
||||||
|
#endif /* max */
|
||||||
|
#endif /* USE_WINDOWS_API */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WOLF_CRYPT_PORT_H */
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
/* wolfevent.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2016 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _WOLF_EVENT_H_
|
||||||
|
#define _WOLF_EVENT_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SINGLE_THREADED
|
||||||
|
#include <wolfssl/wolfcrypt/wc_port.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct WOLFSSL WOLFSSL;
|
||||||
|
typedef struct WOLF_EVENT WOLF_EVENT;
|
||||||
|
typedef struct WOLFSSL_CTX WOLFSSL_CTX;
|
||||||
|
|
||||||
|
typedef unsigned short WOLF_EVENT_FLAG;
|
||||||
|
|
||||||
|
typedef enum WOLF_EVENT_TYPE {
|
||||||
|
WOLF_EVENT_TYPE_NONE,
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
WOLF_EVENT_TYPE_ASYNC_ANY,
|
||||||
|
WOLF_EVENT_TYPE_ASYNC_WOLFSSL,
|
||||||
|
WOLF_EVENT_TYPE_ASYNC_WOLFCRYPT,
|
||||||
|
WOLF_EVENT_TYPE_ASYNC_FIRST = WOLF_EVENT_TYPE_ASYNC_WOLFSSL,
|
||||||
|
WOLF_EVENT_TYPE_ASYNC_LAST = WOLF_EVENT_TYPE_ASYNC_WOLFCRYPT,
|
||||||
|
#endif
|
||||||
|
} WOLF_EVENT_TYPE;
|
||||||
|
|
||||||
|
struct WOLF_EVENT {
|
||||||
|
/* double linked list */
|
||||||
|
WOLF_EVENT* next;
|
||||||
|
WOLF_EVENT* prev;
|
||||||
|
|
||||||
|
void* context;
|
||||||
|
#ifdef HAVE_CAVIUM
|
||||||
|
word64 reqId;
|
||||||
|
#endif
|
||||||
|
int ret; /* Async return code */
|
||||||
|
WOLF_EVENT_TYPE type;
|
||||||
|
WOLF_EVENT_FLAG pending:1;
|
||||||
|
WOLF_EVENT_FLAG done:1;
|
||||||
|
/* Future event flags can go here */
|
||||||
|
};
|
||||||
|
|
||||||
|
enum WOLF_POLL_FLAGS {
|
||||||
|
WOLF_POLL_FLAG_CHECK_HW = 0x01,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
WOLF_EVENT* head; /* head of queue */
|
||||||
|
WOLF_EVENT* tail; /* tail of queue */
|
||||||
|
#ifndef SINGLE_THREADED
|
||||||
|
wolfSSL_Mutex lock; /* queue lock */
|
||||||
|
#endif
|
||||||
|
int count;
|
||||||
|
} WOLF_EVENT_QUEUE;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_WOLF_EVENT
|
||||||
|
|
||||||
|
/* Event */
|
||||||
|
WOLFSSL_API int wolfEvent_Init(WOLF_EVENT* event, WOLF_EVENT_TYPE type, void* context);
|
||||||
|
WOLFSSL_API int wolfEvent_Poll(WOLF_EVENT* event, WOLF_EVENT_FLAG flags);
|
||||||
|
|
||||||
|
/* Event Queue */
|
||||||
|
WOLFSSL_API int wolfEventQueue_Init(WOLF_EVENT_QUEUE* queue);
|
||||||
|
WOLFSSL_API int wolfEventQueue_Push(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event);
|
||||||
|
WOLFSSL_API int wolfEventQueue_Pop(WOLF_EVENT_QUEUE* queue, WOLF_EVENT** event);
|
||||||
|
WOLFSSL_API int wolfEventQueue_Remove(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event);
|
||||||
|
WOLFSSL_API int wolfEventQueue_Poll(WOLF_EVENT_QUEUE* queue, void* context_filter,
|
||||||
|
WOLF_EVENT** events, int maxEvents, WOLF_EVENT_FLAG flags, int* eventCount);
|
||||||
|
WOLFSSL_API int wolfEventQueue_Count(WOLF_EVENT_QUEUE* queue);
|
||||||
|
WOLFSSL_API void wolfEventQueue_Free(WOLF_EVENT_QUEUE* queue);
|
||||||
|
|
||||||
|
#endif /* HAVE_WOLF_EVENT */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _WOLF_EVENT_H_ */
|
Binary file not shown.
Binary file not shown.
|
@ -1,17 +0,0 @@
|
||||||
# Add project specific ProGuard rules here.
|
|
||||||
# By default, the flags in this file are appended to flags specified
|
|
||||||
# in /Users/gfan/dev/sdk_current/tools/proguard/proguard-android.txt
|
|
||||||
# You can edit the include path and order by changing the proguardFiles
|
|
||||||
# directive in build.gradle.
|
|
||||||
#
|
|
||||||
# For more details, see
|
|
||||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
|
||||||
|
|
||||||
# Add any project specific keep options here:
|
|
||||||
|
|
||||||
# If your project uses WebView with JS, uncomment the following
|
|
||||||
# and specify the fully qualified class name to the JavaScript interface
|
|
||||||
# class:
|
|
||||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
|
||||||
# public *;
|
|
||||||
#}
|
|
|
@ -1,3 +0,0 @@
|
||||||
# this CMake file is the root, and is used to create the bin folder
|
|
||||||
# add_subdirectory(wolfssl-oem)
|
|
||||||
# add_subdirectory(wolfcrypt)
|
|
|
@ -25,11 +25,11 @@ add_library( wolfssl-oem
|
||||||
STATIC
|
STATIC
|
||||||
IMPORTED )
|
IMPORTED )
|
||||||
set_target_properties( wolfssl-oem PROPERTIES IMPORTED_LOCATION
|
set_target_properties( wolfssl-oem PROPERTIES IMPORTED_LOCATION
|
||||||
"${CMAKE_SOURCE_DIR}/dist/lib/${ANDROID_ABI}/libwolfssl.a")
|
"${CMAKE_SOURCE_DIR}/libs/wolfssl-lib/${ANDROID_ABI}/libwolfssl.a")
|
||||||
|
|
||||||
# .h files are located at ./dist/lib/include/wolfssl, ./dist/lib/include/wolfssl/wolfcrypt
|
# .h files are located at ./libs/wolfssl-lib/include
|
||||||
include_directories( jni/include
|
include_directories( jni/include
|
||||||
${CMAKE_SOURCE_DIR}/dist/lib/include )
|
${CMAKE_SOURCE_DIR}/libs/wolfssl-lib/include )
|
||||||
|
|
||||||
# set(distribution_DIR ${CMAKE_SOURCE_DIR}/dist)
|
# set(distribution_DIR ${CMAKE_SOURCE_DIR}/dist)
|
||||||
|
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
# create a build target of "wolfcrypt-jni"
|
|
||||||
# library is a SHARED (not STATIC)
|
|
||||||
# add all the source code
|
|
||||||
add_library(wolfcrypt-jni SHARED
|
|
||||||
jni/jni_aes.c
|
|
||||||
jni/jni_asn.c
|
|
||||||
jni/jni_chacha.c
|
|
||||||
jni/jni_curve25519.c
|
|
||||||
jni/jni_des3.c
|
|
||||||
jni/jni_dh.c
|
|
||||||
jni/jni_ecc.c
|
|
||||||
jni/jni_ed25519.c
|
|
||||||
jni/jni_error.c
|
|
||||||
# jni/jni_fips.c
|
|
||||||
jni/jni_hmac.c
|
|
||||||
jni/jni_logging.c
|
|
||||||
jni/jni_md5.c
|
|
||||||
jni/jni_native_struct.c
|
|
||||||
jni/jni_rng.c
|
|
||||||
jni/jni_rsa.c
|
|
||||||
jni/jni_sha.c)
|
|
||||||
|
|
||||||
# .h files are located at wolfssl/wolfssl, wolfssl/wolfssl/wolfcrypt
|
|
||||||
# the source files are looking for wolfssl/wolfcrypt/settings.h
|
|
||||||
# wolfssl-git/wolfssl/wolfcrypt/settings.h
|
|
||||||
# therefore give the root of the search path to the find the files
|
|
||||||
include_directories( jni/include
|
|
||||||
../wolfssl-oem/wolfssl-git
|
|
||||||
../wolfssl-oem/wolfssl-git/wolfssl
|
|
||||||
../wolfssl-oem/wolfssl-git/wolfssl/wolfcrypt )
|
|
||||||
|
|
||||||
# include_directories( jni/include
|
|
||||||
# ../wolfssl-oem/wolfssl-git
|
|
||||||
# ../wolfssl-oem/wolfssl-git/wolfssl
|
|
||||||
# ../wolfssl-oem/wolfssl-git/wolfssl/wolfcrypt )
|
|
||||||
|
|
||||||
set(distribution_DIR ${CMAKE_SOURCE_DIR}/dist)
|
|
||||||
set_target_properties(wolfcrypt-jni
|
|
||||||
PROPERTIES
|
|
||||||
ARCHIVE_OUTPUT_DIRECTORY
|
|
||||||
"${CMAKE_SOURCE_DIR}/dist/lib/${ANDROID_ABI}")
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
DIST README
|
||||||
|
===========
|
||||||
|
|
||||||
|
|
||||||
|
* This folder is *not* auto generated. As of right now files are copied from the ./bulld/intermediates/cmake/release/obj/... location.
|
Loading…
Reference in New Issue