cyassl re-port with cellular comms, PSK test

Dependencies:   VodafoneUSBModem_bleedingedge2 mbed-rtos mbed-src

Committer:
ashleymills
Date:
Fri Apr 26 16:59:36 2013 +0000
Revision:
1:b211d97b0068
Parent:
0:e979170e02e7
nothing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 0:e979170e02e7 1 /* random.h
ashleymills 0:e979170e02e7 2 *
ashleymills 0:e979170e02e7 3 * Copyright (C) 2006-2012 Sawtooth Consulting Ltd.
ashleymills 0:e979170e02e7 4 *
ashleymills 0:e979170e02e7 5 * This file is part of CyaSSL.
ashleymills 0:e979170e02e7 6 *
ashleymills 0:e979170e02e7 7 * CyaSSL is free software; you can redistribute it and/or modify
ashleymills 0:e979170e02e7 8 * it under the terms of the GNU General Public License as published by
ashleymills 0:e979170e02e7 9 * the Free Software Foundation; either version 2 of the License, or
ashleymills 0:e979170e02e7 10 * (at your option) any later version.
ashleymills 0:e979170e02e7 11 *
ashleymills 0:e979170e02e7 12 * CyaSSL is distributed in the hope that it will be useful,
ashleymills 0:e979170e02e7 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ashleymills 0:e979170e02e7 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ashleymills 0:e979170e02e7 15 * GNU General Public License for more details.
ashleymills 0:e979170e02e7 16 *
ashleymills 0:e979170e02e7 17 * You should have received a copy of the GNU General Public License
ashleymills 0:e979170e02e7 18 * along with this program; if not, write to the Free Software
ashleymills 0:e979170e02e7 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
ashleymills 0:e979170e02e7 20 */
ashleymills 0:e979170e02e7 21
ashleymills 0:e979170e02e7 22
ashleymills 0:e979170e02e7 23 #ifndef CTAO_CRYPT_RANDOM_H
ashleymills 0:e979170e02e7 24 #define CTAO_CRYPT_RANDOM_H
ashleymills 0:e979170e02e7 25
ashleymills 0:e979170e02e7 26 #include <cyassl/ctaocrypt/types.h>
ashleymills 0:e979170e02e7 27
ashleymills 0:e979170e02e7 28 #ifndef NO_RC4
ashleymills 0:e979170e02e7 29 #include <cyassl/ctaocrypt/arc4.h>
ashleymills 0:e979170e02e7 30 #else
ashleymills 0:e979170e02e7 31 #include <cyassl/ctaocrypt/sha256.h>
ashleymills 0:e979170e02e7 32 #endif
ashleymills 0:e979170e02e7 33
ashleymills 0:e979170e02e7 34 #ifdef __cplusplus
ashleymills 0:e979170e02e7 35 extern "C" {
ashleymills 0:e979170e02e7 36 #endif
ashleymills 0:e979170e02e7 37
ashleymills 0:e979170e02e7 38
ashleymills 0:e979170e02e7 39 #if defined(USE_WINDOWS_API)
ashleymills 0:e979170e02e7 40 #if defined(_WIN64)
ashleymills 0:e979170e02e7 41 typedef unsigned __int64 ProviderHandle;
ashleymills 0:e979170e02e7 42 /* type HCRYPTPROV, avoid #include <windows.h> */
ashleymills 0:e979170e02e7 43 #else
ashleymills 0:e979170e02e7 44 typedef unsigned long ProviderHandle;
ashleymills 0:e979170e02e7 45 #endif
ashleymills 0:e979170e02e7 46 #endif
ashleymills 0:e979170e02e7 47
ashleymills 0:e979170e02e7 48
ashleymills 0:e979170e02e7 49 /* OS specific seeder */
ashleymills 0:e979170e02e7 50 typedef struct OS_Seed {
ashleymills 0:e979170e02e7 51 #if defined(USE_WINDOWS_API)
ashleymills 0:e979170e02e7 52 ProviderHandle handle;
ashleymills 0:e979170e02e7 53 #else
ashleymills 0:e979170e02e7 54 int fd;
ashleymills 0:e979170e02e7 55 #endif
ashleymills 0:e979170e02e7 56 } OS_Seed;
ashleymills 0:e979170e02e7 57
ashleymills 0:e979170e02e7 58
ashleymills 0:e979170e02e7 59 CYASSL_LOCAL
ashleymills 0:e979170e02e7 60 int GenerateSeed(OS_Seed* os, byte* seed, word32 sz);
ashleymills 0:e979170e02e7 61
ashleymills 0:e979170e02e7 62 #ifndef NO_RC4
ashleymills 0:e979170e02e7 63
ashleymills 0:e979170e02e7 64 #define CYASSL_RNG_CAVIUM_MAGIC 0xBEEF0004
ashleymills 0:e979170e02e7 65
ashleymills 0:e979170e02e7 66 /* secure Random Nnumber Generator */
ashleymills 0:e979170e02e7 67 typedef struct RNG {
ashleymills 0:e979170e02e7 68 OS_Seed seed;
ashleymills 0:e979170e02e7 69 Arc4 cipher;
ashleymills 0:e979170e02e7 70 #ifdef HAVE_CAVIUM
ashleymills 0:e979170e02e7 71 int devId; /* nitrox device id */
ashleymills 0:e979170e02e7 72 word32 magic; /* using cavium magic */
ashleymills 0:e979170e02e7 73 #endif
ashleymills 0:e979170e02e7 74 } RNG;
ashleymills 0:e979170e02e7 75
ashleymills 0:e979170e02e7 76
ashleymills 0:e979170e02e7 77 #ifdef HAVE_CAVIUM
ashleymills 0:e979170e02e7 78 CYASSL_API int InitRngCavium(RNG*, int);
ashleymills 0:e979170e02e7 79 #endif
ashleymills 0:e979170e02e7 80
ashleymills 0:e979170e02e7 81 #else /* NO_RC4 */
ashleymills 0:e979170e02e7 82
ashleymills 0:e979170e02e7 83 #define DBRG_SEED_LEN (440/8)
ashleymills 0:e979170e02e7 84
ashleymills 0:e979170e02e7 85 /* secure Random Nnumber Generator */
ashleymills 0:e979170e02e7 86 typedef struct RNG {
ashleymills 0:e979170e02e7 87 OS_Seed seed;
ashleymills 0:e979170e02e7 88
ashleymills 0:e979170e02e7 89 Sha256 sha;
ashleymills 0:e979170e02e7 90 byte digest[SHA256_DIGEST_SIZE];
ashleymills 0:e979170e02e7 91 byte V[DBRG_SEED_LEN];
ashleymills 0:e979170e02e7 92 byte C[DBRG_SEED_LEN];
ashleymills 0:e979170e02e7 93 word64 reseed_ctr;
ashleymills 0:e979170e02e7 94 } RNG;
ashleymills 0:e979170e02e7 95
ashleymills 0:e979170e02e7 96 #endif
ashleymills 0:e979170e02e7 97
ashleymills 0:e979170e02e7 98 CYASSL_API int InitRng(RNG*);
ashleymills 0:e979170e02e7 99 CYASSL_API void RNG_GenerateBlock(RNG*, byte*, word32 sz);
ashleymills 0:e979170e02e7 100 CYASSL_API byte RNG_GenerateByte(RNG*);
ashleymills 0:e979170e02e7 101
ashleymills 0:e979170e02e7 102 #ifdef NO_RC4
ashleymills 0:e979170e02e7 103 CYASSL_API void FreeRng(RNG*);
ashleymills 0:e979170e02e7 104 #endif
ashleymills 0:e979170e02e7 105
ashleymills 0:e979170e02e7 106 #ifdef __cplusplus
ashleymills 0:e979170e02e7 107 } /* extern "C" */
ashleymills 0:e979170e02e7 108 #endif
ashleymills 0:e979170e02e7 109
ashleymills 0:e979170e02e7 110 #endif /* CTAO_CRYPT_RANDOM_H */
ashleymills 0:e979170e02e7 111