CyaSSL is an SSL library for devices like mbed.

Dependents:   cyassl-client Sync

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-2009 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 "arc4.h"
00027 
00028 #ifdef __cplusplus
00029     extern "C" {
00030 #endif
00031 
00032 
00033 #if defined(USE_WINDOWS_API)
00034     #if defined(_WIN64)
00035         typedef unsigned __int64 ProviderHandle;
00036         /* type HCRYPTPROV, avoid #include <windows.h> */
00037     #else
00038         typedef unsigned long ProviderHandle;
00039     #endif
00040 #endif
00041 
00042 
00043 /* OS specific seeder */
00044 typedef struct OS_Seed {
00045     #if defined(USE_WINDOWS_API)
00046         ProviderHandle handle;
00047     #else
00048         int fd;
00049     #endif
00050 } OS_Seed;
00051 
00052 int GenerateSeed(OS_Seed* os, byte* seed, word32 sz);
00053 
00054 
00055 /* secure Random Nnumber Generator */
00056 typedef struct RNG {
00057     OS_Seed seed;
00058     Arc4    cipher;
00059 } RNG;
00060 
00061 
00062 int  InitRng(RNG*);
00063 void RNG_GenerateBlock(RNG*, byte*, word32 sz);
00064 byte RNG_GenerateByte(RNG*);
00065 
00066 
00067 #ifdef __cplusplus
00068     } /* extern "C" */
00069 #endif
00070 
00071 #endif /* CTAO_CRYPT_RANDOM_H */
00072