]> www.average.org Git - pam_pcsc_cr.git/commitdiff
crypto interface
authorEugene Crosser <Eugene.Crosser@ru.ibm.com>
Tue, 29 Oct 2013 15:49:29 +0000 (19:49 +0400)
committerEugene Crosser <Eugene.Crosser@ru.ibm.com>
Tue, 29 Oct 2013 15:49:29 +0000 (19:49 +0400)
Makefile.am
crypto.c
crypto_if.h [new file with mode: 0644]
ossl_crypto.c

index e83b179e26a16c5468410fb4d69d9bd54194f18d..23711acba19c056e87359fe0cff182c67457245f 100644 (file)
@@ -3,11 +3,11 @@
 AUTOMAKE_OPTIONS = foreign
 ACLOCAL_AMFLAGS = -I m4
 
-noinst_HEADERS = pcsc_cr.h token.h
+noinst_HEADERS = pcsc_cr.h token.h crypto_if.h crypto.h
 
 EXTRA_LTLIBRARIES = libpcsc_cr.la
 libpcsc_cr_la_SOURCES = crypto.c pcsc_cr.c ykneo.c
-EXTRA_libpcsc_cr_la_SOURCES = ossl_crypto.c tom_prypto.c
+EXTRA_libpcsc_cr_la_SOURCES = ossl_crypto.c tom_crypto.c
 libpcsc_cr_la_LIBADD = @CRYPTO_OBJS@
 libpcsc_cr_la_DEPENDENCIES = @CRYPTO_OBJS@
 
index ab6a3c44ad5750376fbf4d0597d161421b7dad67..83ba4efd1d35d0ae618f6cd0f1353b0568075b83 100644 (file)
--- a/crypto.c
+++ b/crypto.c
@@ -1,30 +1,28 @@
-#include <openssl/evp.h>
-#include <openssl/hmac.h>
+#include "crypto.h"
+#include "crypto_if.h"
 
-//int main()
-//{
-//    EVP_CIPHER_CTX ctx;
-//    unsigned char key[32] = {0};
-//    unsigned char iv[16] = {0};
-//    unsigned char in[16] = {0};
-//    unsigned char out[32]; /* at least one block longer than in[] */
-//    int outlen1, outlen2;
-//
-//    EVP_EncryptInit(&ctx, EVP_aes_256_cbc(), key, iv);
-//    EVP_EncryptUpdate(&ctx, out, &outlen1, in, sizeof(in));
-//    EVP_EncryptFinal(&ctx, out + outlen1, &outlen2);
-//
-//    printf("ciphertext length: %d\n", outlen1 + outlen2);
-//
-//    return 0;
-//}
+extern struct crypto_interface ossl_crypto_if;
+extern struct crypto_interface tom_crypto_if;
 
-// result = HMAC(EVP_sha256(), key, 999, data, 888, NULL, NULL);
-//               EVP_MD *
+static struct crypto_interface *active = &ossl_crypto_if;
+
+int encrypt(void *pt, int ptlen, void *key, int keylen, void *ct, int *ctlen)
+{
+       return active->encrypt(pt, ptlen, key, keylen, ct, ctlen);
+}
+
+int decrypt(void *ct, int ctlen, void *key, int keylen, void *pt, int *ptlen)
+{
+       return active->decrypt(ct, ctlen, key, keylen, pt, ptlen);
+}
+
+int hash(void *pt, int ptlen, void *tag, int *taglen)
+{
+       return active->hash(pt, ptlen, tag, taglen);
+}
+
+int hmac(void *pt, int ptlen, void *key, int keylen, void *tag, int *taglen)
+{
+       return active->hmac(pt, ptlen, key, keylen, tag, taglen);
+}
 
-// HMAC_CTX hctx;
-// HMAC_CTX_init(&hctx);
-// if (HMAC_Init(&hctx, key, keylen, EVP_sha1())) success;
-// if (HMAC_Update(&hctx, data, datalen)) success;
-// if (HMAC_Final(&hctx, &digest, &digestlen)) success
-// HMAC_CTX_cleanup(&hctx);
diff --git a/crypto_if.h b/crypto_if.h
new file mode 100644 (file)
index 0000000..488a0e6
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef _CRYPTO_IF_H
+#define _CRYPTO_IF_H
+
+struct crypto_interface {
+       char *name;
+       int (*encrypt)(void *pt, int ptlen, void *key, int keylen,
+                       void *ct, int *ctlen);
+       int (*decrypt)(void *ct, int ctlen, void *key, int keylen,
+                       void *pt, int *ptlen);
+       int (*hash)(void *pt, int ptlen, void *tag, int *taglen);
+       int (*hmac)(void *ct, int ctlen, void *key, int keylen,
+                       void *tag, int *taglen);
+};
+
+#endif
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..61c6504cf0e0688c3193793dc28f50f5797cad3f 100644 (file)
@@ -0,0 +1,53 @@
+#include <openssl/evp.h>
+#include <openssl/hmac.h>
+
+#include "crypto_if.h"
+
+static int ossl_encrypt(void *pt, int ptlen, void *key, int keylen,
+                       void *ct, int *ctlen)
+{
+    EVP_CIPHER_CTX ctx;
+    unsigned char iv[16] = {0};
+    int outlen1, outlen2;
+
+    EVP_EncryptInit(&ctx, EVP_aes_256_cbc(), key, iv);
+    EVP_EncryptUpdate(&ctx, ct, &outlen1, pt, ptlen);
+    EVP_EncryptFinal(&ctx, ct + outlen1, &outlen2);
+    if (outlen1 + outlen2 > *ctlen) return -1;
+    *ctlen = outlen1 + outlen2;
+
+    return 0;
+}
+
+static int ossl_decrypt()
+{
+       return 0;
+}
+
+static int ossl_hash()
+{
+       return 0;
+}
+
+static int ossl_hmac()
+{
+       return 0;
+}
+
+// result = HMAC(EVP_sha256(), key, 999, data, 888, NULL, NULL);
+//               EVP_MD *
+
+// HMAC_CTX hctx;
+// HMAC_CTX_init(&hctx);
+// if (HMAC_Init(&hctx, key, keylen, EVP_sha1())) success;
+// if (HMAC_Update(&hctx, data, datalen)) success;
+// if (HMAC_Final(&hctx, &digest, &digestlen)) success
+// HMAC_CTX_cleanup(&hctx);
+
+struct crypto_interface ossl_crypto_if = {
+       .name           = "openssl",
+       .encrypt        = ossl_encrypt,
+       .decrypt        = ossl_decrypt,
+       .hash           = ossl_hash,
+       .hmac           = ossl_hmac,
+};