[gnome-keyring/dbus-api] [egg] Move padding functionality into egg



commit fe778375c74e1ed59c3abe9a7cf931cb6518a2e6
Author: Stef Walter <stef memberwebs com>
Date:   Sun Dec 13 22:45:37 2009 +0000

    [egg] Move padding functionality into egg
    
    So other components can use it.

 egg/Makefile.am                               |    2 +
 egg/egg-asn1.h                                |    3 ++
 pkcs11/gck/gck-padding.c => egg/egg-padding.c |   32 ++++++++++-------
 pkcs11/gck/gck-padding.h => egg/egg-padding.h |   28 ++++++++-------
 egg/tests/Makefile.am                         |    1 +
 {pkcs11/gck => egg}/tests/test-padding.c      |   48 ++++++++++++------------
 pkcs11/gck/Makefile.am                        |    1 -
 pkcs11/gck/gck-aes-mechanism.c                |    8 ++--
 pkcs11/gck/gck-crypto.c                       |   18 +++++-----
 pkcs11/gck/gck-crypto.h                       |    7 ++--
 pkcs11/gck/gck-mechanism-rsa.c                |    8 ++--
 pkcs11/gck/gck-mechanism-rsa.h                |    8 ++--
 pkcs11/gck/gck-null-mechanism.c               |    1 -
 pkcs11/gck/tests/Makefile.am                  |    1 -
 14 files changed, 89 insertions(+), 77 deletions(-)
---
diff --git a/egg/Makefile.am b/egg/Makefile.am
index 1c91c6c..6d5d3c8 100644
--- a/egg/Makefile.am
+++ b/egg/Makefile.am
@@ -28,6 +28,7 @@ libegg_la_SOURCES = \
 	egg-libgcrypt.c egg-libgcrypt.h \
 	egg-mkdtemp.c egg-mkdtemp.h \
 	egg-oid.c egg-oid.h \
+	egg-padding.c egg-padding.h \
 	egg-openssl.c egg-openssl.h \
 	egg-unix-credentials.c egg-unix-credentials.h \
 	egg-secure-memory.c egg-secure-memory.h \
@@ -83,6 +84,7 @@ libegg_prompt_la_SOURCES = \
 	egg-dh.c egg-dh.h \
 	egg-hex.c egg-hex.h \
 	egg-libgcrypt.c egg-libgcrypt.h \
+	egg-padding.c egg-padding.h \
 	egg-secure-memory.c egg-secure-memory.h
 
 libegg_prompt_la_CFLAGS = \
diff --git a/egg/egg-asn1.h b/egg/egg-asn1.h
index 3ee6d43..8d1aff8 100644
--- a/egg/egg-asn1.h
+++ b/egg/egg-asn1.h
@@ -28,7 +28,10 @@
 
 #include <libtasn1.h>
 
+#ifndef HAVE_EGG_ALLOCATOR
 typedef void* (*EggAllocator) (void* p, gsize);
+#define HAVE_EGG_ALLOCATOR
+#endif
 
 ASN1_TYPE          egg_asn1_get_pk_asn1type               (void);
 
diff --git a/pkcs11/gck/gck-padding.c b/egg/egg-padding.c
similarity index 88%
rename from pkcs11/gck/gck-padding.c
rename to egg/egg-padding.c
index 094eda2..66699ce 100644
--- a/pkcs11/gck/gck-padding.c
+++ b/egg/egg-padding.c
@@ -21,10 +21,10 @@
 
 #include "config.h"
 
-#include "gck-padding.h"
-#include "gck-sexp.h"
+#include "egg-padding.h"
+
+#include <gcrypt.h>
 
-#include "egg/egg-libgcrypt.h"
 #include "egg/egg-secure-memory.h"
 
 /* ----------------------------------------------------------------------------
@@ -67,7 +67,7 @@ fill_random_nonzero (guchar *data, gsize n_data)
 }
 
 static gboolean
-unpad_pkcs1 (guchar bt, GckAllocator alloc, gsize block, const guchar* padded,
+unpad_pkcs1 (guchar bt, EggAllocator alloc, gsize block, const guchar* padded,
              gsize n_padded, gpointer *raw, gsize *n_raw)
 {
 	const guchar *at;
@@ -90,10 +90,13 @@ unpad_pkcs1 (guchar bt, GckAllocator alloc, gsize block, const guchar* padded,
 	++at;
 	*n_raw = n_padded - (at - padded);
 	if (raw) {
-		*raw = (alloc) (NULL, MAX (*n_raw, 1));
+		*raw = (alloc) (NULL, *n_raw + 1);
 		if (*raw == NULL)
 			return FALSE;
 		memcpy (*raw, at, *n_raw);
+
+		/* Convenience null terminate the result */
+		memset (((guchar*)*raw) + *n_raw, 0, 1);
 	}
 
 	return TRUE;
