2002-04-17 08:55:06 +00:00
|
|
|
/*
|
|
|
|
* pkc15-algo.c: ASN.1 handling for algorithm IDs and parameters
|
|
|
|
*
|
2015-10-05 12:06:23 +00:00
|
|
|
* Copyright (C) 2001, 2002 Olaf Kirch <okir@suse.de>
|
2002-04-17 08:55:06 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2015-04-22 21:55:33 +00:00
|
|
|
#if HAVE_CONFIG_H
|
2010-03-04 08:14:36 +00:00
|
|
|
#include "config.h"
|
2015-04-22 21:55:33 +00:00
|
|
|
#endif
|
2010-03-04 08:14:36 +00:00
|
|
|
|
2002-04-17 08:55:06 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2010-03-04 08:14:36 +00:00
|
|
|
#include "internal.h"
|
|
|
|
#include "asn1.h"
|
|
|
|
|
2002-04-17 08:55:06 +00:00
|
|
|
/*
|
|
|
|
* AlgorithmIdentifier handling
|
|
|
|
*/
|
|
|
|
static struct sc_asn1_entry c_asn1_des_iv[] = {
|
2006-01-20 20:52:36 +00:00
|
|
|
{ "iv", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_OCTET_STRING, 0, NULL, NULL },
|
2005-08-05 07:24:43 +00:00
|
|
|
{ NULL, 0, 0, 0, NULL, NULL }
|
2002-04-17 08:55:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2005-03-08 20:59:35 +00:00
|
|
|
asn1_decode_des_params(sc_context_t *ctx, void **paramp,
|
2002-04-17 08:55:06 +00:00
|
|
|
const u8 *buf, size_t buflen, int depth)
|
|
|
|
{
|
|
|
|
struct sc_asn1_entry asn1_des_iv[2];
|
|
|
|
u8 iv[8];
|
|
|
|
int ivlen = 8, r;
|
|
|
|
|
|
|
|
sc_copy_asn1_entry(c_asn1_des_iv, asn1_des_iv);
|
|
|
|
sc_format_asn1_entry(asn1_des_iv + 0, iv, &ivlen, 0);
|
|
|
|
r = _sc_asn1_decode(ctx, asn1_des_iv, buf, buflen, NULL, NULL, 0, depth + 1);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
if (ivlen != 8)
|
|
|
|
return SC_ERROR_INVALID_ASN1_OBJECT;
|
|
|
|
*paramp = malloc(8);
|
2005-01-03 17:20:17 +00:00
|
|
|
if (!*paramp)
|
|
|
|
return SC_ERROR_OUT_OF_MEMORY;
|
2002-04-17 08:55:06 +00:00
|
|
|
memcpy(*paramp, iv, 8);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-03-08 20:59:35 +00:00
|
|
|
asn1_encode_des_params(sc_context_t *ctx, void *params,
|
2002-04-17 08:55:06 +00:00
|
|
|
u8 **buf, size_t *buflen, int depth)
|
|
|
|
{
|
|
|
|
struct sc_asn1_entry asn1_des_iv[2];
|
|
|
|
int ivlen = 8;
|
|
|
|
|
|
|
|
sc_copy_asn1_entry(c_asn1_des_iv, asn1_des_iv);
|
|
|
|
sc_format_asn1_entry(asn1_des_iv + 0, params, &ivlen, 1);
|
|
|
|
return _sc_asn1_encode(ctx, asn1_des_iv, buf, buflen, depth + 1);
|
|
|
|
}
|
|
|
|
|
2009-11-19 15:41:03 +00:00
|
|
|
static const struct sc_asn1_entry c_asn1_gostr3410_params0[] = {
|
|
|
|
{ "GOSTR3410Params", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
|
|
|
|
{ NULL, 0, 0, 0, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct sc_asn1_entry c_asn1_gostr3410_params[] = {
|
|
|
|
{ "key_params", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, 0, NULL, NULL },
|
|
|
|
{ "hash_params", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, 0, NULL, NULL },
|
|
|
|
{ "cipher_params", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_OPTIONAL, NULL, NULL },
|
|
|
|
{ NULL, 0, 0, 0, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
asn1_decode_gostr3410_params(sc_context_t *ctx, void **paramp,
|
|
|
|
const u8 *buf, size_t buflen, int depth)
|
|
|
|
{
|
|
|
|
struct sc_asn1_entry asn1_gostr3410_params0[2], asn1_gostr3410_params[4];
|
|
|
|
struct sc_object_id keyp, hashp, cipherp;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
sc_copy_asn1_entry(c_asn1_gostr3410_params0, asn1_gostr3410_params0);
|
|
|
|
sc_copy_asn1_entry(c_asn1_gostr3410_params, asn1_gostr3410_params);
|
|
|
|
|
|
|
|
sc_format_asn1_entry(asn1_gostr3410_params0 + 0, asn1_gostr3410_params, NULL, 0);
|
|
|
|
sc_format_asn1_entry(asn1_gostr3410_params + 0, &keyp, NULL, 0);
|
|
|
|
sc_format_asn1_entry(asn1_gostr3410_params + 1, &hashp, NULL, 0);
|
|
|
|
sc_format_asn1_entry(asn1_gostr3410_params + 2, &cipherp, NULL, 0);
|
|
|
|
|
|
|
|
r = _sc_asn1_decode(ctx, asn1_gostr3410_params0, buf, buflen, NULL, NULL, 0, depth + 1);
|
|
|
|
/* TODO: store in paramp */
|
|
|
|
(void)paramp; /* no warning */
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
asn1_encode_gostr3410_params(sc_context_t *ctx, void *params,
|
|
|
|
u8 **buf, size_t *buflen, int depth)
|
|
|
|
{
|
2011-05-29 18:18:43 +00:00
|
|
|
struct sc_asn1_entry asn1_gostr3410_params0[2], asn1_gostr3410_params[4];
|
|
|
|
struct sc_pkcs15_gost_parameters *gost_params = (struct sc_pkcs15_gost_parameters *)params;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
sc_copy_asn1_entry(c_asn1_gostr3410_params0, asn1_gostr3410_params0);
|
|
|
|
sc_copy_asn1_entry(c_asn1_gostr3410_params, asn1_gostr3410_params);
|
|
|
|
|
|
|
|
sc_format_asn1_entry(asn1_gostr3410_params0 + 0, asn1_gostr3410_params, NULL, 1);
|
|
|
|
sc_format_asn1_entry(asn1_gostr3410_params + 0, &gost_params->key, NULL, 1);
|
|
|
|
sc_format_asn1_entry(asn1_gostr3410_params + 1, &gost_params->hash, NULL, 1);
|
|
|
|
/* sc_format_asn1_entry(asn1_gostr3410_params + 2, &cipherp, NULL, 1); */
|
|
|
|
|
|
|
|
r = _sc_asn1_encode(ctx, asn1_gostr3410_params0, buf, buflen, depth + 1);
|
|
|
|
|
|
|
|
sc_log(ctx, "encoded-params: %s", sc_dump_hex(*buf, *buflen));
|
|
|
|
return r;
|
2009-11-19 15:41:03 +00:00
|
|
|
}
|
|
|
|
|
2002-04-17 08:55:06 +00:00
|
|
|
static const struct sc_asn1_entry c_asn1_pbkdf2_params[] = {
|
2006-01-20 20:52:36 +00:00
|
|
|
{ "salt", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_OCTET_STRING, 0, NULL, NULL },
|
|
|
|
{ "count", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, 0, NULL, NULL },
|
|
|
|
{ "keyLength", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
|
|
|
|
{ "prf", SC_ASN1_ALGORITHM_ID, SC_ASN1_TAG_SEQUENCE, SC_ASN1_OPTIONAL, NULL, NULL },
|
2005-08-05 07:24:43 +00:00
|
|
|
{ NULL, 0, 0, 0, NULL, NULL }
|
2002-04-17 08:55:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2005-03-08 20:59:35 +00:00
|
|
|
asn1_decode_pbkdf2_params(sc_context_t *ctx, void **paramp,
|
2002-04-17 08:55:06 +00:00
|
|
|
const u8 *buf, size_t buflen, int depth)
|
|
|
|
{
|
|
|
|
struct sc_pbkdf2_params info;
|
|
|
|
struct sc_asn1_entry asn1_pbkdf2_params[5];
|
|
|
|
int r;
|
|
|
|
|
|
|
|
sc_copy_asn1_entry(c_asn1_pbkdf2_params, asn1_pbkdf2_params);
|
|
|
|
sc_format_asn1_entry(asn1_pbkdf2_params + 0,
|
|
|
|
info.salt, &info.salt_len, 0);
|
|
|
|
sc_format_asn1_entry(asn1_pbkdf2_params + 1,
|
|
|
|
&info.iterations, NULL, 0);
|
|
|
|
sc_format_asn1_entry(asn1_pbkdf2_params + 2,
|
|
|
|
&info.key_length, NULL, 0);
|
|
|
|
sc_format_asn1_entry(asn1_pbkdf2_params + 3,
|
|
|
|
&info.hash_alg, NULL, 0);
|
|
|
|
|
|
|
|
memset(&info, 0, sizeof(info));
|
|
|
|
info.salt_len = sizeof(info.salt);
|
|
|
|
info.hash_alg.algorithm = SC_ALGORITHM_SHA1;
|
|
|
|
|
|
|
|
r = _sc_asn1_decode(ctx, asn1_pbkdf2_params, buf, buflen, NULL, NULL, 0, depth + 1);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
*paramp = malloc(sizeof(info));
|
2005-12-05 21:49:59 +00:00
|
|
|
if (!*paramp)
|
2005-01-03 17:20:17 +00:00
|
|
|
return SC_ERROR_OUT_OF_MEMORY;
|
2002-04-17 08:55:06 +00:00
|
|
|
memcpy(*paramp, &info, sizeof(info));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-03-08 20:59:35 +00:00
|
|
|
asn1_encode_pbkdf2_params(sc_context_t *ctx, void *params,
|
2002-04-17 08:55:06 +00:00
|
|
|
u8 **buf, size_t *buflen, int depth)
|
|
|
|
{
|
|
|
|
struct sc_pbkdf2_params *info;
|
|
|
|
struct sc_asn1_entry asn1_pbkdf2_params[5];
|
|
|
|
|
|
|
|
info = (struct sc_pbkdf2_params *) params;
|
|
|
|
|
|
|
|
sc_copy_asn1_entry(c_asn1_pbkdf2_params, asn1_pbkdf2_params);
|
|
|
|
sc_format_asn1_entry(asn1_pbkdf2_params + 0,
|
|
|
|
info->salt, &info->salt_len, 1);
|
|
|
|
sc_format_asn1_entry(asn1_pbkdf2_params + 1,
|
|
|
|
&info->iterations, NULL, 1);
|
|
|
|
if (info->key_length > 0)
|
|
|
|
sc_format_asn1_entry(asn1_pbkdf2_params + 2,
|
|
|
|
&info->key_length, NULL, 1);
|
|
|
|
if (info->hash_alg.algorithm != SC_ALGORITHM_SHA1)
|
|
|
|
sc_format_asn1_entry(asn1_pbkdf2_params + 3,
|
|
|
|
&info->hash_alg, NULL, 0);
|
|
|
|
|
|
|
|
return _sc_asn1_encode(ctx, asn1_pbkdf2_params, buf, buflen, depth + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct sc_asn1_entry c_asn1_pbes2_params[] = {
|
2006-01-20 20:52:36 +00:00
|
|
|
{ "keyDerivationAlg", SC_ASN1_ALGORITHM_ID, SC_ASN1_TAG_SEQUENCE, 0, NULL, NULL },
|
|
|
|
{ "keyEcnryptionAlg", SC_ASN1_ALGORITHM_ID, SC_ASN1_TAG_SEQUENCE, 0, NULL, NULL },
|
2005-08-05 07:24:43 +00:00
|
|
|
{ NULL, 0, 0, 0, NULL, NULL }
|
2002-04-17 08:55:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2005-03-08 20:59:35 +00:00
|
|
|
asn1_decode_pbes2_params(sc_context_t *ctx, void **paramp,
|
2002-04-17 08:55:06 +00:00
|
|
|
const u8 *buf, size_t buflen, int depth)
|
|
|
|
{
|
|
|
|
struct sc_asn1_entry asn1_pbes2_params[3];
|
|
|
|
struct sc_pbes2_params info;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
sc_copy_asn1_entry(c_asn1_pbes2_params, asn1_pbes2_params);
|
|
|
|
sc_format_asn1_entry(asn1_pbes2_params + 0,
|
|
|
|
&info.derivation_alg, NULL, 0);
|
|
|
|
sc_format_asn1_entry(asn1_pbes2_params + 1,
|
|
|
|
&info.key_encr_alg, NULL, 0);
|
|
|
|
memset(&info, 0, sizeof(info));
|
|
|
|
|
|
|
|
r = _sc_asn1_decode(ctx, asn1_pbes2_params, buf, buflen, NULL, NULL, 0, depth + 1);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
*paramp = malloc(sizeof(info));
|
2005-01-03 17:20:17 +00:00
|
|
|
if (!*paramp)
|
|
|
|
return SC_ERROR_OUT_OF_MEMORY;
|
2002-04-17 08:55:06 +00:00
|
|
|
memcpy(*paramp, &info, sizeof(info));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-03-08 20:59:35 +00:00
|
|
|
asn1_encode_pbes2_params(sc_context_t *ctx, void *params,
|
2002-04-17 08:55:06 +00:00
|
|
|
u8 **buf, size_t *buflen, int depth)
|
|
|
|
{
|
|
|
|
struct sc_asn1_entry asn1_pbes2_params[3];
|
|
|
|
struct sc_pbes2_params *info;
|
|
|
|
|
|
|
|
info = (struct sc_pbes2_params *) params;
|
|
|
|
sc_copy_asn1_entry(c_asn1_pbes2_params, asn1_pbes2_params);
|
|
|
|
sc_format_asn1_entry(asn1_pbes2_params + 0,
|
|
|
|
&info->derivation_alg, NULL, 0);
|
|
|
|
sc_format_asn1_entry(asn1_pbes2_params + 1,
|
|
|
|
&info->key_encr_alg, NULL, 0);
|
|
|
|
return _sc_asn1_encode(ctx, asn1_pbes2_params, buf, buflen, depth + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
asn1_free_pbes2_params(void *ptr)
|
|
|
|
{
|
|
|
|
struct sc_pbes2_params *params = (struct sc_pbes2_params *) ptr;
|
|
|
|
|
|
|
|
sc_asn1_clear_algorithm_id(¶ms->derivation_alg);
|
|
|
|
sc_asn1_clear_algorithm_id(¶ms->key_encr_alg);
|
|
|
|
free(params);
|
|
|
|
}
|
|
|
|
|
2015-02-14 16:47:59 +00:00
|
|
|
static const struct sc_asn1_entry c_asn1_ec_params[] = {
|
|
|
|
{ "ecParameters", SC_ASN1_STRUCT, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
|
2010-12-01 20:08:42 +00:00
|
|
|
{ "namedCurve", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, 0, NULL, NULL},
|
|
|
|
{ "implicityCA", SC_ASN1_NULL, SC_ASN1_TAG_NULL, 0, NULL, NULL },
|
|
|
|
{ NULL, 0, 0, 0, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
asn1_decode_ec_params(sc_context_t *ctx, void **paramp,
|
|
|
|
const u8 *buf, size_t buflen, int depth)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
struct sc_object_id curve;
|
|
|
|
struct sc_asn1_entry asn1_ec_params[4];
|
2015-02-14 16:47:59 +00:00
|
|
|
struct sc_ec_parameters *ecp;
|
2010-12-01 20:08:42 +00:00
|
|
|
|
|
|
|
memset(&curve, 0, sizeof(curve));
|
|
|
|
|
2015-02-14 16:47:59 +00:00
|
|
|
/* We only want to copy the parms if they are a namedCurve
|
|
|
|
* or ecParameters nullParam aka implicityCA is not to be
|
2010-12-01 20:08:42 +00:00
|
|
|
* used with PKCS#11 2.20 */
|
|
|
|
sc_copy_asn1_entry(c_asn1_ec_params, asn1_ec_params);
|
|
|
|
sc_format_asn1_entry(asn1_ec_params + 1, &curve, 0, 0);
|
|
|
|
|
|
|
|
/* Some signature algorithms will not have any data */
|
2015-02-14 16:47:59 +00:00
|
|
|
if (buflen == 0 || buf == NULL)
|
2010-12-01 20:08:42 +00:00
|
|
|
return 0;
|
2015-02-14 16:47:59 +00:00
|
|
|
|
2010-12-01 20:08:42 +00:00
|
|
|
r = sc_asn1_decode_choice(ctx, asn1_ec_params, buf, buflen, NULL, NULL);
|
2015-02-14 16:47:59 +00:00
|
|
|
/* r = index in asn1_ec_params */
|
|
|
|
sc_debug(ctx, SC_LOG_DEBUG_ASN1, "asn1_decode_ec_params r=%d", r);
|
|
|
|
if (r < 0)
|
2010-12-01 20:08:42 +00:00
|
|
|
return r;
|
|
|
|
|
2015-04-29 21:22:27 +00:00
|
|
|
ecp = calloc(sizeof(struct sc_ec_parameters), 1);
|
|
|
|
if (ecp == NULL)
|
|
|
|
return SC_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2015-02-14 16:47:59 +00:00
|
|
|
if (r <= 1) {
|
|
|
|
ecp->der.value = malloc(buflen);
|
2015-04-29 21:22:27 +00:00
|
|
|
if (ecp->der.value == NULL) {
|
|
|
|
free(ecp);
|
2010-12-01 20:08:42 +00:00
|
|
|
return SC_ERROR_OUT_OF_MEMORY;
|
2015-04-29 21:22:27 +00:00
|
|
|
}
|
2015-02-14 16:47:59 +00:00
|
|
|
ecp->der.len = buflen;
|
|
|
|
memcpy(ecp->der.value, buf, buflen);
|
|
|
|
}
|
|
|
|
else {
|
2010-12-01 20:08:42 +00:00
|
|
|
r = 0;
|
2015-02-14 16:47:59 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 20:08:42 +00:00
|
|
|
ecp->type = r; /* but 0 = ecparams if any, 1=named curve */
|
|
|
|
*paramp = ecp;
|
2015-04-29 21:22:27 +00:00
|
|
|
return SC_SUCCESS;
|
2010-12-01 20:08:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
asn1_encode_ec_params(sc_context_t *ctx, void *params,
|
2015-02-14 16:47:59 +00:00
|
|
|
u8 **buf, size_t *buflen, int depth)
|
2010-12-01 20:08:42 +00:00
|
|
|
{
|
2015-02-14 16:47:59 +00:00
|
|
|
struct sc_ec_parameters *ecp = (struct sc_ec_parameters *) params;
|
2013-11-15 10:38:51 +00:00
|
|
|
|
|
|
|
/* Only handle named curves. They may be absent too */
|
2015-02-14 16:47:59 +00:00
|
|
|
sc_debug(ctx, SC_LOG_DEBUG_ASN1, "asn1_encode_ec_params() called");
|
2013-11-15 10:38:51 +00:00
|
|
|
*buf = NULL;
|
|
|
|
*buflen = 0;
|
2015-02-14 16:47:59 +00:00
|
|
|
if (ecp && ecp->type == 1 && ecp->der.value) { /* named curve */
|
|
|
|
*buf = malloc(ecp->der.len);
|
2013-11-15 10:38:51 +00:00
|
|
|
if (*buf == NULL)
|
|
|
|
return SC_ERROR_OUT_OF_MEMORY;
|
2010-12-01 20:08:42 +00:00
|
|
|
|
2015-02-14 16:47:59 +00:00
|
|
|
memcpy(*buf, ecp->der.value, ecp->der.len);
|
|
|
|
*buflen = ecp->der.len;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sc_debug(ctx, SC_LOG_DEBUG_ASN1, "Not named curve");
|
|
|
|
}
|
2013-11-15 10:38:51 +00:00
|
|
|
|
|
|
|
return 0;
|
2010-12-01 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
asn1_free_ec_params(void *params)
|
|
|
|
{
|
2015-02-14 16:47:59 +00:00
|
|
|
struct sc_ec_parameters *ecp = (struct sc_ec_parameters *) params;
|
|
|
|
|
2010-12-01 20:08:42 +00:00
|
|
|
if (ecp) {
|
2015-02-14 16:47:59 +00:00
|
|
|
if (ecp->der.value)
|
|
|
|
free(ecp->der.value);
|
|
|
|
if (ecp->named_curve)
|
|
|
|
free(ecp->named_curve);
|
2010-12-01 20:08:42 +00:00
|
|
|
free(ecp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-17 08:55:06 +00:00
|
|
|
static struct sc_asn1_pkcs15_algorithm_info algorithm_table[] = {
|
|
|
|
#ifdef SC_ALGORITHM_SHA1
|
|
|
|
/* hmacWithSHA1 */
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_SHA1, {{ 1, 2, 840, 113549, 2, 7, -1}}, NULL, NULL, NULL },
|
|
|
|
{ SC_ALGORITHM_SHA1, {{ 1, 3, 6, 1, 5, 5, 8, 1, 2, -1}}, NULL, NULL, NULL },
|
2002-04-17 08:55:06 +00:00
|
|
|
/* SHA1 */
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_SHA1, {{ 1, 3, 14, 3, 2, 26, -1}}, NULL, NULL, NULL },
|
2002-04-17 08:55:06 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SC_ALGORITHM_MD5
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_MD5, {{ 1, 2, 840, 113549, 2, 5, -1}}, NULL, NULL, NULL },
|
2002-04-17 08:55:06 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SC_ALGORITHM_DSA
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_DSA, {{ 1, 2, 840, 10040, 4, 3, -1}}, NULL, NULL, NULL },
|
2002-04-17 08:55:06 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SC_ALGORITHM_RSA /* really rsaEncryption */
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_RSA, {{ 1, 2, 840, 113549, 1, 1, 1, -1}}, NULL, NULL, NULL },
|
2002-04-17 08:55:06 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SC_ALGORITHM_DH
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_DH, {{ 1, 2, 840, 10046, 2, 1, -1}}, NULL, NULL, NULL },
|
2002-04-17 08:55:06 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SC_ALGORITHM_RC2_WRAP /* from CMS */
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_RC2_WRAP, {{ 1, 2, 840, 113549, 1, 9, 16, 3, 7, -1}}, NULL, NULL, NULL },
|
2002-04-17 08:55:06 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SC_ALGORITHM_RC2 /* CBC mode */
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_RC2, {{ 1, 2, 840, 113549, 3, 2, -1}},
|
2002-04-17 08:55:06 +00:00
|
|
|
asn1_decode_rc2_params,
|
|
|
|
asn1_encode_rc2_params },
|
|
|
|
#endif
|
|
|
|
#ifdef SC_ALGORITHM_DES /* CBC mode */
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_DES, {{ 1, 3, 14, 3, 2, 7, -1}},
|
2002-04-17 08:55:06 +00:00
|
|
|
asn1_decode_des_params,
|
|
|
|
asn1_encode_des_params,
|
|
|
|
free },
|
|
|
|
#endif
|
|
|
|
#ifdef SC_ALGORITHM_3DES_WRAP /* from CMS */
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_3DES_WRAP, {{ 1, 2, 840, 113549, 1, 9, 16, 3, 6, -1}}, NULL, NULL, NULL },
|
2002-04-17 08:55:06 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SC_ALGORITHM_3DES /* EDE CBC mode */
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_3DES, {{ 1, 2, 840, 113549, 3, 7, -1}},
|
2002-04-17 08:55:06 +00:00
|
|
|
asn1_decode_des_params,
|
|
|
|
asn1_encode_des_params,
|
|
|
|
free },
|
|
|
|
#endif
|
2007-12-17 13:39:20 +00:00
|
|
|
#ifdef SC_ALGORITHM_GOST /* EDE CBC mode */
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_GOST, {{ 1, 2, 4434, 66565, 3, 7, -1}}, NULL, NULL, NULL },
|
2007-12-17 13:39:20 +00:00
|
|
|
#endif
|
2009-10-05 20:10:07 +00:00
|
|
|
#ifdef SC_ALGORITHM_GOSTR3410
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_GOSTR3410, {{ 1, 2, 643, 2, 2, 19, -1}},
|
2009-11-19 15:41:03 +00:00
|
|
|
asn1_decode_gostr3410_params,
|
|
|
|
asn1_encode_gostr3410_params,
|
|
|
|
NULL },
|
2009-10-05 20:10:07 +00:00
|
|
|
#endif
|
2002-04-17 08:55:06 +00:00
|
|
|
/* We do not support PBES1 because the encryption is weak */
|
|
|
|
#ifdef SC_ALGORITHM_PBKDF2
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_PBKDF2, {{ 1, 2, 840, 113549, 1, 5, 12, -1}},
|
2002-04-17 08:55:06 +00:00
|
|
|
asn1_decode_pbkdf2_params,
|
|
|
|
asn1_encode_pbkdf2_params,
|
|
|
|
free },
|
|
|
|
#endif
|
|
|
|
#ifdef SC_ALGORITHM_PBES2
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_PBES2, {{ 1, 2, 840, 113549, 1, 5, 13, -1}},
|
2002-04-17 08:55:06 +00:00
|
|
|
asn1_decode_pbes2_params,
|
|
|
|
asn1_encode_pbes2_params,
|
|
|
|
asn1_free_pbes2_params },
|
|
|
|
#endif
|
2010-12-01 20:08:42 +00:00
|
|
|
|
|
|
|
#ifdef SC_ALGORITHM_EC
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_EC, {{ 1, 2, 840, 10045, 2, 1, -1}},
|
|
|
|
asn1_decode_ec_params,
|
|
|
|
asn1_encode_ec_params,
|
|
|
|
asn1_free_ec_params },
|
2010-12-01 20:08:42 +00:00
|
|
|
#endif
|
2016-05-12 11:15:31 +00:00
|
|
|
/* TODO: -DEE Not clear if we need the next five or not */
|
2010-12-01 20:08:42 +00:00
|
|
|
#ifdef SC_ALGORITHM_ECDSA_SHA1
|
|
|
|
/* Note RFC 3279 says no ecParameters */
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_ECDSA_SHA1, {{ 1, 2, 840, 10045, 4, 1, -1}}, NULL, NULL, NULL},
|
2010-12-01 20:08:42 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SC_ALGORITHM_ECDSA_SHA224
|
|
|
|
/* These next 4 are defined in RFC 5758 */
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_ECDSA_SHA224, {{ 1, 2, 840, 10045, 4, 3, 1, -1}},
|
|
|
|
asn1_decode_ec_params,
|
|
|
|
asn1_encode_ec_params,
|
|
|
|
asn1_free_ec_params },
|
2010-12-01 20:08:42 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SC_ALGORITHM_ECDSA_SHA256
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_ECDSA_SHA256, {{ 1, 2, 840, 10045, 4, 3, 2, -1}},
|
|
|
|
asn1_decode_ec_params,
|
|
|
|
asn1_encode_ec_params,
|
|
|
|
asn1_free_ec_params },
|
2010-12-01 20:08:42 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SC_ALGORITHM_ECDSA_SHA384
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_ECDSA_SHA384, {{ 1, 2, 840, 10045, 4, 3, 3, -1}},
|
|
|
|
asn1_decode_ec_params,
|
|
|
|
asn1_encode_ec_params,
|
|
|
|
asn1_free_ec_params },
|
2010-12-01 20:08:42 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SC_ALGORITHM_ECDSA_SHA512
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
{ SC_ALGORITHM_ECDSA_SHA512, {{ 1, 2, 840, 10045, 4, 3, 4, -1}},
|
|
|
|
asn1_decode_ec_params,
|
|
|
|
asn1_encode_ec_params,
|
|
|
|
asn1_free_ec_params },
|
2010-12-01 20:08:42 +00:00
|
|
|
#endif
|
2010-10-04 15:58:34 +00:00
|
|
|
{ -1, {{ -1 }}, NULL, NULL, NULL }
|
2002-04-17 08:55:06 +00:00
|
|
|
};
|
|
|
|
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
|
2002-04-17 08:55:06 +00:00
|
|
|
static struct sc_asn1_pkcs15_algorithm_info *
|
|
|
|
sc_asn1_get_algorithm_info(const struct sc_algorithm_id *id)
|
|
|
|
{
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
struct sc_asn1_pkcs15_algorithm_info *aip = NULL;
|
2002-04-17 08:55:06 +00:00
|
|
|
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
for (aip = algorithm_table; aip->id >= 0; aip++) {
|
|
|
|
if ((int) id->algorithm < 0 && sc_compare_oid(&id->oid, &aip->oid))
|
|
|
|
return aip;
|
|
|
|
|
|
|
|
if (aip->id == (int)id->algorithm)
|
|
|
|
return aip;
|
2002-04-17 08:55:06 +00:00
|
|
|
}
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
|
2002-04-17 08:55:06 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-02-02 15:39:18 +00:00
|
|
|
static const struct sc_asn1_entry c_asn1_alg_id[3] = {
|
2006-01-20 20:52:36 +00:00
|
|
|
{ "algorithm", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, 0, NULL, NULL },
|
|
|
|
{ "nullParam", SC_ASN1_NULL, SC_ASN1_TAG_NULL, SC_ASN1_OPTIONAL, NULL, NULL },
|
2005-08-05 07:24:43 +00:00
|
|
|
{ NULL, 0, 0, 0, NULL, NULL }
|
2002-04-17 08:55:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int
|
2015-02-02 15:39:18 +00:00
|
|
|
sc_asn1_decode_algorithm_id(struct sc_context *ctx, const unsigned char *in,
|
2002-04-17 08:55:06 +00:00
|
|
|
size_t len, struct sc_algorithm_id *id,
|
|
|
|
int depth)
|
|
|
|
{
|
2015-02-02 15:39:18 +00:00
|
|
|
struct sc_asn1_pkcs15_algorithm_info *alg_info = NULL;
|
2002-04-17 10:33:26 +00:00
|
|
|
struct sc_asn1_entry asn1_alg_id[3];
|
2002-04-17 08:55:06 +00:00
|
|
|
int r;
|
|
|
|
|
2015-02-02 15:39:18 +00:00
|
|
|
LOG_FUNC_CALLED(ctx);
|
2002-04-17 08:55:06 +00:00
|
|
|
sc_copy_asn1_entry(c_asn1_alg_id, asn1_alg_id);
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
sc_format_asn1_entry(asn1_alg_id + 0, &id->oid, NULL, 0);
|
2002-04-17 08:55:06 +00:00
|
|
|
|
|
|
|
memset(id, 0, sizeof(*id));
|
|
|
|
r = _sc_asn1_decode(ctx, asn1_alg_id, in, len, &in, &len, 0, depth + 1);
|
2015-02-02 15:39:18 +00:00
|
|
|
LOG_TEST_RET(ctx, r, "ASN.1 parsing of algo ID failed");
|
|
|
|
|
|
|
|
sc_log(ctx, "decoded OID '%s'", sc_dump_oid(&(id->oid)));
|
2002-04-17 08:55:06 +00:00
|
|
|
|
|
|
|
/* See if we understand the algorithm, and if we do, check
|
|
|
|
* whether we know how to decode any additional parameters */
|
2002-04-19 14:23:31 +00:00
|
|
|
id->algorithm = (unsigned int ) -1;
|
2015-02-02 15:39:18 +00:00
|
|
|
alg_info = sc_asn1_get_algorithm_info(id);
|
|
|
|
if (alg_info != NULL) {
|
2002-04-17 08:55:06 +00:00
|
|
|
id->algorithm = alg_info->id;
|
2002-04-17 10:33:26 +00:00
|
|
|
if (alg_info->decode) {
|
2010-12-01 20:08:42 +00:00
|
|
|
if (asn1_alg_id[1].flags & SC_ASN1_PRESENT) {
|
2015-02-02 15:39:18 +00:00
|
|
|
sc_log(ctx, "SC_ASN1_PRESENT was set, so invalid");
|
|
|
|
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ASN1_OBJECT);
|
2010-12-01 20:08:42 +00:00
|
|
|
}
|
2002-04-17 08:55:06 +00:00
|
|
|
r = alg_info->decode(ctx, &id->params, in, len, depth);
|
2002-04-17 10:33:26 +00:00
|
|
|
}
|
2002-04-17 08:55:06 +00:00
|
|
|
}
|
|
|
|
|
2015-02-02 15:39:18 +00:00
|
|
|
LOG_FUNC_RETURN(ctx, r);
|
2002-04-17 08:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-02-02 15:39:18 +00:00
|
|
|
sc_asn1_encode_algorithm_id(struct sc_context *ctx, u8 **buf, size_t *len,
|
2002-04-17 08:55:06 +00:00
|
|
|
const struct sc_algorithm_id *id,
|
|
|
|
int depth)
|
|
|
|
{
|
|
|
|
struct sc_asn1_pkcs15_algorithm_info *alg_info;
|
|
|
|
struct sc_algorithm_id temp_id;
|
2003-10-06 14:22:03 +00:00
|
|
|
struct sc_asn1_entry asn1_alg_id[3];
|
2004-04-21 18:10:58 +00:00
|
|
|
u8 *obj = NULL;
|
2002-04-17 12:19:43 +00:00
|
|
|
size_t obj_len = 0;
|
2002-04-17 08:55:06 +00:00
|
|
|
int r;
|
2004-04-21 18:10:58 +00:00
|
|
|
u8 *tmp;
|
2002-04-17 08:55:06 +00:00
|
|
|
|
2015-02-02 15:39:18 +00:00
|
|
|
LOG_FUNC_CALLED(ctx);
|
|
|
|
sc_log(ctx, "type of algorithm to encode: %i", id->algorithm);
|
2002-04-17 08:55:06 +00:00
|
|
|
alg_info = sc_asn1_get_algorithm_info(id);
|
2005-12-05 21:49:59 +00:00
|
|
|
if (alg_info == NULL) {
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
sc_log(ctx, "Cannot encode unknown algorithm %u", id->algorithm);
|
2015-02-02 15:39:18 +00:00
|
|
|
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
|
2005-12-05 21:49:59 +00:00
|
|
|
}
|
2002-04-17 08:55:06 +00:00
|
|
|
|
|
|
|
/* Set the oid if not yet given */
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
if (!sc_valid_oid(&id->oid)) {
|
2002-04-17 08:55:06 +00:00
|
|
|
temp_id = *id;
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
temp_id.oid = alg_info->oid;
|
2002-04-17 08:55:06 +00:00
|
|
|
id = &temp_id;
|
|
|
|
}
|
|
|
|
|
2015-02-02 15:39:18 +00:00
|
|
|
sc_log(ctx, "encode algo %s", sc_dump_oid(&(id->oid)));
|
2002-04-17 08:55:06 +00:00
|
|
|
sc_copy_asn1_entry(c_asn1_alg_id, asn1_alg_id);
|
libopensc: 'init', 'format', 'compare', 'is-valid' OID procedures
In a reason of number of bugs(*) that concern the OID management,
the general usage OID procedures 'init', 'format', 'compare', 'is-valid' are introduced.
These procedures should be used by all actors: libopensc, pkcs15, pkcs11, tools, ....
(*)
This bug reported by Andreas Schwier :
https://github.com/OpenSC/OpenSC/commit/8e75d971cb7eadfef9b5b50adb3cb6d18e641ed2#commitcomment-1792477
In pkcs15-algo sc_asn1_get_algorithm_info() can return the OID without ending '-1's:
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L452
https://github.com/OpenSC/OpenSC/blob/staging/src/libopensc/pkcs15-algo.c#L459
2012-09-01 22:12:57 +00:00
|
|
|
sc_format_asn1_entry(asn1_alg_id + 0, (void *) &id->oid, NULL, 1);
|
2002-04-17 08:55:06 +00:00
|
|
|
|
2002-04-17 10:33:26 +00:00
|
|
|
/* no parameters, write NULL tag */
|
|
|
|
if (!id->params || !alg_info->encode)
|
|
|
|
asn1_alg_id[1].flags |= SC_ASN1_PRESENT;
|
|
|
|
|
2002-04-17 08:55:06 +00:00
|
|
|
r = _sc_asn1_encode(ctx, asn1_alg_id, buf, len, depth + 1);
|
2015-02-02 15:39:18 +00:00
|
|
|
LOG_TEST_RET(ctx, r, "ASN.1 encode of algorithm failed");
|
2002-04-17 08:55:06 +00:00
|
|
|
|
|
|
|
/* Encode any parameters */
|
|
|
|
if (id->params && alg_info->encode) {
|
|
|
|
r = alg_info->encode(ctx, id->params, &obj, &obj_len, depth+1);
|
2004-04-21 18:10:58 +00:00
|
|
|
if (r < 0) {
|
|
|
|
if (obj)
|
|
|
|
free(obj);
|
2015-02-02 15:39:18 +00:00
|
|
|
LOG_FUNC_RETURN(ctx, r);
|
2004-04-21 18:10:58 +00:00
|
|
|
}
|
2002-04-17 08:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (obj_len) {
|
2004-04-21 18:10:58 +00:00
|
|
|
tmp = (u8 *) realloc(*buf, *len + obj_len);
|
|
|
|
if (!tmp) {
|
|
|
|
free(*buf);
|
|
|
|
*buf = NULL;
|
|
|
|
free(obj);
|
2015-02-02 15:39:18 +00:00
|
|
|
LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
|
2004-04-21 18:10:58 +00:00
|
|
|
}
|
|
|
|
*buf = tmp;
|
2002-04-17 08:55:06 +00:00
|
|
|
memcpy(*buf + *len, obj, obj_len);
|
|
|
|
*len += obj_len;
|
|
|
|
free(obj);
|
|
|
|
}
|
|
|
|
|
2011-05-29 18:18:43 +00:00
|
|
|
sc_log(ctx, "return encoded algorithm ID: %s", sc_dump_hex(*buf, *len));
|
2015-02-02 15:39:18 +00:00
|
|
|
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
2002-04-17 08:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sc_asn1_clear_algorithm_id(struct sc_algorithm_id *id)
|
|
|
|
{
|
|
|
|
struct sc_asn1_pkcs15_algorithm_info *aip;
|
|
|
|
|
2010-10-04 15:58:34 +00:00
|
|
|
if (id->params && (aip = sc_asn1_get_algorithm_info(id)) && aip->free) {
|
|
|
|
aip->free(id->params);
|
|
|
|
id->params = NULL;
|
|
|
|
}
|
2002-04-17 08:55:06 +00:00
|
|
|
}
|