From f9fa90899a4691ce01244593e2902111fe9bf2c6 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Wed, 18 Aug 2010 05:51:32 +0200 Subject: Replace ncr_derive_t by NLA_NUL_STRING --- examples/pk.c | 6 +++--- ncr-pk.c | 39 ++++++++++++++++++--------------------- ncr.h | 6 ++---- utils.c | 2 +- 4 files changed, 24 insertions(+), 29 deletions(-) diff --git a/examples/pk.c b/examples/pk.c index 25032755504..599f396cf9a 100644 --- a/examples/pk.c +++ b/examples/pk.c @@ -339,7 +339,7 @@ struct ncr_key_export kexport; struct __attribute__((packed)) { struct ncr_key_derive f; struct nlattr algo_head ALIGN_NL; - uint32_t algo ALIGN_NL; + char algo[sizeof(NCR_DERIVE_DH)] ALIGN_NL; struct nlattr flags_head ALIGN_NL; uint32_t flags ALIGN_NL; struct nlattr public_head ALIGN_NL; @@ -496,7 +496,7 @@ struct __attribute__((packed)) { kderive.f.new_key = z1; kderive.algo_head.nla_len = NLA_HDRLEN + sizeof(kderive.algo); kderive.algo_head.nla_type = NCR_ATTR_DERIVATION_ALGORITHM; - kderive.algo = NCR_DERIVE_DH; + strcpy(kderive.algo, NCR_DERIVE_DH); kderive.flags_head.nla_len = NLA_HDRLEN + sizeof(kderive.flags); kderive.flags_head.nla_type = NCR_ATTR_KEY_FLAGS; kderive.flags = NCR_KEY_FLAG_EXPORTABLE; @@ -527,7 +527,7 @@ struct __attribute__((packed)) { kderive.f.new_key = z2; kderive.algo_head.nla_len = NLA_HDRLEN + sizeof(kderive.algo); kderive.algo_head.nla_type = NCR_ATTR_DERIVATION_ALGORITHM; - kderive.algo = NCR_DERIVE_DH; + strcpy(kderive.algo, NCR_DERIVE_DH); kderive.flags_head.nla_len = NLA_HDRLEN + sizeof(kderive.flags); kderive.flags_head.nla_type = NCR_ATTR_KEY_FLAGS; kderive.flags = NCR_KEY_FLAG_EXPORTABLE; diff --git a/ncr-pk.c b/ncr-pk.c index ecac4c777b2..c6055dba1d5 100644 --- a/ncr-pk.c +++ b/ncr-pk.c @@ -632,30 +632,27 @@ int ret; err(); return -EINVAL; } - switch(nla_get_u32(nla)) { - case NCR_DERIVE_DH: - if (oldkey->type != NCR_KEY_TYPE_PRIVATE && - oldkey->algorithm->algo != NCR_ALG_DH) { - err(); - return -EINVAL; - } + if (nla_strcmp(nla, NCR_DERIVE_DH) == 0) { + if (oldkey->type != NCR_KEY_TYPE_PRIVATE && + oldkey->algorithm->algo != NCR_ALG_DH) { + err(); + return -EINVAL; + } - nla = tb[NCR_ATTR_DH_PUBLIC]; - if (nla == NULL) { - err(); - return -EINVAL; - } - ret = dh_derive_gxy(newkey, &oldkey->key.pk.dh, - nla_data(nla), nla_len(nla)); - if (ret < 0) { - err(); - return ret; - } - - break; - default: + nla = tb[NCR_ATTR_DH_PUBLIC]; + if (nla == NULL) { err(); return -EINVAL; + } + ret = dh_derive_gxy(newkey, &oldkey->key.pk.dh, nla_data(nla), + nla_len(nla)); + if (ret < 0) { + err(); + return ret; + } + } else { + err(); + return -EINVAL; } return 0; diff --git a/ncr.h b/ncr.h index 3dae3f38eb8..7f8fba40740 100644 --- a/ncr.h +++ b/ncr.h @@ -31,7 +31,7 @@ enum { NCR_ATTR_UNSPEC, /* 0 is special in lib/nlattr.c. */ NCR_ATTR_ALGORITHM, /* NLA_NUL_STRING */ - NCR_ATTR_DERIVATION_ALGORITHM, /* NLA_U32 - ncr_algorithm_t */ + NCR_ATTR_DERIVATION_ALGORITHM, /* NLA_NUL_STRING - NCR_DERIVE_* */ NCR_ATTR_SIGNATURE_HASH_ALGORITHM, /* NLA_NUL_STRING */ NCR_ATTR_WRAPPING_ALGORITHM, /* NLA_U32 - ncr_wrap_algorithm_t */ NCR_ATTR_UPDATE_INPUT_DATA, /* NLA_BINARY - ncr_session_input_data */ @@ -120,9 +120,7 @@ typedef enum { RSA_PKCS1_PSS, /* for signatures only */ } ncr_rsa_type_t; -typedef enum { - NCR_DERIVE_DH=1, -} ncr_derive_t; +#define NCR_DERIVE_DH "dh" struct ncr_key_derive { diff --git a/utils.c b/utils.c index 23d75f126d5..113a1ee2e06 100644 --- a/utils.c +++ b/utils.c @@ -49,7 +49,7 @@ static const struct nla_policy ncr_attr_policy[NCR_ATTR_MAX + 1] = { [NCR_ATTR_ALGORITHM] = { NLA_NUL_STRING, 0 }, - [NCR_ATTR_DERIVATION_ALGORITHM] = { NLA_U32, 0 }, + [NCR_ATTR_DERIVATION_ALGORITHM] = { NLA_NUL_STRING, 0 }, [NCR_ATTR_SIGNATURE_HASH_ALGORITHM] = { NLA_NUL_STRING, 0 }, [NCR_ATTR_WRAPPING_ALGORITHM] = { NLA_U32, 0 }, [NCR_ATTR_UPDATE_INPUT_DATA] = { -- cgit