Make CMAC API similar to HMAC API. Add methods for CMAC.
authorDr. Stephen Henson <steve@openssl.org>
Mon, 8 Feb 2010 15:31:35 +0000 (15:31 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Mon, 8 Feb 2010 15:31:35 +0000 (15:31 +0000)
14 files changed:
CHANGES
crypto/asn1/ameth_lib.c
crypto/cmac/Makefile
crypto/cmac/cm_ameth.c [new file with mode: 0644]
crypto/cmac/cm_pmeth.c [new file with mode: 0644]
crypto/cmac/cmac.c
crypto/cmac/cmac.h
crypto/evp/evp.h
crypto/evp/m_sigver.c
crypto/evp/pmeth_lib.c
crypto/objects/obj_dat.h
crypto/objects/obj_mac.h
crypto/objects/obj_mac.num
crypto/objects/objects.txt

diff --git a/CHANGES b/CHANGES
index bce3fcf79efc64357fa8b678969567e3d0763304..1c703747efa9ade48953dcce60642f4bee8aac8a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -5,6 +5,7 @@
  Changes between 1.0.0 and 1.1.0  [xx XXX xxxx]
 
   *) Initial CMAC implementation. WARNING: EXPERIMENTAL, API MAY CHANGE.
+     Add CMAC pkey methods.
      [Steve Henson]
 
   *) Experiemental regnegotiation in s_server -www mode. If the client 
index 9a8b6cc22264f6f35ffef862e9d389ea1204f4db..626e15cc9cc9d43129f3554ecc73bc24df6f18bc 100644 (file)
@@ -69,6 +69,7 @@ extern const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[];
 extern const EVP_PKEY_ASN1_METHOD dh_asn1_meth;
 extern const EVP_PKEY_ASN1_METHOD eckey_asn1_meth;
 extern const EVP_PKEY_ASN1_METHOD hmac_asn1_meth;
+extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth;
 
 /* Keep this sorted in type order !! */
 static const EVP_PKEY_ASN1_METHOD *standard_methods[] = 
@@ -90,7 +91,8 @@ static const EVP_PKEY_ASN1_METHOD *standard_methods[] =
 #ifndef OPENSSL_NO_EC
        &eckey_asn1_meth,
 #endif
-       &hmac_asn1_meth
+       &hmac_asn1_meth,
+       &cmac_asn1_meth
        };
 
 typedef int sk_cmp_fn_type(const char * const *a, const char * const *b);
index 7a960f61222dce36a0894aeb8fa758d61ba85e39..80bb676ac6c2dff8d885579b6472d0284564df8c 100644 (file)
@@ -17,8 +17,8 @@ TEST=
 APPS=
 
 LIB=$(TOP)/libcrypto.a
-LIBSRC=cmac.c
-LIBOBJ=cmac.o
+LIBSRC=cmac.c cm_ameth.c cm_pmeth.c
+LIBOBJ=cmac.o cm_ameth.o cm_pmeth.o
 
 SRC= $(LIBSRC)
 
