cyassl re-port with cellular comms, PSK test

Dependencies:   VodafoneUSBModem_bleedingedge2 mbed-rtos mbed-src

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers random.h Source File

random.h

00001 /* random.h
00002  *
00003  * Copyright (C) 2006-2012 Sawtooth Consulting Ltd.
00004  *
00005  * This file is part of CyaSSL.
00006  *
00007  * CyaSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * CyaSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00020  */
00021 
00022 
00023 #ifndef CTAO_CRYPT_RANDOM_H
00024 #define CTAO_CRYPT_RANDOM_H
00025 
00026 #include <cyassl/ctaocrypt/types.h>
00027 
00028 #ifndef NO_RC4
00029     #include <cyassl/ctaocrypt/arc4.h>
00030 #else
00031     #include <cyassl/ctaocrypt/sha256.h>
00032 #endif
00033 
00034 #ifdef __cplusplus
00035     extern "C" {
00036 #endif
00037 
00038 
00039 #if defined(USE_WINDOWS_API)
00040     #if defined(_WIN64)
00041         typedef unsigned __int64 ProviderHandle;
00042         /* type HCRYPTPROV, avoid #include <windows.h> */
00043     #else
00044         typedef unsigned long ProviderHandle;
00045     #endif
00046 #endif
00047 
00048 
00049 /* OS specific seeder */
00050 typedef struct OS_Seed {
00051     #if defined(USE_WINDOWS_API)
00052         ProviderHandle handle;
00053     #else
00054         int fd;
00055     #endif
00056 } OS_Seed;
00057 
00058 
00059 CYASSL_LOCAL
00060 int GenerateSeed(OS_Seed* os, byte* seed, word32 sz);
00061 
00062 #ifndef NO_RC4
00063 
00064 #define CYASSL_RNG_CAVIUM_MAGIC 0xBEEF0004
00065 
00066 /* secure Random Nnumber Generator */
00067 typedef struct RNG {
00068     OS_Seed seed;
00069     Arc4    cipher;
00070 #ifdef HAVE_CAVIUM
00071     int    devId;           /* nitrox device id */
00072     word32 magic;           /* using cavium magic */
00073 #endif
00074 } RNG;
00075 
00076 
00077 #ifdef HAVE_CAVIUM
00078     CYASSL_API int  InitRngCavium(RNG*, int);
00079 #endif
00080 
00081 #else /* NO_RC4 */
00082 
00083 #define DBRG_SEED_LEN (440/8)
00084 
00085 /* secure Random Nnumber Generator */
00086 typedef struct RNG {
00087     OS_Seed seed;
00088 
00089     Sha256 sha;
00090     byte digest[SHA256_DIGEST_SIZE];
00091     byte V[DBRG_SEED_LEN];
00092     byte C[DBRG_SEED_LEN];
00093     word64 reseed_ctr;
00094 } RNG;
00095 
00096 #endif
00097 
00098 CYASSL_API int  InitRng(RNG*);
00099 CYASSL_API void RNG_GenerateBlock(RNG*, byte*, word32 sz);
00100 CYASSL_API byte RNG_GenerateByte(RNG*);
00101 
00102 #ifdef NO_RC4
00103     CYASSL_API void FreeRng(RNG*);
00104 #endif
00105 
00106 #ifdef __cplusplus
00107     } /* extern "C" */
00108 #endif
00109 
00110 #endif /* CTAO_CRYPT_RANDOM_H */
00111