update to cvs head srtp

This commit is contained in:
Anthony Minessale committed 2013-03-31 21:27:19 -05:00
1 parent aad4da5b71
commit 72e2d183c1
100 files changed
+4732 -1509

No files matched your search

+4 -4
View File
@@ -8,7 +8,7 @@
*/
/*
*
* Copyright(c) 2001-2005 Cisco Systems, Inc.
* Copyright(c) 2001-2006 Cisco Systems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -47,7 +47,7 @@
/* single, global prng structure */
static ctr_prng_t ctr_prng;
ctr_prng_t ctr_prng;
err_status_t
ctr_prng_init(rand_source_func_t random_source) {
@@ -66,7 +66,7 @@ ctr_prng_init(rand_source_func_t random_source) {
return status;
/* initialize aes ctr context with random key */
status = aes_icm_context_init(&ctr_prng.state, tmp_key);
status = aes_icm_context_init(&ctr_prng.state, tmp_key, 30);
if (status)
return status;
@@ -92,7 +92,7 @@ ctr_prng_get_octet_string(void *dest, uint32_t len) {
/*
* write prng output
*/
status = aes_icm_output(&ctr_prng.state, dest, len);
status = aes_icm_output(&ctr_prng.state, (uint8_t*)dest, len);
if (status)
return status;
+11 -11
View File
@@ -8,7 +8,7 @@
*/
/*
*
* Copyright(c) 2001-2005 Cisco Systems, Inc.
* Copyright(c) 2001-2006 Cisco Systems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -47,11 +47,11 @@
/* single, global prng structure */
static x917_prng_t x917_prng;
x917_prng_t x917_prng;
err_status_t
x917_prng_init(rand_source_func_t random_source) {
v128_t tmp_key;
uint8_t tmp_key[16];
err_status_t status;
/* initialize output count to zero */
@@ -61,12 +61,12 @@ x917_prng_init(rand_source_func_t random_source) {
x917_prng.rand = random_source;
/* initialize secret key from random source */
status = random_source((uint8_t *)&tmp_key, 16);
status = random_source(tmp_key, 16);
if (status)
return status;
/* expand aes key */
aes_expand_encryption_key(&tmp_key, x917_prng.key);
aes_expand_encryption_key(tmp_key, 16, &x917_prng.key);
/* initialize prng state from random source */
status = x917_prng.rand((uint8_t *)&x917_prng.state, 16);
@@ -80,7 +80,7 @@ err_status_t
x917_prng_get_octet_string(uint8_t *dest, uint32_t len) {
uint32_t t;
v128_t buffer;
int i, tail_len;
uint32_t i, tail_len;
err_status_t status;
/*
@@ -99,7 +99,7 @@ x917_prng_get_octet_string(uint8_t *dest, uint32_t len) {
t = (uint32_t)time(NULL);
/* loop until we have output enough data */
for (i=0; (uint32_t)i < len/16; i++) {
for (i=0; i < len/16; i++) {
/* exor time into state */
x917_prng.state.v32[0] ^= t;
@@ -108,7 +108,7 @@ x917_prng_get_octet_string(uint8_t *dest, uint32_t len) {
v128_copy(&buffer, &x917_prng.state);
/* apply aes to buffer */
aes_encrypt(&buffer, x917_prng.key);
aes_encrypt(&buffer, &x917_prng.key);
/* write data to output */
*dest++ = buffer.v8[0];
@@ -132,7 +132,7 @@ x917_prng_get_octet_string(uint8_t *dest, uint32_t len) {
buffer.v32[0] ^= t;
/* encrypt buffer */
aes_encrypt(&buffer, x917_prng.key);
aes_encrypt(&buffer, &x917_prng.key);
/* copy buffer into state */
v128_copy(&x917_prng.state, &buffer);
@@ -150,7 +150,7 @@ x917_prng_get_octet_string(uint8_t *dest, uint32_t len) {
v128_copy(&buffer, &x917_prng.state);
/* apply aes to buffer */
aes_encrypt(&buffer, x917_prng.key);
aes_encrypt(&buffer, &x917_prng.key);
/* write data to output */
for (i=0; i < tail_len; i++) {
@@ -163,7 +163,7 @@ x917_prng_get_octet_string(uint8_t *dest, uint32_t len) {
buffer.v32[0] ^= t;
/* encrypt buffer */
aes_encrypt(&buffer, x917_prng.key);
aes_encrypt(&buffer, &x917_prng.key);
/* copy buffer into state */
v128_copy(&x917_prng.state, &buffer);
+51 -11
View File
@@ -8,7 +8,7 @@
*/
/*
*
* Copyright(c) 2001-2005 Cisco Systems, Inc.
* Copyright(c) 2001-2006 Cisco Systems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -43,18 +43,36 @@
*/
#include "config.h"
#include "rand_source.h"
#ifdef DEV_URANDOM
# include <fcntl.h> /* for open() */
# include <unistd.h> /* for close() */
#elif defined(HAVE_RAND_S)
# define _CRT_RAND_S
# include <stdlib.h>
#else
# include <stdio.h>
#endif
/* global dev_rand_fdes is file descriptor for /dev/random */
#include "rand_source.h"
static int dev_random_fdes = -1;
/*
* global dev_rand_fdes is file descriptor for /dev/random
*
* This variable is also used to indicate that the random source has
* been initialized. When this variable is set to the value of the
* #define RAND_SOURCE_NOT_READY, it indicates that the random source
* is not ready to be used. The value of the #define
* RAND_SOURCE_READY is for use whenever that variable is used as an
* indicator of the state of the random source, but not as a file
* descriptor.
*/
#define RAND_SOURCE_NOT_READY (-1)
#define RAND_SOURCE_READY (17)
static int dev_random_fdes = RAND_SOURCE_NOT_READY;
err_status_t
@@ -68,10 +86,12 @@ rand_source_init(void) {
dev_random_fdes = open(DEV_URANDOM, O_RDONLY);
if (dev_random_fdes < 0)
return err_status_init_fail;
#elif defined(HAVE_RAND_S)
dev_random_fdes = RAND_SOURCE_READY;
#else
/* no random source available; let the user know */
fprintf(stderr, "WARNING: no real random source present!\n");
dev_random_fdes = 17;
dev_random_fdes = RAND_SOURCE_READY;
#endif
return err_status_ok;
}
@@ -85,25 +105,45 @@ rand_source_get_octet_string(void *dest, uint32_t len) {
* written
*/
#ifdef DEV_URANDOM
if (read(dev_random_fdes, dest, len) != len)
return err_status_fail;
uint8_t *dst = (uint8_t *)dest;
while (len)
{
ssize_t num_read = read(dev_random_fdes, dst, len);
if (num_read <= 0 || num_read > len)
return err_status_fail;
len -= num_read;
dst += num_read;
}
#elif defined(HAVE_RAND_S)
uint8_t *dst = (uint8_t *)dest;
while (len)
{
unsigned int val;
errno_t err = rand_s(&val);
if (err != 0)
return err_status_fail;
*dst++ = val & 0xff;
len--;
}
#else
/* Generic C-library (rand()) version */
/* This is a random source of last resort */
uint8_t *dst = dest;
uint8_t *dst = (uint8_t *)dest;
while (len)
{
int val = rand();
/* rand() returns 0-32767 (ugh) */
/* Is this a good enough way to get random bytes?
It is if it passes FIPS-140... */
*dst++ = (uint8_t)(val & 0xff);
*dst++ = val & 0xff;
len--;
}
#endif
return err_status_ok;
}
err_status_t
rand_source_deinit(void) {
if (dev_random_fdes < 0)
@@ -112,7 +152,7 @@ rand_source_deinit(void) {
#ifdef DEV_URANDOM
close(dev_random_fdes);
#endif
dev_random_fdes = -1;
dev_random_fdes = RAND_SOURCE_NOT_READY;
return err_status_ok;
}