/************************** Types and definitions ***************************/
+#define SILC_ACC_KEY_MAGIC 0xfde09137
+
SILC_PKCS_GET_ALGORITHM(silc_acc_pkcs_get_algorithm);
SILC_PKCS_IMPORT_PUBLIC_KEY_FILE(silc_acc_pkcs_import_public_key_file);
SILC_PKCS_IMPORT_PUBLIC_KEY(silc_acc_pkcs_import_public_key);
/* Accelerator public key */
typedef struct {
+ SilcUInt32 magic;
int pkcs_index; /* Accelerator PKCS index */
SilcAccelerator acc; /* The accelerator */
void *context; /* Accelerator context */
/* Accelerator private key */
typedef struct {
+ SilcUInt32 magic;
int pkcs_index; /* Accelerator PKCS index */
SilcAccelerator acc; /* The accelerator */
void *context; /* Accelerator context */
SILC_PKCS_PUBLIC_KEY_COMPARE(silc_acc_pkcs_public_key_compare)
{
- /* XXX */
- return FALSE;
+ SilcAcceleratorPublicKey pub;
+
+ pub = key2;
+ if (pub->magic == SILC_ACC_KEY_MAGIC)
+ key2 = pub->accelerated->public_key;
+
+ pub = key1;
+
+ return pub->accelerated->pkcs->
+ public_key_compare(pub->accelerated->pkcs,
+ pub->accelerated->public_key, key2);
}
SILC_PKCS_IMPORT_PRIVATE_KEY_FILE(silc_acc_pkcs_import_private_key_file)
{
- return 0;
+ /* Not implemented */
+ return FALSE;
}
SILC_PKCS_IMPORT_PRIVATE_KEY(silc_acc_pkcs_import_private_key)
{
- return 0;
+ /* Not implemented */
+ return FALSE;
}
SILC_PKCS_EXPORT_PRIVATE_KEY_FILE(silc_acc_pkcs_export_private_key_file)
{
- return 0;
+ SilcAcceleratorPrivateKey prv = private_key;
+ return prv->accelerated->pkcs->
+ export_private_key_file(prv->accelerated->pkcs, stack,
+ prv->accelerated->private_key, passphrase,
+ passphrase_len, encoding, rng, ret_len);
}
SILC_PKCS_EXPORT_PRIVATE_KEY(silc_acc_pkcs_export_private_key)
{
- return 0;
+ SilcAcceleratorPrivateKey prv = private_key;
+ return prv->accelerated->pkcs->
+ export_private_key(prv->accelerated->pkcs, stack,
+ prv->accelerated->private_key, ret_len);
}
SILC_PKCS_PRIVATE_KEY_BITLEN(silc_acc_pkcs_private_key_bitlen)
{
- return 0;
+ SilcAcceleratorPrivateKey prv = private_key;
+ return prv->accelerated->pkcs->
+ private_key_bitlen(prv->accelerated->pkcs,
+ prv->accelerated->private_key);
}
+/* Accelerator routines follow */
+
SILC_PKCS_PUBLIC_KEY_FREE(silc_acc_pkcs_public_key_free)
{
-
+ SilcAcceleratorPublicKey pub = public_key;
+ pub->acc->pkcs[pub->pkcs_index].
+ public_key_free(&pub->acc->pkcs[pub->pkcs_index], pub->context);
}
SILC_PKCS_PRIVATE_KEY_FREE(silc_acc_pkcs_private_key_free)
{
-
+ SilcAcceleratorPrivateKey prv = private_key;
+ prv->acc->pkcs[prv->pkcs_index].
+ private_key_free(&prv->acc->pkcs[prv->pkcs_index], prv->context);
}
SILC_PKCS_ENCRYPT(silc_acc_pkcs_encrypt)
/* Accelerate */
return prv->acc->pkcs[prv->pkcs_index].sign(
&prv->acc->pkcs[prv->pkcs_index], prv->context, src,
- src_len, compute_hash, hash, sign_cb, context);
+ src_len, compute_hash, hash, rng, sign_cb, context);
}
SILC_PKCS_VERIFY(silc_acc_pkcs_verify)
/* Accelerate */
return pub->acc->pkcs[pub->pkcs_index].verify(
&pub->acc->pkcs[pub->pkcs_index], pub->context,
- signature, signature_len, data, data_len, hash,
+ signature, signature_len, data, data_len, hash, rng,
verify_cb, context);
}
return NULL;
}
+ if (silc_acc_get_public_key(NULL, public_key)) {
+ SILC_LOG_DEBUG(("Pubilc key %p is already accelerated", public_key));
+ return NULL;
+ }
+
/* Check that accelerator supports this public key algorithm */
alg = silc_pkcs_get_algorithm(public_key);
if (!alg)
}
if (alg) {
SILC_LOG_DEBUG(("Accelerator %s does not support %s/%s acceleration",
- alg->name, alg->scheme));
+ acc->name, alg->name, alg->scheme));
return NULL;
}
}
*pubkey->pkcs = silc_acc_pkcs;
pubkey->pkcs->type = silc_pkcs_get_type(public_key);
+ pubkey->alg = silc_pkcs_get_algorithm(public_key);
/* Allocate accelerator public key */
acc_pubkey = silc_calloc(1, sizeof(*acc_pubkey));
silc_free(pubkey);
return NULL;
}
+ acc_pubkey->magic = SILC_ACC_KEY_MAGIC;
acc_pubkey->accelerated = public_key;
acc_pubkey->acc = acc;
acc_pubkey->pkcs_index = i;
/* Accelerate the public key. Returns accelerator context. */
- if (!acc->pkcs->import_public_key(&acc->pkcs[i], public_key, 0,
- &acc_pubkey->context)) {
+ if (!acc->pkcs[i].import_public_key(&acc->pkcs[i], public_key, 0,
+ &acc_pubkey->context)) {
SILC_LOG_ERROR(("Error accelerating public key with accelerator '%s'",
acc->name));
silc_free(acc_pubkey);
return NULL;
}
+ if (silc_acc_get_private_key(NULL, private_key)) {
+ SILC_LOG_DEBUG(("Private key %p is already accelerated", private_key));
+ return NULL;
+ }
+
/* Check that accelerator supports this private key algorithm */
alg = silc_pkcs_get_algorithm(private_key);
if (!alg)
}
if (alg) {
SILC_LOG_DEBUG(("Accelerator %s does not support %s/%s acceleration",
- alg->name, alg->scheme));
+ acc->name, alg->name, alg->scheme));
return NULL;
}
}
*privkey->pkcs = silc_acc_pkcs;
privkey->pkcs->type = silc_pkcs_get_type(private_key);
+ privkey->alg = silc_pkcs_get_algorithm(private_key);
/* Allocate accelerator public key */
acc_privkey = silc_calloc(1, sizeof(*acc_privkey));
silc_free(privkey);
return NULL;
}
+ acc_privkey->magic = SILC_ACC_KEY_MAGIC;
acc_privkey->accelerated = private_key;
acc_privkey->acc = acc;
acc_privkey->pkcs_index = i;
/* Accelerate the public key. Returns accelerator context. */
- if (!acc->pkcs->import_private_key(&acc->pkcs[i], private_key, 0,
- &acc_privkey->context)) {
+ if (!acc->pkcs[i].import_private_key(&acc->pkcs[i], private_key, 0,
+ &acc_privkey->context)) {
SILC_LOG_ERROR(("Error accelerating private key with accelerator '%s'",
acc->name));
silc_free(acc_privkey);