41 #ifndef _UCOMMON_SECURE_H_
42 #define _UCOMMON_SECURE_H_
44 #ifndef _UCOMMON_CONFIG_H_
48 #ifndef _UCOMMON_UCOMMON_H_
52 #define MAX_CIPHER_KEYSIZE 512
53 #define MAX_DIGEST_HASHSIZE 512
68 typedef enum {OK=0, INVALID, MISSING_CERTIFICATE, MISSING_PRIVATEKEY, INVALID_CERTIFICATE, INVALID_AUTHORITY, INVALID_PEERNAME, INVALID_CIPHER} error_t;
74 SYSTEM_CERTIFICATES, SYSTEM_KEYS} path_t;
82 inline secure() {error = OK;};
115 static bool init(
const char *program = NULL);
124 static bool fips(
const char *program = NULL);
139 static int oscerts(
const char *path);
161 static server_t server(
const char *authority = NULL);
169 static client_t client(
const char *authority = NULL);
177 static client_t user(
const char *authority);
184 static void cipher(
secure *context,
const char *ciphers);
191 {
return error == OK;};
204 static void uuid(
char *
string);
208 template <
typename T>
209 inline static void erase(T *
object)
210 {memset(
object, 0,
sizeof(
object));
delete object;}
240 void open(
const char *host,
const char *service,
size_t size = 536);
248 size_t _pull(
char *address,
size_t size);
254 inline bool is_secure(
void)
255 {
return bio != NULL;};
270 typedef enum {ENCRYPT = 1, DECRYPT = 0} mode_t;
285 const void *algotype;
290 const void *hashtype;
297 unsigned char keybuf[MAX_CIPHER_KEYSIZE / 8], ivbuf[MAX_CIPHER_KEYSIZE / 8];
300 size_t keysize, blksize;
302 Key(
const char *cipher);
305 void set(
const char *cipher);
307 void set(
const char *cipher,
const char *digest);
309 void assign(
const char *key,
size_t size,
const unsigned char *salt,
unsigned rounds);
312 Key(
const char *cipher,
const char *digest,
const char *text,
size_t size = 0,
const unsigned char *salt = NULL,
unsigned rounds = 1);
314 Key(
const char *cipher,
const char *digest);
318 void assign(
const char *key,
size_t size = 0);
322 inline size_t size(
void)
325 inline size_t iosize(
void)
328 inline operator bool()
329 {
return keysize > 0;};
331 inline bool operator!()
332 {
return keysize == 0;};
334 inline Key& operator=(
const char *pass)
335 {assign(pass);
return *
this;};
337 static void options(
const unsigned char *salt = NULL,
unsigned rounds = 1);
344 size_t bufsize, bufpos;
346 unsigned char *bufaddr;
350 virtual void push(
unsigned char *address,
size_t size);
357 Cipher(
key_t key, mode_t mode,
unsigned char *address = NULL,
size_t size = 0);
361 void set(
unsigned char *address,
size_t size = 0);
363 void set(
key_t key, mode_t mode,
unsigned char *address,
size_t size = 0);
379 size_t put(
const unsigned char *data,
size_t size);
387 size_t puts(
const char *
string);
400 size_t pad(
const unsigned char *address,
size_t size);
410 size_t process(
unsigned char *address,
size_t size,
bool flag =
false);
412 inline size_t size(
void)
415 inline size_t pos(
void)
418 inline size_t align(
void)
419 {
return keys.iosize();};
426 static bool is(
const char *name);
441 const void *hashtype;
446 unsigned char buffer[MAX_DIGEST_HASHSIZE / 8];
447 char textbuf[MAX_DIGEST_HASHSIZE / 8 + 1];
459 inline bool puts(
const char *str)
460 {
return put(str, strlen(str));};
462 bool put(
const void *memory,
size_t size);
464 inline unsigned size()
const
467 const unsigned char *
get(void);
469 const char *c_str(
void);
472 {
return String(c_str());};
475 {
return String(c_str());};
477 void set(
const char *id);
479 inline void operator=(
const char *
id)
482 inline bool operator *=(
const char *text)
483 {
return puts(text);};
485 inline bool operator +=(
const char *text)
486 {
return puts(text);};
488 inline const char *operator*()
491 inline bool operator!()
const
492 {
return !bufsize && context == NULL;};
494 inline operator bool()
const
495 {
return bufsize > 0 || context != NULL;};
502 void recycle(
bool binary =
false);
514 static bool is(
const char *name);
516 static void uuid(
char *
string,
const char *name,
const unsigned char *ns = NULL);
518 static String uuid(
const char *name,
const unsigned char *ns = NULL);
535 static bool seed(
const unsigned char *buffer,
size_t size);
540 static void seed(
void);
550 static size_t key(
unsigned char *memory,
size_t size);
560 static size_t fill(
unsigned char *memory,
size_t size);
566 static int get(void);
574 static int get(
int min,
int max);
580 static double real(
void);
588 static double real(
double min,
double max);
595 static bool status(
void);
601 static void uuid(
char *
string);
626 inline void zerofill(
void *
addr,
size_t size)
628 ::memset(addr, 0, size);
631 #if defined(OLD_STDCPP) || defined(NEW_STDCPP)
658 void open(
const char *host,
const char *service,
size_t size = 536);
666 ssize_t _write(
const char *address,
size_t size);
668 ssize_t _read(
char *address,
size_t size);
672 inline void flush(
void)
675 inline bool is_secure(
void)
676 {
return bio != NULL;}