Added cipher acceleration to SILC Accelerator. Added cipher softacc.
[crypto.git] / lib / silcacc / silcacc_pkcs.c
index c7920a29e3745668735369a964b85307c4d15d02..cc666880811b635db25652f8c69b5a2da000a639 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2007 Pekka Riikonen
+  Copyright (C) 2007 -  2008 Pekka Riikonen
 
   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
@@ -17,7 +17,7 @@
 
 */
 
-#include "silc.h"
+#include "silccrypto.h"
 
 /************************** Types and definitions ***************************/
 
@@ -242,7 +242,7 @@ SILC_PKCS_SIGN(silc_acc_pkcs_sign)
   /* 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)
@@ -252,7 +252,7 @@ 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);
 }
 
@@ -280,6 +280,11 @@ SilcPublicKey silc_acc_public_key(SilcAccelerator acc,
     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)
@@ -325,9 +330,9 @@ SilcPublicKey silc_acc_public_key(SilcAccelerator 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)) {
-    SILC_LOG_ERROR(("Error accelerating public key with accelerator '%s'",
+  if (!acc->pkcs[i].import_public_key(&acc->pkcs[i], public_key, 0,
+                                     &acc_pubkey->context)) {
+    SILC_LOG_DEBUG(("Error accelerating public key with accelerator '%s'",
                    acc->name));
     silc_free(acc_pubkey);
     silc_free(pubkey->pkcs);
@@ -363,6 +368,11 @@ SilcPrivateKey silc_acc_private_key(SilcAccelerator acc,
     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)
@@ -407,9 +417,10 @@ SilcPrivateKey silc_acc_private_key(SilcAccelerator acc,
   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)) {
+  /* Accelerate the public key.  Returns accelerator context.  The
+     import_public_key operation is used to accelerate the key. */
+  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);