diff --git a/crypto/cmac/cm_ameth.c b/crypto/cmac/cm_ameth.c
new file mode 100644 (file)
index 0000000..58a1a9d
--- /dev/null
@@ -0,0 +1,102 @@
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2010.
+ */
+/* ====================================================================
+ * Copyright (c) 2010 The OpenSSL Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ *    software must display the following acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/evp.h>
+#include <openssl/cmac.h>
+#include "asn1_locl.h"
+
+/* CMAC "ASN1" method. This is just here to indicate the
+ * maximum CMAC output length and to free up a CMAC
+ * key.
+ */
+
+static int cmac_size(const EVP_PKEY *pkey)
+       {
+       return EVP_MAX_BLOCK_LENGTH;
+       }
+
+static void cmac_key_free(EVP_PKEY *pkey)
+       {
+       CMAC_CTX *cmctx = (CMAC_CTX *)pkey->pkey.ptr;
+       if (cmctx)
+               CMAC_CTX_free(cmctx);
+       }
+
+const EVP_PKEY_ASN1_METHOD cmac_asn1_meth = 
+       {
+       EVP_PKEY_CMAC,
+       EVP_PKEY_CMAC,
+       0,
+
+       "CMAC",
+       "OpenSSL CMAC method",
+
+       0,0,0,0,
+
+       0,0,0,
+
+       cmac_size,
+       0,
+       0,0,0,0,0,0,
+
+       cmac_key_free,
+       0,
+       0,0
+       };
+
diff --git a/crypto/cmac/cm_pmeth.c b/crypto/cmac/cm_pmeth.c
new file mode 100644 (file)
index 0000000..585fc8e
--- /dev/null
@@ -0,0 +1,229 @@
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+ * project 2010.
+ */
+/* ====================================================================
+ * Copyright (c) 2010 The OpenSSL Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ *    software must display the following acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <openssl/x509.h>
+#include <openssl/x509v3.h>
+#include <openssl/evp.h>
+#include <openssl/cmac.h>
+#include "evp_locl.h"
+
+/* The context structure and "key" is simply a CMAC_CTX */
+
+static int pkey_cmac_init(EVP_PKEY_CTX *ctx)
+       {
+       ctx->data = CMAC_CTX_new();
+       if (!ctx->data)
+               return 0;
+       ctx->keygen_info_count = 0;
+       return 1;
+       }
+
+static int pkey_cmac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
+       {
+       if (!pkey_cmac_init(dst))
+               return 0;
+       if (!CMAC_CTX_copy(dst->data, src->data))
+               return 0;
+       return 1;
+       }
+
+static void pkey_cmac_cleanup(EVP_PKEY_CTX *ctx)
+       {
+       CMAC_CTX_free(ctx->data);
+       }
+
+static int pkey_cmac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
+       {
+       CMAC_CTX *cmkey = CMAC_CTX_new();
+       CMAC_CTX *cmctx = ctx->data;
+       if (!cmkey)
+               return 0;
+       if (!CMAC_CTX_copy(cmkey, cmctx))
+               {
+               CMAC_CTX_free(cmkey);
+               return 0;
+               }
+       EVP_PKEY_assign(pkey, EVP_PKEY_CMAC, cmkey);
+       
+       return 1;
+       }
+
+static int int_update(EVP_MD_CTX *ctx,const void *data,size_t count)
+       {
+       if (!CMAC_Update(ctx->pctx->data, data, count))
+               return 0;
+       return 1;
+       }
+
+static int cmac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
+       {
+       EVP_MD_CTX_set_flags(mctx, EVP_MD_CTX_FLAG_NO_INIT);
+       mctx->update = int_update;
+       return 1;
+       }
+
+static int cmac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
+                                       EVP_MD_CTX *mctx)
+       {
+       return CMAC_Final(ctx->data, sig, siglen);
+       }
+
+static int pkey_cmac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
+       {
+       CMAC_CTX *cmctx = ctx->data;
+       switch (type)
+               {
+
+               case EVP_PKEY_CTRL_SET_MAC_KEY:
+               if (!p2 || p1 < 0)
+                       return 0;
+               if (!CMAC_Init(cmctx, p2, p1, NULL, NULL))
+                       return 0;
+               break;
+
+               case EVP_PKEY_CTRL_CIPHER:
+               if (!CMAC_Init(cmctx, NULL, 0, p2, NULL))
+                       return 0;
+               break;
+
+               case EVP_PKEY_CTRL_MD:
+               if (ctx->pkey && !CMAC_CTX_copy(ctx->data,
+                                       (CMAC_CTX *)ctx->pkey->pkey.ptr))
+                       return 0;
+               if (!CMAC_Init(cmctx, NULL, 0, NULL, NULL))
+                       return 0;
+               break;
+
+               default:
+               return -2;
+
+               }
+       return 1;
+       }
+
+static int pkey_cmac_ctrl_str(EVP_PKEY_CTX *ctx,
+                       const char *type, const char *value)
+       {
+       if (!value)
+               {
+               return 0;
+               }
+       if (!strcmp(type, "key"))
+               {
+               void *p = (void *)value;
+               return pkey_cmac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY,
+                                                               strlen(p), p);
+               }
+       if (!strcmp(type, "cipher"))
+               {
+               const EVP_CIPHER *c;
+               c = EVP_get_cipherbyname(value);
+               if (!c)
+                       return 0;
+               return pkey_cmac_ctrl(ctx, EVP_PKEY_CTRL_CIPHER, -1, (void *)c);
+               }
+       if (!strcmp(type, "hexkey"))
+               {
+               unsigned char *key;
+               int r;
+               long keylen;
+               key = string_to_hex(value, &keylen);
+               if (!key)
+                       return 0;
+               r = pkey_cmac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, keylen, key);
+               OPENSSL_free(key);
+               return r;
+               }
+       return -2;
+       }
+
+const EVP_PKEY_METHOD cmac_pkey_meth = 
+       {
+       EVP_PKEY_CMAC,
+       EVP_PKEY_FLAG_SIGCTX_CUSTOM,
+       pkey_cmac_init,
+       pkey_cmac_copy,
+       pkey_cmac_cleanup,
+
+       0, 0,
+
+       0,
+       pkey_cmac_keygen,
+
+       0, 0,
+
+       0, 0,
+
+       0,0,
+
+       cmac_signctx_init,
+       cmac_signctx,
+
+       0,0,
+
+       0,0,
+
+       0,0,
+
+       0,0,
+
+       pkey_cmac_ctrl,
+       pkey_cmac_ctrl_str
+
+       };
index 5ec88b3ad7300a777815c3b5d0a825dc58f5a843..307e93ddf582e5fd1d8ac3bed1b706808b102293 100644 (file)
@@ -122,6 +122,22 @@ void CMAC_CTX_free(CMAC_CTX *ctx)
        OPENSSL_free(ctx);
        }
 
