M7350v7_en_gpl
This commit is contained in:
194
wlan/8192es/DriverSrcPkg/Users/wsc/portingssl/crypto/aes/aes_cbc.c
Executable file
194
wlan/8192es/DriverSrcPkg/Users/wsc/portingssl/crypto/aes/aes_cbc.c
Executable file
@ -0,0 +1,194 @@
|
||||
/* crypto/aes/aes_cbc.c -*- mode:C; c-file-style: "eay" -*- */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2002 The OpenSSL Project. 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED 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 THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS 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.
|
||||
* ====================================================================
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AES_DEBUG
|
||||
# ifndef NDEBUG
|
||||
# define NDEBUG
|
||||
# endif
|
||||
#endif
|
||||
#include <assert.h>
|
||||
|
||||
#include <openssl/aes.h>
|
||||
#include "aes_locl.h"
|
||||
|
||||
//for debug sean
|
||||
#if 0
|
||||
static void debug_out(unsigned char *label, unsigned char *data, int data_length)
|
||||
{
|
||||
int i,j;
|
||||
int num_blocks;
|
||||
int block_remainder;
|
||||
|
||||
num_blocks = data_length >> 4;
|
||||
block_remainder = data_length & 15;
|
||||
|
||||
if (label)
|
||||
printf("%s\n", label);
|
||||
|
||||
if (data==NULL || data_length==0)
|
||||
return;
|
||||
|
||||
for (i=0; i<num_blocks; i++) {
|
||||
printf("\t");
|
||||
for (j=0; j<16; j++)
|
||||
printf("%02x ", data[j + (i<<4)]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (block_remainder > 0) {
|
||||
printf("\t");
|
||||
for (j=0; j<block_remainder; j++)
|
||||
printf("%02x ", data[j+(num_blocks<<4)]);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(OPENSSL_FIPS_AES_ASM)
|
||||
void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
const unsigned long length, const AES_KEY *key,
|
||||
unsigned char *ivec, const int enc) {
|
||||
|
||||
unsigned long n;
|
||||
unsigned long len = length;
|
||||
unsigned char tmp[AES_BLOCK_SIZE];
|
||||
const unsigned char *iv = ivec;
|
||||
|
||||
assert(in && out && key && ivec);
|
||||
assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc));
|
||||
|
||||
if (AES_ENCRYPT == enc) {
|
||||
//for debug sean
|
||||
#if 0
|
||||
printf("<<----------%s %d------------>>\n", __FUNCTION__, __LINE__);
|
||||
printf("<<----------rounds = %d------------>>\n", key->rounds);
|
||||
debug_out("<--in-->", in, length);
|
||||
debug_out("<--iv-->", ivec, AES_BLOCK_SIZE);
|
||||
#endif
|
||||
while (len >= AES_BLOCK_SIZE) {
|
||||
for(n=0; n < AES_BLOCK_SIZE; ++n)
|
||||
out[n] = in[n] ^ iv[n];
|
||||
AES_encrypt(out, out, key);
|
||||
iv = out;
|
||||
len -= AES_BLOCK_SIZE;
|
||||
in += AES_BLOCK_SIZE;
|
||||
out += AES_BLOCK_SIZE;
|
||||
}
|
||||
if (len) {
|
||||
for(n=0; n < len; ++n)
|
||||
out[n] = in[n] ^ iv[n];
|
||||
for(n=len; n < AES_BLOCK_SIZE; ++n)
|
||||
out[n] = iv[n];
|
||||
AES_encrypt(out, out, key);
|
||||
iv = out;
|
||||
}
|
||||
memcpy(ivec,iv,AES_BLOCK_SIZE);
|
||||
} else if (in != out) {
|
||||
//for debug sean
|
||||
#if 0
|
||||
printf("<<----------%s %d------------>>\n", __FUNCTION__, __LINE__);
|
||||
printf("<<----------rounds = %d------------>>\n", key->rounds);
|
||||
debug_out("<--in-->", in, length);
|
||||
debug_out("<--iv-->", ivec, AES_BLOCK_SIZE);
|
||||
#endif
|
||||
while (len >= AES_BLOCK_SIZE) {
|
||||
AES_decrypt(in, out, key);
|
||||
for(n=0; n < AES_BLOCK_SIZE; ++n)
|
||||
out[n] ^= iv[n];
|
||||
iv = in;
|
||||
len -= AES_BLOCK_SIZE;
|
||||
in += AES_BLOCK_SIZE;
|
||||
out += AES_BLOCK_SIZE;
|
||||
}
|
||||
if (len) {
|
||||
AES_decrypt(in,tmp,key);
|
||||
for(n=0; n < len; ++n)
|
||||
out[n] = tmp[n] ^ iv[n];
|
||||
iv = in;
|
||||
}
|
||||
memcpy(ivec,iv,AES_BLOCK_SIZE);
|
||||
} else {
|
||||
//for debug sean
|
||||
#if 0
|
||||
printf("<<----------%s %d------------>>\n", __FUNCTION__, __LINE__);
|
||||
printf("<<----------rounds = %d------------>>\n", key->rounds);
|
||||
debug_out("<--in-->", in, length);
|
||||
debug_out("<--iv-->", ivec, AES_BLOCK_SIZE);
|
||||
#endif
|
||||
while (len >= AES_BLOCK_SIZE) {
|
||||
memcpy(tmp, in, AES_BLOCK_SIZE);
|
||||
AES_decrypt(in, out, key);
|
||||
for(n=0; n < AES_BLOCK_SIZE; ++n)
|
||||
out[n] ^= ivec[n];
|
||||
memcpy(ivec, tmp, AES_BLOCK_SIZE);
|
||||
len -= AES_BLOCK_SIZE;
|
||||
in += AES_BLOCK_SIZE;
|
||||
out += AES_BLOCK_SIZE;
|
||||
}
|
||||
if (len) {
|
||||
memcpy(tmp, in, AES_BLOCK_SIZE);
|
||||
AES_decrypt(tmp, out, key);
|
||||
for(n=0; n < len; ++n)
|
||||
out[n] ^= ivec[n];
|
||||
for(n=len; n < AES_BLOCK_SIZE; ++n)
|
||||
out[n] = tmp[n];
|
||||
memcpy(ivec, tmp, AES_BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
//for debug sean
|
||||
#if 0
|
||||
debug_out("<--in-->", in, length);
|
||||
debug_out("<--out-->", out-length, length);
|
||||
debug_out("<--iv-->", ivec, AES_BLOCK_SIZE);
|
||||
#endif
|
||||
}
|
||||
#endif
|
85
wlan/8192es/DriverSrcPkg/Users/wsc/portingssl/crypto/aes/aes_locl.h
Executable file
85
wlan/8192es/DriverSrcPkg/Users/wsc/portingssl/crypto/aes/aes_locl.h
Executable file
@ -0,0 +1,85 @@
|
||||
/* crypto/aes/aes.h -*- mode:C; c-file-style: "eay" -*- */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2002 The OpenSSL Project. 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED 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 THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS 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.
|
||||
* ====================================================================
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HEADER_AES_LOCL_H
|
||||
#define HEADER_AES_LOCL_H
|
||||
|
||||
#include <openssl/e_os2.h>
|
||||
|
||||
#ifdef OPENSSL_NO_AES
|
||||
#error AES is disabled.
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(_MSC_VER) && !defined(_M_IA64) && !defined(OPENSSL_SYS_WINCE)
|
||||
# define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
|
||||
# define GETU32(p) SWAP(*((u32 *)(p)))
|
||||
# define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
|
||||
#else
|
||||
# define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
|
||||
# define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
|
||||
#endif
|
||||
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned char u8;
|
||||
|
||||
#define MAXKC (256/32)
|
||||
#define MAXKB (256/8)
|
||||
#define MAXNR 14
|
||||
|
||||
/* This controls loop-unrolling in aes_core.c */
|
||||
#undef FULL_UNROLL
|
||||
|
||||
#endif /* !HEADER_AES_LOCL_H */
|
366
wlan/8192es/DriverSrcPkg/Users/wsc/portingssl/crypto/aes/fips.c
Executable file
366
wlan/8192es/DriverSrcPkg/Users/wsc/portingssl/crypto/aes/fips.c
Executable file
@ -0,0 +1,366 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2003 The OpenSSL Project. 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED 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 THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <openssl/fips.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/fips_rand.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/hmac.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include "fips_locl.h"
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 1024
|
||||
#endif
|
||||
|
||||
static int fips_selftest_fail;
|
||||
static int fips_mode;
|
||||
static const void *fips_rand_check;
|
||||
|
||||
static void fips_set_mode(int onoff)
|
||||
{
|
||||
int owning_thread = fips_is_owning_thread();
|
||||
|
||||
if (fips_is_started())
|
||||
{
|
||||
if (!owning_thread) fips_w_lock();
|
||||
fips_mode = onoff;
|
||||
if (!owning_thread) fips_w_unlock();
|
||||
}
|
||||
}
|
||||
|
||||
static void fips_set_rand_check(const void *rand_check)
|
||||
{
|
||||
int owning_thread = fips_is_owning_thread();
|
||||
|
||||
if (fips_is_started())
|
||||
{
|
||||
if (!owning_thread) fips_w_lock();
|
||||
fips_rand_check = rand_check;
|
||||
if (!owning_thread) fips_w_unlock();
|
||||
}
|
||||
}
|
||||
|
||||
int FIPS_mode(void)
|
||||
{
|
||||
int ret = 0;
|
||||
int owning_thread = fips_is_owning_thread();
|
||||
|
||||
if (fips_is_started())
|
||||
{
|
||||
if (!owning_thread) fips_r_lock();
|
||||
ret = fips_mode;
|
||||
if (!owning_thread) fips_r_unlock();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
const void *FIPS_rand_check(void)
|
||||
{
|
||||
const void *ret = 0;
|
||||
int owning_thread = fips_is_owning_thread();
|
||||
|
||||
if (fips_is_started())
|
||||
{
|
||||
if (!owning_thread) fips_r_lock();
|
||||
ret = fips_rand_check;
|
||||
if (!owning_thread) fips_r_unlock();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FIPS_selftest_failed(void)
|
||||
{
|
||||
int ret = 0;
|
||||
if (fips_is_started())
|
||||
{
|
||||
int owning_thread = fips_is_owning_thread();
|
||||
|
||||
if (!owning_thread) fips_r_lock();
|
||||
ret = fips_selftest_fail;
|
||||
if (!owning_thread) fips_r_unlock();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FIPS_selftest()
|
||||
{
|
||||
ERR_load_crypto_strings();
|
||||
|
||||
return FIPS_selftest_sha1()
|
||||
&& FIPS_selftest_hmac()
|
||||
&& FIPS_selftest_aes()
|
||||
&& FIPS_selftest_des()
|
||||
&& FIPS_selftest_rsa()
|
||||
&& FIPS_selftest_dsa();
|
||||
}
|
||||
|
||||
#ifndef HMAC_EXT
|
||||
#define HMAC_EXT "sha1"
|
||||
#endif
|
||||
|
||||
static char key[]="etaonrishdlcupfm";
|
||||
|
||||
#ifdef OPENSSL_PIC
|
||||
int DSO_pathbyaddr(void *addr,char *path,int sz);
|
||||
|
||||
static int FIPS_check_dso()
|
||||
{
|
||||
unsigned char buf[1024];
|
||||
char path [512];
|
||||
unsigned char mdbuf[EVP_MAX_MD_SIZE];
|
||||
FILE *f;
|
||||
HMAC_CTX hmac;
|
||||
int len,n;
|
||||
|
||||
len = DSO_pathbyaddr(NULL,path,sizeof(path)-sizeof(HMAC_EXT));
|
||||
if (len<=0)
|
||||
{
|
||||
FIPSerr(FIPS_F_FIPS_CHECK_DSO,FIPS_R_NO_DSO_PATH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
f=fopen(path,"rb");
|
||||
if(!f)
|
||||
{
|
||||
FIPSerr(FIPS_F_FIPS_CHECK_EXE,FIPS_R_CANNOT_READ_EXE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
HMAC_Init(&hmac,key,strlen(key),EVP_sha1());
|
||||
while(!feof(f))
|
||||
{
|
||||
n=fread(buf,1,sizeof buf,f);
|
||||
if(ferror(f))
|
||||
{
|
||||
clearerr(f);
|
||||
fclose(f);
|
||||
FIPSerr(FIPS_F_FIPS_CHECK_EXE,FIPS_R_CANNOT_READ_EXE);
|
||||
return 0;
|
||||
}
|
||||
if (n) HMAC_Update(&hmac,buf,n);
|
||||
}
|
||||
fclose(f);
|
||||
HMAC_Final(&hmac,mdbuf,&n);
|
||||
HMAC_CTX_cleanup(&hmac);
|
||||
|
||||
path[len-1]='.';
|
||||
strcpy(path+len,HMAC_EXT);
|
||||
f=fopen(path,"rb");
|
||||
if(!f || fread(buf,1,20,f) != 20)
|
||||
{
|
||||
if (f) fclose(f);
|
||||
FIPSerr(FIPS_F_FIPS_CHECK_EXE,FIPS_R_CANNOT_READ_EXE_DIGEST);
|
||||
return 0;
|
||||
}
|
||||
fclose(f);
|
||||
if(memcmp(buf,mdbuf,20))
|
||||
{
|
||||
FIPSerr(FIPS_F_FIPS_CHECK_EXE,FIPS_R_EXE_DIGEST_DOES_NOT_MATCH);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
static int FIPS_check_exe(const char *path)
|
||||
{
|
||||
unsigned char buf[1024];
|
||||
char p2[PATH_MAX];
|
||||
unsigned int n;
|
||||
unsigned char mdbuf[EVP_MAX_MD_SIZE];
|
||||
FILE *f;
|
||||
HMAC_CTX hmac;
|
||||
const char *sha1_fmt="%s."HMAC_EXT;
|
||||
|
||||
f=fopen(path,"rb");
|
||||
#ifdef __CYGWIN32__
|
||||
/* cygwin scrupulously strips .exe extentions:-( as of now it's
|
||||
actually no point to attempt above fopen, but we keep the call
|
||||
just in case the behavior changes in the future... */
|
||||
if (!f)
|
||||
{
|
||||
sha1_fmt="%s.exe."HMAC_EXT;
|
||||
BIO_snprintf(p2,sizeof p2,"%s.exe",path);
|
||||
f=fopen(p2,"rb");
|
||||
}
|
||||
#endif
|
||||
if(!f)
|
||||
{
|
||||
FIPSerr(FIPS_F_FIPS_CHECK_EXE,FIPS_R_CANNOT_READ_EXE);
|
||||
return 0;
|
||||
}
|
||||
HMAC_Init(&hmac,key,strlen(key),EVP_sha1());
|
||||
while(!feof(f))
|
||||
{
|
||||
n=fread(buf,1,sizeof buf,f);
|
||||
if(ferror(f))
|
||||
{
|
||||
clearerr(f);
|
||||
fclose(f);
|
||||
FIPSerr(FIPS_F_FIPS_CHECK_EXE,FIPS_R_CANNOT_READ_EXE);
|
||||
return 0;
|
||||
}
|
||||
if (n) HMAC_Update(&hmac,buf,n);
|
||||
}
|
||||
fclose(f);
|
||||
HMAC_Final(&hmac,mdbuf,&n);
|
||||
HMAC_CTX_cleanup(&hmac);
|
||||
BIO_snprintf(p2,sizeof p2,sha1_fmt,path);
|
||||
f=fopen(p2,"rb");
|
||||
if(!f || fread(buf,1,20,f) != 20)
|
||||
{
|
||||
if (f) fclose(f);
|
||||
FIPSerr(FIPS_F_FIPS_CHECK_EXE,FIPS_R_CANNOT_READ_EXE_DIGEST);
|
||||
return 0;
|
||||
}
|
||||
fclose(f);
|
||||
if(memcmp(buf,mdbuf,20))
|
||||
{
|
||||
FIPSerr(FIPS_F_FIPS_CHECK_EXE,FIPS_R_EXE_DIGEST_DOES_NOT_MATCH);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int FIPS_mode_set(int onoff,const char *path)
|
||||
{
|
||||
int fips_set_owning_thread();
|
||||
int fips_clear_owning_thread();
|
||||
int ret = 0;
|
||||
|
||||
fips_w_lock();
|
||||
fips_set_started();
|
||||
fips_set_owning_thread();
|
||||
|
||||
if(onoff)
|
||||
{
|
||||
unsigned char buf[24];
|
||||
|
||||
fips_selftest_fail = 0;
|
||||
|
||||
/* Don't go into FIPS mode twice, just so we can do automagic
|
||||
seeding */
|
||||
if(FIPS_mode())
|
||||
{
|
||||
FIPSerr(FIPS_F_FIPS_MODE_SET,FIPS_R_FIPS_MODE_ALREADY_SET);
|
||||
fips_selftest_fail = 1;
|
||||
ret = 0;
|
||||
goto end;
|
||||
}
|
||||
|
||||
#ifdef OPENSSL_PIC
|
||||
if(!FIPS_check_dso())
|
||||
#else
|
||||
if(!FIPS_check_exe(path))
|
||||
#endif
|
||||
{
|
||||
fips_selftest_fail = 1;
|
||||
ret = 0;
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* Perform RNG KAT before seeding */
|
||||
if (!FIPS_selftest_rng())
|
||||
{
|
||||
fips_selftest_fail = 1;
|
||||
ret = 0;
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* automagically seed PRNG if not already seeded */
|
||||
if(!FIPS_rand_seeded())
|
||||
{
|
||||
if(RAND_bytes(buf,sizeof buf) <= 0)
|
||||
{
|
||||
fips_selftest_fail = 1;
|
||||
ret = 0;
|
||||
goto end;
|
||||
}
|
||||
FIPS_set_prng_key(buf,buf+8);
|
||||
FIPS_rand_seed(buf+16,8);
|
||||
}
|
||||
|
||||
/* now switch into FIPS mode */
|
||||
fips_set_rand_check(FIPS_rand_method());
|
||||
RAND_set_rand_method(FIPS_rand_method());
|
||||
if(FIPS_selftest())
|
||||
fips_set_mode(1);
|
||||
else
|
||||
{
|
||||
fips_selftest_fail = 1;
|
||||
ret = 0;
|
||||
goto end;
|
||||
}
|
||||
ret = 1;
|
||||
goto end;
|
||||
}
|
||||
fips_set_mode(0);
|
||||
fips_selftest_fail = 0;
|
||||
ret = 1;
|
||||
end:
|
||||
fips_clear_owning_thread();
|
||||
fips_w_unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* here just to cause error codes to exist */
|
||||
static void dummy()
|
||||
{
|
||||
FIPSerr(FIPS_F_HASH_FINAL,FIPS_F_NON_FIPS_METHOD);
|
||||
FIPSerr(FIPS_F_HASH_FINAL,FIPS_R_FIPS_SELFTEST_FAILED);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
1269
wlan/8192es/DriverSrcPkg/Users/wsc/portingssl/crypto/aes/fips_aes_core.c
Executable file
1269
wlan/8192es/DriverSrcPkg/Users/wsc/portingssl/crypto/aes/fips_aes_core.c
Executable file
File diff suppressed because it is too large
Load Diff
85
wlan/8192es/DriverSrcPkg/Users/wsc/portingssl/crypto/aes/fips_aes_locl.h
Executable file
85
wlan/8192es/DriverSrcPkg/Users/wsc/portingssl/crypto/aes/fips_aes_locl.h
Executable file
@ -0,0 +1,85 @@
|
||||
/* crypto/aes/aes.h -*- mode:C; c-file-style: "eay" -*- */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2002 The OpenSSL Project. 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED 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 THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS 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.
|
||||
* ====================================================================
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HEADER_AES_LOCL_H
|
||||
#define HEADER_AES_LOCL_H
|
||||
|
||||
#include <openssl/e_os2.h>
|
||||
|
||||
#ifdef OPENSSL_NO_AES
|
||||
#error AES is disabled.
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(_MSC_VER) && !defined(_M_IA64) && !defined(OPENSSL_SYS_WINCE)
|
||||
# define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
|
||||
# define GETU32(p) SWAP(*((u32 *)(p)))
|
||||
# define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
|
||||
#else
|
||||
# define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
|
||||
# define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
|
||||
#endif
|
||||
|
||||
typedef unsigned long u32;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned char u8;
|
||||
|
||||
#define MAXKC (256/32)
|
||||
#define MAXKB (256/8)
|
||||
#define MAXNR 14
|
||||
|
||||
/* This controls loop-unrolling in aes_core.c */
|
||||
#undef FULL_UNROLL
|
||||
|
||||
#endif /* !HEADER_AES_LOCL_H */
|
70
wlan/8192es/DriverSrcPkg/Users/wsc/portingssl/crypto/aes/fips_locl.h
Executable file
70
wlan/8192es/DriverSrcPkg/Users/wsc/portingssl/crypto/aes/fips_locl.h
Executable file
@ -0,0 +1,70 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2003 The OpenSSL Project. 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED 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 THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* These are trampolines implemented in crypto/cryptlib.c */
|
||||
void fips_w_lock(void);
|
||||
void fips_w_unlock(void);
|
||||
void fips_r_lock(void);
|
||||
void fips_r_unlock(void);
|
||||
int fips_is_started(void);
|
||||
void fips_set_started(void);
|
||||
int fips_is_owning_thread(void);
|
||||
int fips_set_owning_thread(void);
|
||||
int fips_clear_owning_thread(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
Reference in New Issue
Block a user