69 lines
1.5 KiB
C++
69 lines
1.5 KiB
C++
// Copyright (c) 2013-2015 IONU Security, Inc. All rights reserved.
|
|
//
|
|
// DRBG class for deterministic random bit generation and predictable RSA keys
|
|
|
|
#ifndef eyedrbg_h
|
|
#define eyedrbg_h
|
|
|
|
#include <vector>
|
|
#include <openssl/evp.h>
|
|
|
|
#ifdef WIN32
|
|
# ifdef DLLEXPORT
|
|
# define LIBEYE_DLL __declspec(dllexport)
|
|
# else
|
|
# define LIBEYE_DLL __declspec(dllimport)
|
|
# endif
|
|
#else
|
|
#define LIBEYE_DLL
|
|
#endif
|
|
|
|
#define IONU_DRBG_BUFFER_LEN 32768
|
|
|
|
namespace sequencelogic {
|
|
|
|
|
|
class EyeDRBG {
|
|
public:
|
|
/**
|
|
* @constructor
|
|
* @param seed value for DRBG
|
|
* @param seed length
|
|
*/
|
|
LIBEYE_DLL EyeDRBG (const unsigned char* seed, size_t seedlen);
|
|
|
|
LIBEYE_DLL ~EyeDRBG ();
|
|
|
|
/**
|
|
* Generate an RSA key
|
|
* @param rsa pointer to OpenSSL RSA structure
|
|
* @return true for success
|
|
*/
|
|
LIBEYE_DLL bool GenerateDRBGRSAKey (RSA* rsa);
|
|
|
|
/**
|
|
* Generate an EC key
|
|
* @param eckey pointer to OpenSSL EC_KEY structure
|
|
* @return true for success
|
|
*/
|
|
LIBEYE_DLL bool GenerateDRBGECKey (EC_KEY *eckey);
|
|
|
|
/**
|
|
* Get bytes from pseudo random number generator
|
|
* @param bytes buffer to fill
|
|
* @param len number of bytes to get
|
|
*/
|
|
LIBEYE_DLL bool RandBytes (unsigned char* bytes, size_t len);
|
|
|
|
private:
|
|
unsigned char* _data; // Random data buffer
|
|
unsigned char _ctr; // Wrapping counter
|
|
size_t _pos; // Current position in buffer
|
|
void FillBuffer();
|
|
bool GenerateRSAPrime (BIGNUM *rsap);
|
|
};
|
|
|
|
|
|
} //namespce ionu
|
|
#endif
|