+int CMAC_CTX_copy(CMAC_CTX *out, const CMAC_CTX *in)
+       {
+       int bl;
+       if (in->nlast_block == -1)
+               return 0;
+       if (!EVP_CIPHER_CTX_copy(&out->cctx, &in->cctx))
+               return 0;
+       bl = EVP_CIPHER_CTX_block_size(&in->cctx);
+       memcpy(out->k1, in->k1, bl);
+       memcpy(out->k2, in->k2, bl);
+       memcpy(out->tbl, in->tbl, bl);
+       memcpy(out->last_block, in->last_block, bl);
+       out->nlast_block = in->nlast_block;
+       return 1;
+       }
+
 int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen, 
                        const EVP_CIPHER *cipher, ENGINE *impl)
        {
@@ -130,11 +146,11 @@ int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen,
        if (!key && !cipher && !impl && keylen == 0)
                {
                /* Not initialised */
-               if (ctx->last_block == -1)
+               if (ctx->nlast_block == -1)
                        return 0;
                if (!EVP_EncryptInit_ex(&ctx->cctx, NULL, NULL, NULL, zero_iv))
                        return 0;
-               return 0;
+               return 1;
                }
        /* Initialiase context */
        if (cipher && !EVP_EncryptInit_ex(&ctx->cctx, cipher, impl, NULL, NULL))
@@ -158,6 +174,8 @@ int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen,
                /* Reset context again ready for first data block */
                if (!EVP_EncryptInit_ex(&ctx->cctx, NULL, NULL, NULL, zero_iv))
                        return 0;
+               /* Zero tbl so resume works */
+               memset(ctx->tbl, 0, bl);
                ctx->nlast_block = 0;
                }
        return 1;
@@ -205,18 +223,21 @@ int CMAC_Update(CMAC_CTX *ctx, const void *in, size_t dlen)
 
        }
 
-size_t CMAC_Final(CMAC_CTX *ctx, unsigned char *out)
+int CMAC_Final(CMAC_CTX *ctx, unsigned char *out, size_t *poutlen)
        {
        int i, bl, lb;
        if (ctx->nlast_block == -1)
                return 0;
        bl = EVP_CIPHER_CTX_block_size(&ctx->cctx);
+       *poutlen = (size_t)bl;
+       if (!out)
+               return 1;
        lb = ctx->nlast_block;
        /* Is last block complete? */
        if (lb == bl)
                {
                for (i = 0; i < bl; i++)
-                       ctx->last_block[i] ^= ctx->k1[i];
+                       out[i] = ctx->last_block[i] ^ ctx->k1[i];
                }
        else
                {
@@ -224,9 +245,25 @@ size_t CMAC_Final(CMAC_CTX *ctx, unsigned char *out)
                if (bl - lb > 1)
                        memset(ctx->last_block + lb + 1, 0, bl - lb - 1);
                for (i = 0; i < bl; i++)
-                       ctx->last_block[i] ^= ctx->k2[i];
+                       out[i] = ctx->last_block[i] ^ ctx->k2[i];
                }
-       if (!EVP_Cipher(&ctx->cctx, out, ctx->last_block, bl))
+       if (!EVP_Cipher(&ctx->cctx, out, out, bl))
+               {
+               OPENSSL_cleanse(out, bl);       
+               return 0;
+               }
+       return 1;
+       }
+
+int CMAC_resume(CMAC_CTX *ctx)
+       {
+       if (ctx->nlast_block == -1)
                return 0;
-       return bl;
+       /* The buffer "tbl" containes the last fully encrypted block
+        * which is the last IV (or all zeroes if no last encrypted block).
+        * The last block has not been modified since CMAC_final().
+        * So reinitliasing using the last decrypted block will allow
+        * CMAC to continue after calling CMAC_Final(). 
+        */
+       return EVP_EncryptInit_ex(&ctx->cctx, NULL, NULL, NULL, ctx->tbl);
        }
