diff options
author | Miloslav Trmač <mitr@redhat.com> | 2010-08-18 05:51:32 +0200 |
---|---|---|
committer | Miloslav Trmač <mitr@redhat.com> | 2010-08-24 23:59:46 +0200 |
commit | f9fa90899a4691ce01244593e2902111fe9bf2c6 (patch) | |
tree | 39d1ba8c29b4df7323016dc171692225cc1f847f | |
parent | eef7de54be0cd38abb689de7b0a749154b04c694 (diff) | |
download | kernel-crypto-f9fa90899a4691ce01244593e2902111fe9bf2c6.tar.gz kernel-crypto-f9fa90899a4691ce01244593e2902111fe9bf2c6.tar.xz kernel-crypto-f9fa90899a4691ce01244593e2902111fe9bf2c6.zip |
Replace ncr_derive_t by NLA_NUL_STRING
-rw-r--r-- | examples/pk.c | 6 | ||||
-rw-r--r-- | ncr-pk.c | 39 | ||||
-rw-r--r-- | ncr.h | 6 | ||||
-rw-r--r-- | 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; @@ -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; @@ -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 { @@ -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] = { |