@@ -104,7 +107,7 @@ unpad_pkcs1 (guchar bt, GckAllocator alloc, gsize block, const guchar* padded,
  */
 
 gboolean
-gck_padding_zero_pad (GckAllocator alloc, gsize block, gconstpointer raw,
+egg_padding_zero_pad (EggAllocator alloc, gsize block, gconstpointer raw,
                       gsize n_raw, gpointer *padded, gsize *n_padded)
 {
 	guchar *pad;
@@ -137,7 +140,7 @@ gck_padding_zero_pad (GckAllocator alloc, gsize block, gconstpointer raw,
 }
 
 gboolean
-gck_padding_pkcs1_pad_01 (GckAllocator alloc, gsize block, gconstpointer raw,
+egg_padding_pkcs1_pad_01 (EggAllocator alloc, gsize block, gconstpointer raw,
                            gsize n_raw, gpointer *padded, gsize *n_padded)
 {
 	guchar *pad;
@@ -175,7 +178,7 @@ gck_padding_pkcs1_pad_01 (GckAllocator alloc, gsize block, gconstpointer raw,
 }
 
 gboolean
-gck_padding_pkcs1_pad_02 (GckAllocator alloc, gsize block, gconstpointer raw,
+egg_padding_pkcs1_pad_02 (EggAllocator alloc, gsize block, gconstpointer raw,
                            gsize n_raw, gpointer *padded, gsize *n_padded)
 {
 	guchar *pad;
@@ -213,21 +216,21 @@ gck_padding_pkcs1_pad_02 (GckAllocator alloc, gsize block, gconstpointer raw,
 }
 
 gboolean
-gck_padding_pkcs1_unpad_01 (GckAllocator alloc, gsize block, gconstpointer padded,
+egg_padding_pkcs1_unpad_01 (EggAllocator alloc, gsize block, gconstpointer padded,
                              gsize n_padded, gpointer *raw, gsize *n_raw)
 {
 	return unpad_pkcs1 (0x01, alloc, block, padded, n_padded, raw, n_raw);
 }
 
 gboolean
-gck_padding_pkcs1_unpad_02 (GckAllocator alloc, gsize block, gconstpointer padded,
+egg_padding_pkcs1_unpad_02 (EggAllocator alloc, gsize block, gconstpointer padded,
                              gsize n_padded, gpointer *raw, gsize *n_raw)
 {
 	return unpad_pkcs1 (0x02, alloc, block, padded, n_padded, raw, n_raw);
 }
 
 gboolean
-gck_padding_pkcs7_pad (GckAllocator alloc, gsize block, gconstpointer raw,
+egg_padding_pkcs7_pad (EggAllocator alloc, gsize block, gconstpointer raw,
                        gsize n_raw, gpointer *padded, gsize *n_padded)
 {
 	guchar *pad;
@@ -256,7 +259,7 @@ gck_padding_pkcs7_pad (GckAllocator alloc, gsize block, gconstpointer raw,
 }
 
 gboolean
-gck_padding_pkcs7_unpad (GckAllocator alloc, gsize block, gconstpointer padded,
+egg_padding_pkcs7_unpad (EggAllocator alloc, gsize block, gconstpointer padded,
                          gsize n_padded, gpointer *raw, gsize *n_raw)
 {
 	const guchar *pad;
@@ -286,10 +289,13 @@ gck_padding_pkcs7_unpad (GckAllocator alloc, gsize block, gconstpointer padded,
 		alloc = g_realloc;
 
 	if (raw) {
-		*raw = (alloc) (NULL, MAX (*n_raw, 1));
+		*raw = (alloc) (NULL, *n_raw + 1);
 		if (*raw == NULL)
 			return FALSE;
+
+		/* Output the result, null terminated */
 		memcpy (*raw, pad, *n_raw);
+		memset (((guchar*)*raw) + *n_raw, 0, 1);
 	}
 
 	return TRUE;
diff --git a/pkcs11/gck/gck-padding.h b/egg/egg-padding.h
similarity index 81%
rename from pkcs11/gck/gck-padding.h
rename to egg/egg-padding.h
index 718e656..d953fd4 100644
--- a/pkcs11/gck/gck-padding.h
+++ b/egg/egg-padding.h
@@ -19,68 +19,70 @@
  * 02111-1307, USA.
  */
 
-#ifndef GCK_PADDING_H_
-#define GCK_PADDING_H_
+#ifndef EGG_PADDING_H_
+#define EGG_PADDING_H_
 
 #include <glib.h>
 
-typedef gpointer         (*GckAllocator)                               (gpointer,
-                                                                        gsize);
+#ifndef HAVE_EGG_ALLOCATOR
+typedef void* (*EggAllocator) (void* p, gsize);
+#define HAVE_EGG_ALLOCATOR
+#endif
 
-typedef gboolean         (*GckPadding)                                 (GckAllocator alloc,
+typedef gboolean         (*EggPadding)                                 (EggAllocator alloc,
                                                                         gsize n_block,
                                                                         gconstpointer input,
                                                                         gsize n_input,
                                                                         gpointer *output,
                                                                         gsize *n_output);
 
-gboolean                 gck_padding_zero_pad                          (GckAllocator alloc,
+gboolean                 egg_padding_zero_pad                          (EggAllocator alloc,
                                                                         gsize n_block,
                                                                         gconstpointer raw,
                                                                         gsize n_raw,
                                                                         gpointer *padded,
                                                                         gsize *n_padded);
 
-gboolean                 gck_padding_pkcs1_pad_01                     (GckAllocator alloc,
+gboolean                 egg_padding_pkcs1_pad_01                      (EggAllocator alloc,
                                                                         gsize n_block,
                                                                         gconstpointer raw,
                                                                         gsize n_raw,
                                                                         gpointer *padded,
                                                                         gsize *n_padded);
 
-gboolean                 gck_padding_pkcs1_pad_02                     (GckAllocator alloc,
+gboolean                 egg_padding_pkcs1_pad_02                      (EggAllocator alloc,
                                                                         gsize n_block,
                                                                         gconstpointer raw,
                                                                         gsize n_raw,
                                                                         gpointer *padded,
                                                                         gsize *n_padded);
 
-gboolean                 gck_padding_pkcs1_unpad_01                   (GckAllocator alloc,
+gboolean                 egg_padding_pkcs1_unpad_01                    (EggAllocator alloc,
                                                                         gsize n_block,
                                                                         gconstpointer padded,
                                                                         gsize n_padded,
                                                                         gpointer *raw,
                                                                         gsize *n_raw);
 
-gboolean                 gck_padding_pkcs1_unpad_02                   (GckAllocator alloc,
+gboolean                 egg_padding_pkcs1_unpad_02                    (EggAllocator alloc,
                                                                         gsize n_block,
                                                                         gconstpointer padded,
                                                                         gsize n_padded,
                                                                         gpointer *raw,
                                                                         gsize *n_raw);
 
-gboolean                 gck_padding_pkcs7_pad                         (GckAllocator alloc,
+gboolean                 egg_padding_pkcs7_pad                         (EggAllocator alloc,
                                                                         gsize n_block,
                                                                         gconstpointer raw,
                                                                         gsize n_raw,
                                                                         gpointer *padded,
                                                                         gsize *n_padded);
 
-gboolean                 gck_padding_pkcs7_unpad                       (GckAllocator alloc,
+gboolean                 egg_padding_pkcs7_unpad                       (EggAllocator alloc,
                                                                         gsize n_block,
                                                                         gconstpointer raw,
                                                                         gsize n_raw,
                                                                         gpointer *padded,
                                                                         gsize *n_padded);
 
-#endif /* GCK_PADDING_H_ */
+#endif /* EGG_PADDING_H_ */
diff --git a/egg/tests/Makefile.am b/egg/tests/Makefile.am
index e95b813..3bcecbc 100644
--- a/egg/tests/Makefile.am
+++ b/egg/tests/Makefile.am
@@ -7,6 +7,7 @@ UNIT_AUTO = \
 	unit-test-cleanup.c \
 	unit-test-hex.c \
 	unit-test-oid.c \
+	test-padding.c \
 	unit-test-secmem.c \
 	unit-test-symkey.c \
 	unit-test-openssl.c \
diff --git a/pkcs11/gck/tests/test-padding.c b/egg/tests/test-padding.c
similarity index 72%
rename from pkcs11/gck/tests/test-padding.c
rename to egg/tests/test-padding.c
index 1ab63c9..569f07f 100644
--- a/pkcs11/gck/tests/test-padding.c
+++ b/egg/tests/test-padding.c
@@ -27,12 +27,12 @@
 
 #include "run-auto-test.h"
 
-#include "gck/gck-padding.h"
+#include "egg/egg-padding.h"
 
 #include <gcrypt.h>
 
 static void
-test_padding (GckPadding padding, gsize block, gconstpointer input,
+test_padding (EggPadding padding, gsize block, gconstpointer input,
               gsize n_input, gconstpointer output, gsize n_output)
 {
 	gpointer result;
@@ -59,30 +59,30 @@ DEFINE_TEST(zero_padding)
 {
 	guchar padded[] = { 0x00, 0x00, 0x00, 0x00, 'T', 'E', 'S', 'T' };
 	gchar raw[] = "TEST";
-	test_padding (gck_padding_zero_pad, 8, raw, 4, padded, 8);
+	test_padding (egg_padding_zero_pad, 8, raw, 4, padded, 8);
 }
 
 DEFINE_TEST(zero_padding_no_data)
 {
 	guchar padded[] = { };
 	gchar raw[] = "";
-	test_padding (gck_padding_zero_pad, 8, raw, 0, padded, 0);
+	test_padding (egg_padding_zero_pad, 8, raw, 0, padded, 0);
 }
 
 DEFINE_TEST(pkcs1_one_padding)
 {
 	guchar padded[] = { 0x00, 0x01, 0xFF, 0x00, 'T', 'E', 'S', 'T' };
 	gchar raw[] = "TEST";
-	test_padding (gck_padding_pkcs1_pad_01, 8, raw, 4, padded, 8);
-	test_padding (gck_padding_pkcs1_unpad_01, 8, padded, 8, raw, 4);
+	test_padding (egg_padding_pkcs1_pad_01, 8, raw, 4, padded, 8);
+	test_padding (egg_padding_pkcs1_unpad_01, 8, padded, 8, raw, 4);
 }
 
 DEFINE_TEST(pkcs1_one_padding_no_data)
 {
 	guchar padded[] = { 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00 };
 	gchar raw[] = "";
-	test_padding (gck_padding_pkcs1_pad_01, 8, raw, 0, padded, 8);
-	test_padding (gck_padding_pkcs1_unpad_01, 8, padded, 8, raw, 0);
+	test_padding (egg_padding_pkcs1_pad_01, 8, raw, 0, padded, 8);
+	test_padding (egg_padding_pkcs1_unpad_01, 8, padded, 8, raw, 0);
 }
 
 DEFINE_TEST(pkcs1_two_padding)
@@ -93,10 +93,10 @@ DEFINE_TEST(pkcs1_two_padding)
 	gpointer vesult;
 	gsize n_result;
 
-	test_padding (gck_padding_pkcs1_unpad_02, 8, padded, 8, raw, 2);
+	test_padding (egg_padding_pkcs1_unpad_02, 8, padded, 8, raw, 2);
 
 	/* PKCS#1 02 padding is unpredictable */
-	if (!gck_padding_pkcs1_pad_02 (NULL, 8, raw, 2, &vesult, &n_result))
+	if (!egg_padding_pkcs1_pad_02 (NULL, 8, raw, 2, &vesult, &n_result))
 		g_assert_not_reached ();
 	result = vesult;
 	g_assert (result != NULL);
@@ -114,25 +114,25 @@ DEFINE_TEST(pkcs1_two_padding)
 DEFINE_TEST(pkcs1_padding_invalid_prefix)
 {
 	guchar padded[] = { 0x01, 0x04, 0x04, 0x04 };
-	test_padding (gck_padding_pkcs1_unpad_01, 4, padded, 4, NULL, 0);
+	test_padding (egg_padding_pkcs1_unpad_01, 4, padded, 4, NULL, 0);
 }
 
 DEFINE_TEST(pkcs1_padding_invalid_type)
 {
 	guchar padded[] = { 0x00, 0x03, 0xFF, 0x00, 'T', 'E', 'S', 'T' };
-	test_padding (gck_padding_pkcs1_unpad_01, 8, padded, 8, NULL, 0);
+	test_padding (egg_padding_pkcs1_unpad_01, 8, padded, 8, NULL, 0);
 }
 
 DEFINE_TEST(pkcs1_padding_invalid_no_zero)
 {
 	guchar padded[] = { 0x00, 0x01, 0xFF, 0xFF, 'T', 'E', 'S', 'T' };
-	test_padding (gck_padding_pkcs1_unpad_01, 8, padded, 8, NULL, 0);
+	test_padding (egg_padding_pkcs1_unpad_01, 8, padded, 8, NULL, 0);
 }
 
 DEFINE_TEST(pkcs1_padding_invalid_length)
 {
 	guchar padded[] = { 0x00, 0x01, 0xFF, 0xFF, 'T', 'E', 'S' };
-	test_padding (gck_padding_pkcs1_unpad_01, 8, padded, 7, NULL, 0);
+	test_padding (egg_padding_pkcs1_unpad_01, 8, padded, 7, NULL, 0);
 }
 
 DEFINE_TEST(pkcs7_padding)
@@ -140,8 +140,8 @@ DEFINE_TEST(pkcs7_padding)
 	guchar padded[] = { 'T', 'E', 'S', 'T', 0x04, 0x04, 0x04, 0x04 };
 	gchar raw[] = "TEST";
 
-	test_padding (gck_padding_pkcs7_pad, 8, raw, 4, padded, 8);
-	test_padding (gck_padding_pkcs7_unpad, 8, padded, 8, raw, 4);
+	test_padding (egg_padding_pkcs7_pad, 8, raw, 4, padded, 8);
+	test_padding (egg_padding_pkcs7_unpad, 8, padded, 8, raw, 4);
 }
 
 DEFINE_TEST(pkcs7_padding_equal_block)
@@ -149,8 +149,8 @@ DEFINE_TEST(pkcs7_padding_equal_block)
 	guchar padded[] = { 'T', 'E', 'S', 'T', 'T', 'E', 'S', 'T', 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 };
 	gchar raw[] = "TESTTEST";
 
-	test_padding (gck_padding_pkcs7_pad, 8, raw, 8, padded, 16);
-	test_padding (gck_padding_pkcs7_unpad, 8, padded, 16, raw, 8);
+	test_padding (egg_padding_pkcs7_pad, 8, raw, 8, padded, 16);
+	test_padding (egg_padding_pkcs7_unpad, 8, padded, 16, raw, 8);
 }
 
 DEFINE_TEST(pkcs7_padding_zero)
@@ -158,25 +158,25 @@ DEFINE_TEST(pkcs7_padding_zero)
 	guchar padded[] = { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 };
 	gchar raw[] = "";
 
-	test_padding (gck_padding_pkcs7_pad, 8, raw, 0, padded, 8);
-	test_padding (gck_padding_pkcs7_unpad, 8, padded, 8, raw, 0);
+	test_padding (egg_padding_pkcs7_pad, 8, raw, 0, padded, 8);
+	test_padding (egg_padding_pkcs7_unpad, 8, padded, 8, raw, 0);
 }
 
 DEFINE_TEST(pkcs7_padding_invalid_zero)
 {
 	guchar padded[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-	test_padding (gck_padding_pkcs7_unpad, 8, padded, 8, NULL, 0);
+	test_padding (egg_padding_pkcs7_unpad, 8, padded, 8, NULL, 0);
 }
 
 DEFINE_TEST(pkcs7_padding_invalid_too_long)
 {
 	guchar padded[] = { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 };
-	test_padding (gck_padding_pkcs7_unpad, 4, padded, 8, NULL, 0);
-	test_padding (gck_padding_pkcs7_unpad, 4, padded, 4, NULL, 0);
+	test_padding (egg_padding_pkcs7_unpad, 4, padded, 8, NULL, 0);
+	test_padding (egg_padding_pkcs7_unpad, 4, padded, 4, NULL, 0);
 }
 
 DEFINE_TEST(pkcs7_padding_invalid_different)
 {
 	guchar padded[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
-	test_padding (gck_padding_pkcs7_unpad, 8, padded, 8, NULL, 0);
+	test_padding (egg_padding_pkcs7_unpad, 8, padded, 8, NULL, 0);
 }
diff --git a/pkcs11/gck/Makefile.am b/pkcs11/gck/Makefile.am
index 7fe5cc4..6d04a55 100644
--- a/pkcs11/gck/Makefile.am
+++ b/pkcs11/gck/Makefile.am
@@ -43,7 +43,6 @@ libgck_la_SOURCES = \
 	gck-null-key.c gck-null-key.h \
 	gck-null-mechanism.c gck-null-mechanism.h \
 	gck-object.c gck-object.h \
-	gck-padding.c gck-padding.h \
 	gck-private-xsa-key.c gck-private-xsa-key.h \
 	gck-public-xsa-key.c gck-public-xsa-key.h \
 	gck-secret.c gck-secret.h \
diff --git a/pkcs11/gck/gck-aes-mechanism.c b/pkcs11/gck/gck-aes-mechanism.c
index b2c5342..b8cecff 100644
--- a/pkcs11/gck/gck-aes-mechanism.c
+++ b/pkcs11/gck/gck-aes-mechanism.c
@@ -23,12 +23,12 @@
 
 #include "gck-aes-key.h"
 #include "gck-aes-mechanism.h"
-#include "gck-padding.h"
 #include "gck-session.h"
 #include "gck-transaction.h"
 #include "gck-util.h"
 
 #include "egg/egg-libgcrypt.h"
+#include "egg/egg-padding.h"
 #include "egg/egg-secure-memory.h"
 
 static gboolean
@@ -98,7 +98,7 @@ gck_aes_mechanism_wrap (GckSession *session, CK_MECHANISM_PTR mech,
 	if (!output) {
 		if (!retrieve_length (session, wrapped, &n_value))
 			return CKR_KEY_NOT_WRAPPABLE;
-		if (!gck_padding_pkcs7_pad (NULL, block, NULL, n_value, NULL, &n_padded))
+		if (!egg_padding_pkcs7_pad (NULL, block, NULL, n_value, NULL, &n_padded))
 			return CKR_KEY_SIZE_RANGE;
 		*n_output = n_padded;
 		return CKR_OK;
@@ -119,7 +119,7 @@ gck_aes_mechanism_wrap (GckSession *session, CK_MECHANISM_PTR mech,
 		return CKR_KEY_NOT_WRAPPABLE;
 	}
 
-	ret = gck_padding_pkcs7_pad (egg_secure_realloc, block, value, n_value, &padded, &n_padded);
+	ret = egg_padding_pkcs7_pad (egg_secure_realloc, block, value, n_value, &padded, &n_padded);
 	egg_secure_free (value);
 
 	if (ret == FALSE) {
@@ -194,7 +194,7 @@ gck_aes_mechanism_unwrap (GckSession *session, CK_MECHANISM_PTR mech,
 	gcry_cipher_close (cih);
 
 	/* Unpad the resulting value */
-	ret = gck_padding_pkcs7_unpad (egg_secure_realloc, block, padded, n_padded, &value, &n_value);
+	ret = egg_padding_pkcs7_unpad (egg_secure_realloc, block, padded, n_padded, &value, &n_value);
 	egg_secure_free (padded);
 
 	/* TODO: This is dubious, there doesn't seem to be an rv for 'bad decrypt' */
diff --git a/pkcs11/gck/gck-crypto.c b/pkcs11/gck/gck-crypto.c
index 0b90cc7..32fd20e 100644
--- a/pkcs11/gck/gck-crypto.c
+++ b/pkcs11/gck/gck-crypto.c
@@ -39,7 +39,7 @@
  */
 
 CK_RV
-gck_crypto_data_to_sexp (const gchar *format, guint nbits, GckPadding padding,
+gck_crypto_data_to_sexp (const gchar *format, guint nbits, EggPadding padding,
                          CK_BYTE_PTR data, CK_ULONG n_data, gcry_sexp_t *sexp)
 {
 	gpointer padded = NULL;
@@ -81,7 +81,7 @@ gck_crypto_data_to_sexp (const gchar *format, guint nbits, GckPadding padding,
 
 CK_RV
 gck_crypto_sexp_to_data (gcry_sexp_t sexp, guint bits, CK_BYTE_PTR data,
-                         CK_ULONG *n_data, GckPadding padding, ...)
+                         CK_ULONG *n_data, EggPadding padding, ...)
 {
 	gcry_sexp_t at = NULL;
 	gsize n_block, offset, len;
@@ -184,11 +184,11 @@ gck_crypto_encrypt_xsa (gcry_sexp_t sexp, CK_MECHANISM_TYPE mech, CK_BYTE_PTR da
 	switch (mech) {
 	case CKM_RSA_PKCS:
 		g_return_val_if_fail (algorithm == GCRY_PK_RSA, CKR_GENERAL_ERROR); 
-		rv = gck_mechanism_rsa_encrypt (sexp, gck_padding_pkcs1_pad_02, data, n_data, encrypted, n_encrypted);
+		rv = gck_mechanism_rsa_encrypt (sexp, egg_padding_pkcs1_pad_02, data, n_data, encrypted, n_encrypted);
 		break;
 	case CKM_RSA_X_509:
 		g_return_val_if_fail (algorithm == GCRY_PK_RSA, CKR_GENERAL_ERROR);
-		rv = gck_mechanism_rsa_encrypt (sexp, gck_padding_zero_pad, data, n_data, encrypted, n_encrypted);
+		rv = gck_mechanism_rsa_encrypt (sexp, egg_padding_zero_pad, data, n_data, encrypted, n_encrypted);
 		break;
 	default:
 		/* Again shouldn't be reached */
@@ -238,7 +238,7 @@ gck_crypto_decrypt_xsa (gcry_sexp_t sexp, CK_MECHANISM_TYPE mech, CK_BYTE_PTR en
 	switch (mech) {
 	case CKM_RSA_PKCS:
 		g_return_val_if_fail (algorithm == GCRY_PK_RSA, CKR_GENERAL_ERROR); 
-		rv = gck_mechanism_rsa_decrypt (sexp, gck_padding_pkcs1_unpad_02, encrypted, n_encrypted, data, n_data);
+		rv = gck_mechanism_rsa_decrypt (sexp, egg_padding_pkcs1_unpad_02, encrypted, n_encrypted, data, n_data);
 		break;
 	case CKM_RSA_X_509:
 		g_return_val_if_fail (algorithm == GCRY_PK_RSA, CKR_GENERAL_ERROR);
@@ -293,11 +293,11 @@ gck_crypto_sign_xsa (gcry_sexp_t sexp, CK_MECHANISM_TYPE mech, CK_BYTE_PTR data,
 	switch (mech) {
 	case CKM_RSA_PKCS:
 		g_return_val_if_fail (algorithm == GCRY_PK_RSA, CKR_GENERAL_ERROR); 
-		rv = gck_mechanism_rsa_sign (sexp, gck_padding_pkcs1_pad_01, data, n_data, signature, n_signature);
+		rv = gck_mechanism_rsa_sign (sexp, egg_padding_pkcs1_pad_01, data, n_data, signature, n_signature);
 		break;
 	case CKM_RSA_X_509:
 		g_return_val_if_fail (algorithm == GCRY_PK_RSA, CKR_GENERAL_ERROR);
-		rv = gck_mechanism_rsa_sign (sexp, gck_padding_zero_pad, data, n_data, signature, n_signature);
+		rv = gck_mechanism_rsa_sign (sexp, egg_padding_zero_pad, data, n_data, signature, n_signature);
 		break;
 	case CKM_DSA:
 		g_return_val_if_fail (algorithm == GCRY_PK_DSA, CKR_GENERAL_ERROR);
@@ -352,11 +352,11 @@ gck_crypto_verify_xsa (gcry_sexp_t sexp, CK_MECHANISM_TYPE mech, CK_BYTE_PTR dat
 	switch (mech) {
 	case CKM_RSA_PKCS:
 		g_return_val_if_fail (algorithm == GCRY_PK_RSA, CKR_GENERAL_ERROR); 
-		rv = gck_mechanism_rsa_verify (sexp, gck_padding_pkcs1_pad_01, data, n_data, signature, n_signature);
+		rv = gck_mechanism_rsa_verify (sexp, egg_padding_pkcs1_pad_01, data, n_data, signature, n_signature);
 		break;
 	case CKM_RSA_X_509:
 		g_return_val_if_fail (algorithm == GCRY_PK_RSA, CKR_GENERAL_ERROR);
-		rv = gck_mechanism_rsa_verify (sexp, gck_padding_zero_pad, data, n_data, signature, n_signature);
+		rv = gck_mechanism_rsa_verify (sexp, egg_padding_zero_pad, data, n_data, signature, n_signature);
 		break;
 	case CKM_DSA:
 		g_return_val_if_fail (algorithm == GCRY_PK_DSA, CKR_GENERAL_ERROR);
diff --git a/pkcs11/gck/gck-crypto.h b/pkcs11/gck/gck-crypto.h
index 9921ee5..d9c60b3 100644
--- a/pkcs11/gck/gck-crypto.h
+++ b/pkcs11/gck/gck-crypto.h
@@ -22,11 +22,12 @@
 #ifndef GCKCRYPTO_H_
 #define GCKCRYPTO_H_
 
-#include "gck-padding.h"
 #include "gck-types.h"
 
 #include "pkcs11/pkcs11.h"
 
+#include "egg/egg-padding.h"
+
 #include <glib.h>
 
 #include <gcrypt.h>
@@ -109,12 +110,12 @@ CK_RV                    gck_crypto_sexp_to_data                       (gcry_sex
                                                                         guint bits,
                                                                         CK_BYTE_PTR data,
                                                                         CK_ULONG *n_data,
-                                                                        GckPadding padding,
+                                                                        EggPadding padding,
                                                                         ...) G_GNUC_NULL_TERMINATED;
 
 CK_RV                    gck_crypto_data_to_sexp                       (const gchar *format,
                                                                         guint nbits,
-                                                                        GckPadding padding,
+                                                                        EggPadding padding,
                                                                         CK_BYTE_PTR data,
                                                                         CK_ULONG n_data,
                                                                         gcry_sexp_t *sexp);
diff --git a/pkcs11/gck/gck-mechanism-rsa.c b/pkcs11/gck/gck-mechanism-rsa.c
index 2d3a253..8210258 100644
--- a/pkcs11/gck/gck-mechanism-rsa.c
+++ b/pkcs11/gck/gck-mechanism-rsa.c
@@ -32,7 +32,7 @@
  */
 
 CK_RV
-gck_mechanism_rsa_encrypt (gcry_sexp_t sexp, GckPadding padding, CK_BYTE_PTR data,
+gck_mechanism_rsa_encrypt (gcry_sexp_t sexp, EggPadding padding, CK_BYTE_PTR data,
                            CK_ULONG n_data, CK_BYTE_PTR encrypted, CK_ULONG_PTR n_encrypted)
 {
 	gcry_sexp_t splain, sdata;
@@ -78,7 +78,7 @@ gck_mechanism_rsa_encrypt (gcry_sexp_t sexp, GckPadding padding, CK_BYTE_PTR dat
 }
 
 CK_RV
-gck_mechanism_rsa_decrypt (gcry_sexp_t sexp, GckPadding padding, CK_BYTE_PTR encrypted,
+gck_mechanism_rsa_decrypt (gcry_sexp_t sexp, EggPadding padding, CK_BYTE_PTR encrypted,
                            CK_ULONG n_encrypted, CK_BYTE_PTR data, CK_ULONG_PTR n_data)
 {
 	gcry_sexp_t splain, sdata;
@@ -126,7 +126,7 @@ gck_mechanism_rsa_decrypt (gcry_sexp_t sexp, GckPadding padding, CK_BYTE_PTR enc
 }
 
 CK_RV
-gck_mechanism_rsa_sign (gcry_sexp_t sexp, GckPadding padding, CK_BYTE_PTR data,
+gck_mechanism_rsa_sign (gcry_sexp_t sexp, EggPadding padding, CK_BYTE_PTR data,
                         CK_ULONG n_data, CK_BYTE_PTR signature, CK_ULONG_PTR n_signature)
 {
 	gcry_sexp_t ssig, sdata;
@@ -171,7 +171,7 @@ gck_mechanism_rsa_sign (gcry_sexp_t sexp, GckPadding padding, CK_BYTE_PTR data,
 }
 
 CK_RV
-gck_mechanism_rsa_verify (gcry_sexp_t sexp, GckPadding padding, CK_BYTE_PTR data,
+gck_mechanism_rsa_verify (gcry_sexp_t sexp, EggPadding padding, CK_BYTE_PTR data,
                           CK_ULONG n_data, CK_BYTE_PTR signature, CK_ULONG n_signature)
 {
 	gcry_sexp_t ssig, sdata;
diff --git a/pkcs11/gck/gck-mechanism-rsa.h b/pkcs11/gck/gck-mechanism-rsa.h
index fd8e7e0..b0ede3c 100644
--- a/pkcs11/gck/gck-mechanism-rsa.h
+++ b/pkcs11/gck/gck-mechanism-rsa.h
@@ -37,28 +37,28 @@ static const CK_MECHANISM_TYPE GCK_CRYPTO_RSA_MECHANISMS[] = {
 };
 
 CK_RV                    gck_mechanism_rsa_encrypt                     (gcry_sexp_t sexp,
-                                                                        GckPadding padding,
+                                                                        EggPadding padding,
                                                                         CK_BYTE_PTR data,
                                                                         CK_ULONG n_data,
                                                                         CK_BYTE_PTR encrypted,
                                                                         CK_ULONG_PTR n_encrypted);
 
 CK_RV                    gck_mechanism_rsa_decrypt                     (gcry_sexp_t sexp,
-                                                                        GckPadding padding,
+                                                                        EggPadding padding,
                                                                         CK_BYTE_PTR encrypted,
                                                                         CK_ULONG n_encrypted,
                                                                         CK_BYTE_PTR data,
                                                                         CK_ULONG_PTR n_data);
 
 CK_RV                    gck_mechanism_rsa_sign                        (gcry_sexp_t sexp,
-                                                                        GckPadding padding,
+                                                                        EggPadding padding,
                                                                         CK_BYTE_PTR data,
                                                                         CK_ULONG n_data,
                                                                         CK_BYTE_PTR signature,
                                                                         CK_ULONG_PTR n_signature);
 
 CK_RV                    gck_mechanism_rsa_verify                      (gcry_sexp_t sexp,
-                                                                        GckPadding padding,
+                                                                        EggPadding padding,
                                                                         CK_BYTE_PTR data,
                                                                         CK_ULONG n_data,
                                                                         CK_BYTE_PTR signature,
diff --git a/pkcs11/gck/gck-null-mechanism.c b/pkcs11/gck/gck-null-mechanism.c
index df4a795..149aea5 100644
--- a/pkcs11/gck/gck-null-mechanism.c
+++ b/pkcs11/gck/gck-null-mechanism.c
@@ -23,7 +23,6 @@
 
 #include "gck-null-key.h"
 #include "gck-null-mechanism.h"
-#include "gck-padding.h"
 #include "gck-session.h"
 #include "gck-transaction.h"
 #include "gck-util.h"
diff --git a/pkcs11/gck/tests/Makefile.am b/pkcs11/gck/tests/Makefile.am
index a9cad0e..1a16b2b 100644
--- a/pkcs11/gck/tests/Makefile.am
+++ b/pkcs11/gck/tests/Makefile.am
@@ -6,7 +6,6 @@ asn1-def-test.h: test.asn
 UNIT_AUTO = \
 	unit-test-attributes.c \
 	unit-test-sexp.c \
-	test-padding.c \
 	unit-test-data-asn1.c \
 	unit-test-data-der.c \
 	unit-test-object.c \



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]