index 294b537246bd3100bec46684deabb01e7f3087f2..712e92dced2cf7fc6fd5b111228532bdd014747d 100644 (file)
@@ -68,11 +68,13 @@ CMAC_CTX *CMAC_CTX_new(void);
 void CMAC_CTX_cleanup(CMAC_CTX *ctx);
 void CMAC_CTX_free(CMAC_CTX *ctx);
 EVP_CIPHER_CTX *CMAC_CTX_get0_cipher_ctx(CMAC_CTX *ctx);
+int CMAC_CTX_copy(CMAC_CTX *out, const CMAC_CTX *in);
 
 int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen, 
                        const EVP_CIPHER *cipher, ENGINE *impl);
 int CMAC_Update(CMAC_CTX *ctx, const void *data, size_t dlen);
-int CMAC_Final(CMAC_CTX *ctx, unsigned char *out);
+int CMAC_Final(CMAC_CTX *ctx, unsigned char *out, size_t *poutlen);
+int CMAC_resume(CMAC_CTX *ctx);
 
 #ifdef  __cplusplus
 }
index f8fbe5a58654baf569689acf9784454d2c40d2aa..96f83b8f62b3cf7da8fe540457da816182178052 100644 (file)
 #define EVP_PKEY_DH    NID_dhKeyAgreement
 #define EVP_PKEY_EC    NID_X9_62_id_ecPublicKey
 #define EVP_PKEY_HMAC  NID_hmac
+#define EVP_PKEY_CMAC  NID_cmac
 
 #ifdef __cplusplus
 extern "C" {
@@ -1042,10 +1043,16 @@ void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth,
 #define EVP_PKEY_CTRL_CMS_DECRYPT      10
 #define EVP_PKEY_CTRL_CMS_SIGN         11
 
+#define EVP_PKEY_CTRL_CIPHER           12
+
 #define EVP_PKEY_ALG_CTRL              0x1000
 
 
 #define EVP_PKEY_FLAG_AUTOARGLEN       2
+/* Method handles all operations: don't assume any digest related
+ * defaults.
+ */
+#define EVP_PKEY_FLAG_SIGCTX_CUSTOM    4
 
 const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type);
 EVP_PKEY_METHOD* EVP_PKEY_meth_new(int id, int flags);
index f0b7f95059e75f9e0f8e3aa57a898b57f23baa20..2fd35a90e4d0c2be4c3a99681079cfab7f1126cd 100644 (file)
@@ -72,17 +72,21 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
        if (ctx->pctx == NULL)
                return 0;
 
-       if (type == NULL)
+       if (!(ctx->pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM))
                {
-               int def_nid;
-               if (EVP_PKEY_get_default_digest_nid(pkey, &def_nid) > 0)
-                       type = EVP_get_digestbynid(def_nid);
-               }
 
-       if (type == NULL)
-               {
-               EVPerr(EVP_F_DO_SIGVER_INIT, EVP_R_NO_DEFAULT_DIGEST);
-               return 0;
+               if (type == NULL)
+                       {
+                       int def_nid;
+                       if (EVP_PKEY_get_default_digest_nid(pkey, &def_nid) > 0)
+                               type = EVP_get_digestbynid(def_nid);
+                       }
+
+               if (type == NULL)
+                       {
+                       EVPerr(EVP_F_DO_SIGVER_INIT, EVP_R_NO_DEFAULT_DIGEST);
+                       return 0;
+                       }
                }
 
        if (ver)
@@ -109,8 +113,8 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
                }
        if (EVP_PKEY_CTX_set_signature_md(ctx->pctx, type) <= 0)
                return 0;
-       if (pctx)
-               *pctx = ctx->pctx;
+       if (ctx->pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM)
+               return 1;
        if (!EVP_DigestInit_ex(ctx, type, e))
                return 0;
        return 1;
@@ -131,7 +135,20 @@ int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
 int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen)
        {
        int sctx, r = 0;
-       if (ctx->pctx->pmeth->signctx)
+       EVP_PKEY_CTX *pctx = ctx->pctx;
+       if (pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM)
+               {
+               EVP_PKEY_CTX *dctx;
+               if (!sigret)
+                       return pctx->pmeth->signctx(pctx, sigret, siglen, ctx);
+               dctx = EVP_PKEY_CTX_dup(ctx->pctx);
+               if (!dctx)
+                       return 0;
+               r = dctx->pmeth->signctx(dctx, sigret, siglen, ctx);
+               EVP_PKEY_CTX_free(dctx);
+               return r;
+               }
+       if (pctx->pmeth->signctx)
                sctx = 1;
        else
                sctx = 0;
@@ -158,13 +175,13 @@ int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen)
                {
                if (sctx)
                        {
-                       if (ctx->pctx->pmeth->signctx(ctx->pctx, sigret, siglen, ctx) <= 0)
+                       if (pctx->pmeth->signctx(pctx, sigret, siglen, ctx) <= 0)
                                return 0;
                        }
                else
                        {
                        int s = EVP_MD_size(ctx->digest);
-                       if (s < 0 || EVP_PKEY_sign(ctx->pctx, sigret, siglen, NULL, s) <= 0)
+                       if (s < 0 || EVP_PKEY_sign(pctx, sigret, siglen, NULL, s) <= 0)
                                return 0;
                        }
                }
