Mercurial > hg > octave-lyh > gnulib-hg
changeset 10343:267a3a1ea894
lib/gc-gnulib.c: Indentation cleanup. Add some comments regarding Windows crypto stuff, from Mono.
author | Simon Josefsson <simon@josefsson.org> |
---|---|
date | Tue, 19 Aug 2008 17:58:08 +0200 |
parents | ba4baf9b29e2 |
children | a5fb0200cceb |
files | ChangeLog lib/gc-gnulib.c |
diffstat | 2 files changed, 35 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-08-19 Simon Josefsson <simon@josefsson.org> + + * lib/gc-gnulib.c: Indentation cleanup. Add some comments + regarding Windows crypto stuff, from Mono. + 2008-08-19 Adam Strzelecki <ono@java.pl> (tiny change) * lib/gc-gnulib.c: Use CRYPT_VERIFY_CONTEXT. Try to use Intel CSP
--- a/lib/gc-gnulib.c +++ b/lib/gc-gnulib.c @@ -92,11 +92,22 @@ { #ifdef GNULIB_GC_RANDOM # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - if(g_hProv) - CryptReleaseContext(g_hProv, 0); - if(!CryptAcquireContext(&g_hProv, NULL, NULL, PROV_INTEL_SEC, CRYPT_VERIFY_CONTEXT)) - if(!CryptAcquireContext(&g_hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFY_CONTEXT)) - return GC_RANDOM_ERROR; + if (g_hProv) + CryptReleaseContext (g_hProv, 0); + + /* There is no need to create a container for just random data, so + we can use CRYPT_VERIFY_CONTEXT (one call) see: + http://blogs.msdn.com/dangriff/archive/2003/11/19/51709.aspx */ + + /* We first try to use the Intel PIII RNG if drivers are present */ + if (!CryptAcquireContext (&g_hProv, NULL, NULL, + PROV_INTEL_SEC, CRYPT_VERIFY_CONTEXT)) + { + /* not a PIII or no drivers available, use default RSA CSP */ + if (!CryptAcquireContext (&g_hProv, NULL, NULL, + PROV_RSA_FULL, CRYPT_VERIFY_CONTEXT)) + return GC_RANDOM_ERROR; + } # endif #endif @@ -108,9 +119,9 @@ { #ifdef GNULIB_GC_RANDOM # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - if(g_hProv) + if (g_hProv) { - CryptReleaseContext(g_hProv, 0); + CryptReleaseContext (g_hProv, 0); g_hProv = 0; } # endif @@ -127,9 +138,9 @@ randomize (int level, char *data, size_t datalen) { #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - if(!g_hProv) + if (!g_hProv) return GC_RANDOM_ERROR; - CryptGenRandom(g_hProv, (DWORD)datalen, data); + CryptGenRandom (g_hProv, (DWORD) datalen, data); #else int fd; const char *device; @@ -214,9 +225,11 @@ { return; } + /* Ciphers. */ -typedef struct _gc_cipher_ctx { +typedef struct _gc_cipher_ctx +{ Gc_cipher alg; Gc_cipher_mode mode; #ifdef GNULIB_GC_ARCTWO @@ -359,7 +372,7 @@ char keyMaterial[RIJNDAEL_MAX_KEY_SIZE + 1]; for (i = 0; i < keylen; i++) - sprintf (&keyMaterial[2*i], "%02x", key[i] & 0xFF); + sprintf (&keyMaterial[2 * i], "%02x", key[i] & 0xFF); rc = rijndaelMakeKey (&ctx->aesEncKey, RIJNDAEL_DIR_ENCRYPT, keylen * 8, keyMaterial); @@ -417,7 +430,7 @@ char ivMaterial[2 * RIJNDAEL_MAX_IV_SIZE + 1]; for (i = 0; i < ivlen; i++) - sprintf (&ivMaterial[2*i], "%02x", iv[i] & 0xFF); + sprintf (&ivMaterial[2 * i], "%02x", iv[i] & 0xFF); rc = rijndaelCipherInit (&ctx->aesContext, RIJNDAEL_MODE_CBC, ivMaterial); @@ -456,7 +469,7 @@ case GC_CBC: for (; len >= ARCTWO_BLOCK_SIZE; len -= ARCTWO_BLOCK_SIZE, - data += ARCTWO_BLOCK_SIZE) + data += ARCTWO_BLOCK_SIZE) { size_t i; for (i = 0; i < ARCTWO_BLOCK_SIZE; i++) @@ -465,7 +478,7 @@ ARCTWO_BLOCK_SIZE); memcpy (ctx->arctwoIV, data, ARCTWO_BLOCK_SIZE); } - break; + break; default: return GC_INVALID_CIPHER; @@ -526,7 +539,7 @@ case GC_CBC: for (; len >= ARCTWO_BLOCK_SIZE; len -= ARCTWO_BLOCK_SIZE, - data += ARCTWO_BLOCK_SIZE) + data += ARCTWO_BLOCK_SIZE) { char tmpIV[ARCTWO_BLOCK_SIZE]; size_t i; @@ -595,7 +608,8 @@ #define MAX_DIGEST_SIZE 20 -typedef struct _gc_hash_ctx { +typedef struct _gc_hash_ctx +{ Gc_hash alg; Gc_hash_mode mode; char hash[MAX_DIGEST_SIZE];