removed trailing spaces ([[:space:]]+$)

This commit is contained in:
Martin Willi
2009-09-04 13:46:09 +02:00
parent 7d1b030446
commit 7daf5226b7
703 changed files with 10633 additions and 10633 deletions
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2009 Martin Willi
* Hochschule fuer Technik Rapperswil
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -25,17 +25,17 @@ typedef struct private_gcrypt_crypter_t private_gcrypt_crypter_t;
* Private data of gcrypt_crypter_t
*/
struct private_gcrypt_crypter_t {
/**
* Public part of this class.
*/
gcrypt_crypter_t public;
/**
* gcrypt cipher handle
*/
gcry_cipher_hd_t h;
/**
* gcrypt algorithm identifier
*/
@@ -49,7 +49,7 @@ static void decrypt(private_gcrypt_crypter_t *this, chunk_t data,
chunk_t iv, chunk_t *dst)
{
gcry_cipher_setiv(this->h, iv.ptr, iv.len);
if (dst)
{
*dst = chunk_alloc(data.len);
@@ -68,7 +68,7 @@ static void encrypt(private_gcrypt_crypter_t *this, chunk_t data,
chunk_t iv, chunk_t *dst)
{
gcry_cipher_setiv(this->h, iv.ptr, iv.len);
if (dst)
{
*dst = chunk_alloc(data.len);
@@ -86,7 +86,7 @@ static void encrypt(private_gcrypt_crypter_t *this, chunk_t data,
static size_t get_block_size(private_gcrypt_crypter_t *this)
{
size_t len = 0;
gcry_cipher_algo_info(this->alg, GCRYCTL_GET_BLKLEN, NULL, &len);
return len;
}
@@ -97,7 +97,7 @@ static size_t get_block_size(private_gcrypt_crypter_t *this)
static size_t get_key_size(private_gcrypt_crypter_t *this)
{
size_t len = 0;
gcry_cipher_algo_info(this->alg, GCRYCTL_GET_KEYLEN, NULL, &len);
return len;
}
@@ -129,7 +129,7 @@ gcrypt_crypter_t *gcrypt_crypter_create(encryption_algorithm_t algo,
int gcrypt_alg;
int mode = GCRY_CIPHER_MODE_CBC;
gcry_error_t err;
switch (algo)
{
case ENCR_DES:
@@ -227,9 +227,9 @@ gcrypt_crypter_t *gcrypt_crypter_create(encryption_algorithm_t algo,
default:
return NULL;
}
this = malloc_thing(private_gcrypt_crypter_t);
this->alg = gcrypt_alg;
err = gcry_cipher_open(&this->h, gcrypt_alg, mode, 0);
if (err)
@@ -239,14 +239,14 @@ gcrypt_crypter_t *gcrypt_crypter_create(encryption_algorithm_t algo,
free(this);
return NULL;
}
this->public.crypter_interface.encrypt = (void (*) (crypter_t *, chunk_t,chunk_t, chunk_t *))encrypt;
this->public.crypter_interface.decrypt = (void (*) (crypter_t *, chunk_t , chunk_t, chunk_t *))decrypt;
this->public.crypter_interface.get_block_size = (size_t (*) (crypter_t *))get_block_size;
this->public.crypter_interface.get_key_size = (size_t (*) (crypter_t *))get_key_size;
this->public.crypter_interface.set_key = (void (*) (crypter_t *,chunk_t))set_key;
this->public.crypter_interface.destroy = (void (*) (crypter_t *))destroy;
return &this->public;
}
@@ -29,7 +29,7 @@ typedef struct gcrypt_crypter_t gcrypt_crypter_t;
* Implementation of crypters using gcrypt.
*/
struct gcrypt_crypter_t {
/**
* The crypter_t interface.
*/
@@ -38,7 +38,7 @@ struct gcrypt_crypter_t {
/**
* Constructor to create gcrypt_crypter_t.
*
*
* @param algo algorithm to implement
* @param key_size key size in bytes
* @return gcrypt_crypter_t, NULL if not supported
+26 -26
View File
@@ -278,7 +278,7 @@ static u_int8_t group18_modulus[] = {
typedef struct modulus_entry_t modulus_entry_t;
/**
/**
* Entry of the modulus list.
*/
struct modulus_entry_t {
@@ -312,7 +312,7 @@ static modulus_entry_t modulus_entries[] = {
static modulus_entry_t *find_entry(diffie_hellman_group_t group)
{
int i;
for (i = 0; i < countof(modulus_entries); i++)
{
if (modulus_entries[i].group == group)
@@ -329,47 +329,47 @@ typedef struct private_gcrypt_dh_t private_gcrypt_dh_t;
* Private data of an gcrypt_dh_t object.
*/
struct private_gcrypt_dh_t {
/**
* Public gcrypt_dh_t interface
*/
gcrypt_dh_t public;
/**
* Diffie Hellman group number
*/
u_int16_t group;
/*
/*
* Generator value
*/
*/
gcry_mpi_t g;
/**
* Own private value
*/
gcry_mpi_t xa;
/**
* Own public value
*/
gcry_mpi_t ya;
/**
* Other public value
*/
gcry_mpi_t yb;
/**
* Shared secret
*/
gcry_mpi_t zz;
/**
* Modulus
*/
gcry_mpi_t p;
/**
* Modulus length.
*/
@@ -383,7 +383,7 @@ static void set_other_public_value(private_gcrypt_dh_t *this, chunk_t value)
{
gcry_mpi_t p_min_1;
gcry_error_t err;
if (this->yb)
{
gcry_mpi_release(this->yb);
@@ -395,11 +395,11 @@ static void set_other_public_value(private_gcrypt_dh_t *this, chunk_t value)
DBG1("importing mpi yb failed: %s", gpg_strerror(err));
return;
}
p_min_1 = gcry_mpi_new(this->p_len * 8);
gcry_mpi_sub_ui(p_min_1, this->p, 1);
/* check public value:
/* check public value:
* 1. 0 or 1 is invalid as 0^a = 0 and 1^a = 1
* 2. a public value larger or equal the modulus is invalid */
if (gcry_mpi_cmp_ui(this->yb, 1) > 0 &&
@@ -425,7 +425,7 @@ static chunk_t export_mpi(gcry_mpi_t value, size_t len)
{
chunk_t chunk;
size_t written;
chunk = chunk_alloc(len);
gcry_mpi_print(GCRYMPI_FMT_USG, chunk.ptr, chunk.len, &written, value);
if (written < len)
@@ -490,21 +490,21 @@ gcrypt_dh_t *gcrypt_dh_create(diffie_hellman_group_t group)
chunk_t random;
rng_t *rng;
size_t len;
entry = find_entry(group);
if (!entry)
{
return NULL;
}
this = malloc_thing(private_gcrypt_dh_t);
this->public.dh.get_shared_secret = (status_t (*)(diffie_hellman_t *, chunk_t *)) get_shared_secret;
this->public.dh.set_other_public_value = (void (*)(diffie_hellman_t *, chunk_t )) set_other_public_value;
this->public.dh.get_my_public_value = (void (*)(diffie_hellman_t *, chunk_t *)) get_my_public_value;
this->public.dh.get_dh_group = (diffie_hellman_group_t (*)(diffie_hellman_t *)) get_dh_group;
this->public.dh.destroy = (void (*)(diffie_hellman_t *)) destroy;
this->group = group;
this->p_len = entry->modulus.len;
err = gcry_mpi_scan(&this->p, GCRYMPI_FMT_USG,
@@ -524,7 +524,7 @@ gcrypt_dh_t *gcrypt_dh_create(diffie_hellman_group_t group)
{
len = entry->opt_len;
}
rng = lib->crypto->create_rng(lib->crypto, RNG_STRONG);
if (rng)
{ /* prefer external randomizer */
@@ -551,14 +551,14 @@ gcrypt_dh_t *gcrypt_dh_create(diffie_hellman_group_t group)
/* achieve bitsof(p)-1 by setting MSB to 0 */
gcry_mpi_clear_bit(this->xa, len * 8 - 1);
}
this->g = gcry_mpi_set_ui(NULL, entry->g);
this->ya = gcry_mpi_new(this->p_len * 8);
this->yb = NULL;
this->zz = NULL;
gcry_mpi_powm(this->ya, this->g, this->xa, this->p);
return &this->public;
}
+2 -2
View File
@@ -29,7 +29,7 @@ typedef struct gcrypt_dh_t gcrypt_dh_t;
* Implementation of the Diffie-Hellman algorithm using libgcrypt mpi.
*/
struct gcrypt_dh_t {
/**
* Implements diffie_hellman_t interface.
*/
@@ -38,7 +38,7 @@ struct gcrypt_dh_t {
/**
* Creates a new gcrypt_dh_t object.
*
*
* @param group Diffie Hellman group number to use
* @return gcrypt_dh_t object, NULL if not supported
*/
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2009 Martin Willi
* Hochschule fuer Technik Rapperswil
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -25,12 +25,12 @@ typedef struct private_gcrypt_hasher_t private_gcrypt_hasher_t;
* Private data of gcrypt_hasher_t
*/
struct private_gcrypt_hasher_t {
/**
* Public part of this class.
*/
gcrypt_hasher_t public;
/**
* gcrypt hasher context
*/
@@ -101,7 +101,7 @@ gcrypt_hasher_t *gcrypt_hasher_create(hash_algorithm_t algo)
private_gcrypt_hasher_t *this;
int gcrypt_alg;
gcry_error_t err;
switch (algo)
{
case HASH_MD2:
@@ -131,9 +131,9 @@ gcrypt_hasher_t *gcrypt_hasher_create(hash_algorithm_t algo)
default:
return NULL;
}
this = malloc_thing(private_gcrypt_hasher_t);
err = gcry_md_open(&this->hd, gcrypt_alg, 0);
if (err)
{
@@ -142,13 +142,13 @@ gcrypt_hasher_t *gcrypt_hasher_create(hash_algorithm_t algo)
free(this);
return NULL;
}
this->public.hasher_interface.get_hash = (void (*) (hasher_t*, chunk_t, u_int8_t*))get_hash;
this->public.hasher_interface.allocate_hash = (void (*) (hasher_t*, chunk_t, chunk_t*))allocate_hash;
this->public.hasher_interface.get_hash_size = (size_t (*) (hasher_t*))get_hash_size;
this->public.hasher_interface.reset = (void (*) (hasher_t*))reset;
this->public.hasher_interface.destroy = (void (*) (hasher_t*))destroy;
return &this->public;
}
@@ -29,7 +29,7 @@ typedef struct gcrypt_hasher_t gcrypt_hasher_t;
* Implementation of hashers using libgcrypt.
*/
struct gcrypt_hasher_t {
/**
* The hasher_t interface.
*/
@@ -38,7 +38,7 @@ struct gcrypt_hasher_t {
/**
* Constructor to create gcrypt_hasher_t.
*
*
* @param algo algorithm
* @return gcrypt_hasher_t, NULL if not supported
*/
@@ -57,7 +57,7 @@ static int mutex_init(void **lock)
static int mutex_destroy(void **lock)
{
mutex_t *mutex = *lock;
mutex->destroy(mutex);
return 0;
}
@@ -68,7 +68,7 @@ static int mutex_destroy(void **lock)
static int mutex_lock(void **lock)
{
mutex_t *mutex = *lock;
mutex->lock(mutex);
return 0;
}
@@ -79,7 +79,7 @@ static int mutex_lock(void **lock)
static int mutex_unlock(void **lock)
{
mutex_t *mutex = *lock;
mutex->unlock(mutex);
return 0;
}
@@ -119,15 +119,15 @@ static void destroy(private_gcrypt_plugin_t *this)
plugin_t *plugin_create()
{
private_gcrypt_plugin_t *this;
gcry_control(GCRYCTL_SET_THREAD_CBS, &thread_functions);
if (!gcry_check_version(GCRYPT_VERSION))
{
DBG1("libgcrypt version mismatch");
return NULL;
}
/* we currently do not use secure memory */
gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
if (lib->settings->get_bool(lib->settings,
@@ -136,11 +136,11 @@ plugin_t *plugin_create()
gcry_control(GCRYCTL_ENABLE_QUICK_RANDOM, 0);
}
gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
this = malloc_thing(private_gcrypt_plugin_t);
this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
/* hashers */
lib->crypto->add_hasher(lib->crypto, HASH_SHA1,
(hasher_constructor_t)gcrypt_hasher_create);
@@ -156,7 +156,7 @@ plugin_t *plugin_create()
(hasher_constructor_t)gcrypt_hasher_create);
lib->crypto->add_hasher(lib->crypto, HASH_SHA512,
(hasher_constructor_t)gcrypt_hasher_create);
/* crypters */
lib->crypto->add_crypter(lib->crypto, ENCR_3DES,
(crypter_constructor_t)gcrypt_crypter_create);
@@ -176,39 +176,39 @@ plugin_t *plugin_create()
(crypter_constructor_t)gcrypt_crypter_create);
lib->crypto->add_crypter(lib->crypto, ENCR_TWOFISH_CBC,
(crypter_constructor_t)gcrypt_crypter_create);
/* random numbers */
lib->crypto->add_rng(lib->crypto, RNG_WEAK,
lib->crypto->add_rng(lib->crypto, RNG_WEAK,
(rng_constructor_t)gcrypt_rng_create);
lib->crypto->add_rng(lib->crypto, RNG_STRONG,
lib->crypto->add_rng(lib->crypto, RNG_STRONG,
(rng_constructor_t)gcrypt_rng_create);
lib->crypto->add_rng(lib->crypto, RNG_TRUE,
lib->crypto->add_rng(lib->crypto, RNG_TRUE,
(rng_constructor_t)gcrypt_rng_create);
/* diffie hellman groups, using modp */
lib->crypto->add_dh(lib->crypto, MODP_2048_BIT,
lib->crypto->add_dh(lib->crypto, MODP_2048_BIT,
(dh_constructor_t)gcrypt_dh_create);
lib->crypto->add_dh(lib->crypto, MODP_1536_BIT,
lib->crypto->add_dh(lib->crypto, MODP_1536_BIT,
(dh_constructor_t)gcrypt_dh_create);
lib->crypto->add_dh(lib->crypto, MODP_3072_BIT,
lib->crypto->add_dh(lib->crypto, MODP_3072_BIT,
(dh_constructor_t)gcrypt_dh_create);
lib->crypto->add_dh(lib->crypto, MODP_4096_BIT,
lib->crypto->add_dh(lib->crypto, MODP_4096_BIT,
(dh_constructor_t)gcrypt_dh_create);
lib->crypto->add_dh(lib->crypto, MODP_6144_BIT,
lib->crypto->add_dh(lib->crypto, MODP_6144_BIT,
(dh_constructor_t)gcrypt_dh_create);
lib->crypto->add_dh(lib->crypto, MODP_8192_BIT,
lib->crypto->add_dh(lib->crypto, MODP_8192_BIT,
(dh_constructor_t)gcrypt_dh_create);
lib->crypto->add_dh(lib->crypto, MODP_1024_BIT,
(dh_constructor_t)gcrypt_dh_create);
lib->crypto->add_dh(lib->crypto, MODP_768_BIT,
lib->crypto->add_dh(lib->crypto, MODP_768_BIT,
(dh_constructor_t)gcrypt_dh_create);
/* RSA */
lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
(builder_constructor_t)gcrypt_rsa_private_key_builder);
lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_RSA,
(builder_constructor_t)gcrypt_rsa_public_key_builder);
return &this->public.plugin;
}
@@ -28,7 +28,7 @@ struct private_gcrypt_rng_t {
* Public gcrypt_rng_t interface.
*/
gcrypt_rng_t public;
/**
* RNG quality of this instance
*/
@@ -79,7 +79,7 @@ static void destroy(private_gcrypt_rng_t *this)
gcrypt_rng_t *gcrypt_rng_create(rng_quality_t quality)
{
private_gcrypt_rng_t *this;
switch (quality)
{
case RNG_WEAK:
@@ -89,15 +89,15 @@ gcrypt_rng_t *gcrypt_rng_create(rng_quality_t quality)
default:
return NULL;
}
this = malloc_thing(private_gcrypt_rng_t);
this->public.rng.get_bytes = (void (*) (rng_t *, size_t, u_int8_t*)) get_bytes;
this->public.rng.allocate_bytes = (void (*) (rng_t *, size_t, chunk_t*)) allocate_bytes;
this->public.rng.destroy = (void (*) (rng_t *))destroy;
this->quality = quality;
return &this->public;
}
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
/**
* @defgroup gcrypt_rng gcrypt_rng
* @{ @ingroup gcrypt_p
@@ -29,7 +29,7 @@ typedef struct gcrypt_rng_t gcrypt_rng_t;
* rng_t implementation using libgcrypt.
*/
struct gcrypt_rng_t {
/**
* Implements rng_t.
*/
@@ -38,7 +38,7 @@ struct gcrypt_rng_t {
/**
* Creates an gcrypt_rng_t instance.
*
*
* @param quality required quality of gcryptness
* @return created gcrypt_rng_t
*/
@@ -28,17 +28,17 @@ typedef struct private_gcrypt_rsa_private_key_t private_gcrypt_rsa_private_key_t
* Private data of a gcrypt_rsa_private_key_t object.
*/
struct private_gcrypt_rsa_private_key_t {
/**
* Public interface
*/
gcrypt_rsa_private_key_t public;
/**
* gcrypt S-expression representing an RSA key
*/
gcry_sexp_t key;
/**
* reference count
*/
@@ -54,7 +54,7 @@ chunk_t gcrypt_rsa_find_token(gcry_sexp_t sexp, char *name, gcry_sexp_t key)
gcry_sexp_t token;
chunk_t data = chunk_empty, tmp;
size_t len = 0;
token = gcry_sexp_find_token(sexp, name, 1);
if (token)
{
@@ -108,7 +108,7 @@ static bool sign_raw(private_gcrypt_rsa_private_key_t *this,
gcry_error_t err;
chunk_t em;
size_t k;
/* EM = 0x00 || 0x01 || PS || 0x00 || T
* PS = 0xFF padding, with length to fill em
* T = data
@@ -124,7 +124,7 @@ static bool sign_raw(private_gcrypt_rsa_private_key_t *this,
em.ptr[1] = 0x01;
em.ptr[em.len - data.len - 1] = 0x00;
memcpy(em.ptr + em.len - data.len, data.ptr, data.len);
err = gcry_sexp_build(&in, NULL, "(data(flags raw)(value %b))",
em.len, em.ptr);
chunk_free(&em);
@@ -157,7 +157,7 @@ static bool sign_pkcs1(private_gcrypt_rsa_private_key_t *this,
gcry_error_t err;
gcry_sexp_t in, out;
int hash_oid;
hash_oid = hasher_algorithm_to_oid(hash_algorithm);
if (hash_oid == OID_UNKNOWN)
{
@@ -170,7 +170,7 @@ static bool sign_pkcs1(private_gcrypt_rsa_private_key_t *this,
}
hasher->allocate_hash(hasher, data, &hash);
hasher->destroy(hasher);
err = gcry_sexp_build(&in, NULL, "(data(flags pkcs1)(hash %s %b))",
hash_name, hash.len, hash.ptr);
chunk_free(&hash);
@@ -202,7 +202,7 @@ static key_type_t get_type(private_gcrypt_rsa_private_key_t *this)
/**
* Implementation of gcrypt_rsa_private_key.destroy.
*/
static bool sign(private_gcrypt_rsa_private_key_t *this, signature_scheme_t scheme,
static bool sign(private_gcrypt_rsa_private_key_t *this, signature_scheme_t scheme,
chunk_t data, chunk_t *sig)
{
switch (scheme)
@@ -238,7 +238,7 @@ static bool decrypt(private_gcrypt_rsa_private_key_t *this,
gcry_sexp_t in, out;
chunk_t padded;
u_char *pos = NULL;;
err = gcry_sexp_build(&in, NULL, "(enc-val(flags)(rsa(a %b)))",
encrypted.len, encrypted.ptr);
if (err)
@@ -290,15 +290,15 @@ static public_key_t* get_public_key(private_gcrypt_rsa_private_key_t *this)
{
chunk_t n, e;
public_key_t *public;
n = gcrypt_rsa_find_token(this->key, "n", NULL);
e = gcrypt_rsa_find_token(this->key, "e", NULL);
public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_RSA,
BUILD_RSA_MODULUS, n, BUILD_RSA_PUB_EXP, e, BUILD_END);
chunk_free(&n);
chunk_free(&e);
return public;
}
@@ -312,12 +312,12 @@ static bool get_encoding(private_gcrypt_rsa_private_key_t *this,
gcry_mpi_t p = NULL, q = NULL, d = NULL, exp1, exp2;
gcry_error_t err;
bool success;
/* p and q are swapped, gcrypt expects p < q */
cp = gcrypt_rsa_find_token(this->key, "q", NULL);
cq = gcrypt_rsa_find_token(this->key, "p", NULL);
cd = gcrypt_rsa_find_token(this->key, "d", NULL);
err = gcry_mpi_scan(&p, GCRYMPI_FMT_USG, cp.ptr, cp.len, NULL)
| gcry_mpi_scan(&q, GCRYMPI_FMT_USG, cq.ptr, cq.len, NULL)
| gcry_mpi_scan(&d, GCRYMPI_FMT_USG, cd.ptr, cd.len, NULL);
@@ -332,24 +332,24 @@ static bool get_encoding(private_gcrypt_rsa_private_key_t *this,
DBG1("scanning mpi for export failed: %s", gpg_strerror(err));
return FALSE;
}
gcry_mpi_sub_ui(p, p, 1);
exp1 = gcry_mpi_new(gcry_pk_get_nbits(this->key));
gcry_mpi_mod(exp1, d, p);
gcry_mpi_release(p);
gcry_mpi_sub_ui(q, q, 1);
exp2 = gcry_mpi_new(gcry_pk_get_nbits(this->key));
gcry_mpi_mod(exp1, d, q);
gcry_mpi_release(q);
err = gcry_mpi_aprint(GCRYMPI_FMT_USG, &cexp1.ptr, &cexp1.len, exp1)
| gcry_mpi_aprint(GCRYMPI_FMT_USG, &cexp2.ptr, &cexp2.len, exp2);
gcry_mpi_release(d);
gcry_mpi_release(exp1);
gcry_mpi_release(exp2);
if (err)
{
DBG1("printing mpi for export failed: %s", gpg_strerror(err));
@@ -360,11 +360,11 @@ static bool get_encoding(private_gcrypt_rsa_private_key_t *this,
chunk_clear(&cexp2);
return FALSE;
}
cn = gcrypt_rsa_find_token(this->key, "n", NULL);
ce = gcrypt_rsa_find_token(this->key, "e", NULL);
cu = gcrypt_rsa_find_token(this->key, "u", NULL);
success = lib->encoding->encode(lib->encoding, type, NULL, encoding,
KEY_PART_RSA_MODULUS, cn,
KEY_PART_RSA_PUB_EXP, ce, KEY_PART_RSA_PRIV_EXP, cd,
@@ -379,7 +379,7 @@ static bool get_encoding(private_gcrypt_rsa_private_key_t *this,
chunk_clear(&cexp1);
chunk_clear(&cexp2);
chunk_clear(&cu);
return success;
}
@@ -391,14 +391,14 @@ static bool get_fingerprint(private_gcrypt_rsa_private_key_t *this,
{
chunk_t n, e;
bool success;
if (lib->encoding->get_cache(lib->encoding, type, this, fp))
{
return TRUE;
}
n = gcrypt_rsa_find_token(this->key, "n", NULL);
e = gcrypt_rsa_find_token(this->key, "e", NULL);
success = lib->encoding->encode(lib->encoding,
type, this, fp, KEY_PART_RSA_MODULUS, n,
KEY_PART_RSA_PUB_EXP, e, KEY_PART_END);
@@ -435,7 +435,7 @@ static void destroy(private_gcrypt_rsa_private_key_t *this)
static private_gcrypt_rsa_private_key_t *gcrypt_rsa_private_key_create_empty()
{
private_gcrypt_rsa_private_key_t *this = malloc_thing(private_gcrypt_rsa_private_key_t);
this->public.interface.get_type = (key_type_t (*)(private_key_t *this))get_type;
this->public.interface.sign = (bool (*)(private_key_t *this, signature_scheme_t scheme, chunk_t data, chunk_t *signature))sign;
this->public.interface.decrypt = (bool (*)(private_key_t *this, chunk_t crypto, chunk_t *plain))decrypt;
@@ -447,10 +447,10 @@ static private_gcrypt_rsa_private_key_t *gcrypt_rsa_private_key_create_empty()
this->public.interface.get_encoding = (bool(*)(private_key_t*, key_encoding_type_t type, chunk_t *encoding))get_encoding;
this->public.interface.get_ref = (private_key_t* (*)(private_key_t *this))get_ref;
this->public.interface.destroy = (void (*)(private_key_t *this))destroy;
this->key = NULL;
this->ref = 1;
return this;
}
@@ -462,14 +462,14 @@ static gcrypt_rsa_private_key_t *generate(size_t key_size)
private_gcrypt_rsa_private_key_t *this;
gcry_sexp_t param, key;
gcry_error_t err;
err = gcry_sexp_build(&param, NULL, "(genkey(rsa(nbits %d)))", key_size);
if (err)
{
DBG1("building S-expression failed: %s", gpg_strerror(err));
return NULL;
}
err = gcry_pk_genkey(&key, param);
gcry_sexp_release(param);
if (err)
@@ -479,7 +479,7 @@ static gcrypt_rsa_private_key_t *generate(size_t key_size)
}
this = gcrypt_rsa_private_key_create_empty();
this->key = key;
return &this->public;
}
@@ -491,7 +491,7 @@ static gcrypt_rsa_private_key_t *load(chunk_t n, chunk_t e, chunk_t d,
{
gcry_error_t err;
private_gcrypt_rsa_private_key_t *this = gcrypt_rsa_private_key_create_empty();
err = gcry_sexp_build(&this->key, NULL,
"(private-key(rsa(n %b)(e %b)(d %b)(p %b)(q %b)(u %b)))",
n.len, n.ptr, e.len, e.ptr, d.len, d.ptr,
@@ -551,7 +551,7 @@ static gcrypt_rsa_private_key_t *build(private_builder_t *this)
static void add(private_builder_t *this, builder_part_t part, ...)
{
va_list args;
va_start(args, part);
switch (part)
{
@@ -594,19 +594,19 @@ static void add(private_builder_t *this, builder_part_t part, ...)
builder_t *gcrypt_rsa_private_key_builder(key_type_t type)
{
private_builder_t *this;
if (type != KEY_RSA)
{
return NULL;
}
this = malloc_thing(private_builder_t);
this->key_size = 0;
this->n = this->e = this->d = this->p = this->q = this->u = chunk_empty;
this->public.add = (void(*)(builder_t *this, builder_part_t part, ...))add;
this->public.build = (void*(*)(builder_t *this))build;
return &this->public;
}
@@ -29,7 +29,7 @@ typedef struct gcrypt_rsa_private_key_t gcrypt_rsa_private_key_t;
* Private_key_t implementation of RSA algorithm using libgcrypt.
*/
struct gcrypt_rsa_private_key_t {
/**
* Implements private_key_t interface
*/
@@ -12,7 +12,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include <gcrypt.h>
#include "gcrypt_rsa_public_key.h"
@@ -29,17 +29,17 @@ typedef struct private_gcrypt_rsa_public_key_t private_gcrypt_rsa_public_key_t;
* Private data structure with signing context.
*/
struct private_gcrypt_rsa_public_key_t {
/**
* Public interface for this signer.
*/
gcrypt_rsa_public_key_t public;
/**
* gcrypt S-expression representing an public RSA key
*/
gcry_sexp_t key;
/**
* reference counter
*/
@@ -61,7 +61,7 @@ static bool verify_raw(private_gcrypt_rsa_public_key_t *this,
gcry_error_t err;
chunk_t em;
size_t k;
/* EM = 0x00 || 0x01 || PS || 0x00 || T
* PS = 0xFF padding, with length to fill em
* T = data
@@ -77,7 +77,7 @@ static bool verify_raw(private_gcrypt_rsa_public_key_t *this,
em.ptr[1] = 0x01;
em.ptr[em.len - data.len - 1] = 0x00;
memcpy(em.ptr + em.len - data.len, data.ptr, data.len);
err = gcry_sexp_build(&in, NULL, "(data(flags raw)(value %b))",
em.len, em.ptr);
chunk_free(&em);
@@ -116,7 +116,7 @@ static bool verify_pkcs1(private_gcrypt_rsa_public_key_t *this,
chunk_t hash;
gcry_error_t err;
gcry_sexp_t in, sig;
hasher = lib->crypto->create_hasher(lib->crypto, algorithm);
if (!hasher)
{
@@ -124,7 +124,7 @@ static bool verify_pkcs1(private_gcrypt_rsa_public_key_t *this,
}
hasher->allocate_hash(hasher, data, &hash);
hasher->destroy(hasher);
err = gcry_sexp_build(&in, NULL, "(data(flags pkcs1)(hash %s %b))",
hash_name, hash.len, hash.ptr);
chunk_free(&hash);
@@ -133,7 +133,7 @@ static bool verify_pkcs1(private_gcrypt_rsa_public_key_t *this,
DBG1("building data S-expression failed: %s", gpg_strerror(err));
return FALSE;
}
err = gcry_sexp_build(&sig, NULL, "(sig-val(rsa(s %b)))",
signature.len, signature.ptr);
if (err)
@@ -198,7 +198,7 @@ static bool encrypt_(private_gcrypt_rsa_public_key_t *this, chunk_t plain,
{
gcry_sexp_t in, out;
gcry_error_t err;
/* "pkcs1" uses PKCS 1.5 (section 8.1) block type 2 encryption:
* 00 | 02 | RANDOM | 00 | DATA */
err = gcry_sexp_build(&in, NULL, "(data(flags pkcs1)(value %b))",
@@ -236,7 +236,7 @@ static bool get_encoding(private_gcrypt_rsa_public_key_t *this,
{
chunk_t n, e;
bool success;
n = gcrypt_rsa_find_token(this->key, "n", NULL);
e = gcrypt_rsa_find_token(this->key, "e", NULL);
success = lib->encoding->encode(lib->encoding, type, NULL, encoding,
@@ -244,7 +244,7 @@ static bool get_encoding(private_gcrypt_rsa_public_key_t *this,
KEY_PART_END);
chunk_free(&n);
chunk_free(&e);
return success;
}
@@ -256,14 +256,14 @@ static bool get_fingerprint(private_gcrypt_rsa_public_key_t *this,
{
chunk_t n, e;
bool success;
if (lib->encoding->get_cache(lib->encoding, type, this, fp))
{
return TRUE;
}
n = gcrypt_rsa_find_token(this->key, "n", NULL);
e = gcrypt_rsa_find_token(this->key, "e", NULL);
success = lib->encoding->encode(lib->encoding,
type, this, fp, KEY_PART_RSA_MODULUS, n,
KEY_PART_RSA_PUB_EXP, e, KEY_PART_END);
@@ -300,7 +300,7 @@ static void destroy(private_gcrypt_rsa_public_key_t *this)
static private_gcrypt_rsa_public_key_t *gcrypt_rsa_public_key_create_empty()
{
private_gcrypt_rsa_public_key_t *this = malloc_thing(private_gcrypt_rsa_public_key_t);
this->public.interface.get_type = (key_type_t (*)(public_key_t *this))get_type;
this->public.interface.verify = (bool (*)(public_key_t *this, signature_scheme_t scheme, chunk_t data, chunk_t signature))verify;
this->public.interface.encrypt = (bool (*)(public_key_t *this, chunk_t crypto, chunk_t *plain))encrypt_;
@@ -310,10 +310,10 @@ static private_gcrypt_rsa_public_key_t *gcrypt_rsa_public_key_create_empty()
this->public.interface.get_encoding = (bool(*)(public_key_t*, key_encoding_type_t type, chunk_t *encoding))get_encoding;
this->public.interface.get_ref = (public_key_t* (*)(public_key_t *this))get_ref;
this->public.interface.destroy = (void (*)(public_key_t *this))destroy;
this->key = NULL;
this->ref = 1;
return this;
}
@@ -324,7 +324,7 @@ static gcrypt_rsa_public_key_t *load(chunk_t n, chunk_t e)
{
private_gcrypt_rsa_public_key_t *this;
gcry_error_t err;
this = gcrypt_rsa_public_key_create_empty();
err = gcry_sexp_build(&this->key, NULL, "(public-key(rsa(n %b)(e %b)))",
n.len, n.ptr, e.len, e.ptr);
@@ -355,7 +355,7 @@ struct private_builder_t {
static gcrypt_rsa_public_key_t *build(private_builder_t *this)
{
gcrypt_rsa_public_key_t *key;
key = load(this->n, this->e);
free(this);
return key;
@@ -367,7 +367,7 @@ static gcrypt_rsa_public_key_t *build(private_builder_t *this)
static void add(private_builder_t *this, builder_part_t part, ...)
{
va_list args;
va_start(args, part);
switch (part)
{
@@ -390,18 +390,18 @@ static void add(private_builder_t *this, builder_part_t part, ...)
builder_t *gcrypt_rsa_public_key_builder(key_type_t type)
{
private_builder_t *this;
if (type != KEY_RSA)
{
return NULL;
}
this = malloc_thing(private_builder_t);
this->n = this->e = chunk_empty;
this->public.add = (void(*)(builder_t *this, builder_part_t part, ...))add;
this->public.build = (void*(*)(builder_t *this))build;
return &this->public;
}