index 4a05f0b1359d59c699f7c76bedae828d47220831..e4a08fb96d3295d10fb0026cf5c308aae58535f6 100644 (file)
@@ -73,7 +73,7 @@ DECLARE_STACK_OF(EVP_PKEY_METHOD)
 STACK_OF(EVP_PKEY_METHOD) *app_pkey_methods = NULL;
 
 extern const EVP_PKEY_METHOD rsa_pkey_meth, dh_pkey_meth, dsa_pkey_meth;
-extern const EVP_PKEY_METHOD ec_pkey_meth, hmac_pkey_meth;
+extern const EVP_PKEY_METHOD ec_pkey_meth, hmac_pkey_meth, cmac_pkey_meth;
 
 static const EVP_PKEY_METHOD *standard_methods[] =
        {
@@ -90,6 +90,7 @@ static const EVP_PKEY_METHOD *standard_methods[] =
        &ec_pkey_meth,
 #endif
        &hmac_pkey_meth,
+       &cmac_pkey_meth
        };
 
 DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_METHOD *, const EVP_PKEY_METHOD *,
index cbccf5afd6156908fb73725deed6898977a4de19..258ad8148954ba1fea2975b2d6c5bd2dd199eae8 100644 (file)
@@ -62,9 +62,9 @@
  * [including the GNU Public Licence.]
  */
 
-#define NUM_NID 894
-#define NUM_SN 887
-#define NUM_LN 887
+#define NUM_NID 895
+#define NUM_SN 888
+#define NUM_LN 888
 #define NUM_OBJ 841
 
 static const unsigned char lvalues[5835]={
@@ -2354,6 +2354,7 @@ static const ASN1_OBJECT nid_objs[NUM_NID]={
 {"dmdName","dmdName",NID_dmdName,3,&(lvalues[5820]),0},
 {"id-alg-PWRI-KEK","id-alg-PWRI-KEK",NID_id_alg_PWRI_KEK,11,
        &(lvalues[5823]),0},
+{"CMAC","cmac",NID_cmac,0,NULL,0},
 };
 
 static const unsigned int sn_objs[NUM_SN]={
@@ -2403,6 +2404,7 @@ static const unsigned int sn_objs[NUM_SN]={
 110,   /* "CAST5-CFB" */
 109,   /* "CAST5-ECB" */
 111,   /* "CAST5-OFB" */
+894,   /* "CMAC" */
 13,    /* "CN" */
 141,   /* "CRLReason" */
 417,   /* "CSPName" */
@@ -3471,6 +3473,7 @@ static const unsigned int ln_objs[NUM_LN]={
 407,   /* "characteristic-two-field" */
 395,   /* "clearance" */
 633,   /* "cleartext track 2" */
+894,   /* "cmac" */
 13,    /* "commonName" */
 513,   /* "content types" */
 50,    /* "contentType" */
index a4326633cdffccb13aff9ebe174e513e02dfe970..f6683405df3075eeb389d362ba96ae8225e0b2bc 100644 (file)
 #define LN_hmac                "hmac"
 #define NID_hmac               855
 
+#define SN_cmac                "CMAC"
+#define LN_cmac                "cmac"
+#define NID_cmac               894
+
index 65ca66fff2153b7a7977bd85343ec3a49d6e61ca..24f881688bfe0c0db5d447a27e61bdd4d3be2a18 100644 (file)
@@ -891,3 +891,4 @@ supportedAlgorithms         890
 deltaRevocationList            891
 dmdName                892
 id_alg_PWRI_KEK                893
+cmac           894
index 97be8779068a6a36c86aa41ae2321332ffce2ff6..848a6d9a39ce791366eaca8a2cad3df1d05283d9 100644 (file)
@@ -1258,3 +1258,5 @@ kisa 1 6                : SEED-OFB      : seed-ofb
 # There is no OID that just denotes "HMAC" oddly enough...
 
                        : HMAC                          : hmac
+# Nor CMAC either
+                       : CMAC                          : cmac