summaryrefslogtreecommitdiff
path: root/cipher/pubkey-util.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2013-10-25 15:44:03 +0200
committerWerner Koch <wk@gnupg.org>2013-10-29 14:38:53 +0100
commitba892a0a874c8b2a83dbf0940608cd7e2911ce01 (patch)
tree05d693e86d52f336aa9142c8176fb5a88a3b59cb /cipher/pubkey-util.c
parent1faa61845f180bd47e037e400dde2d864ee83c89 (diff)
downloadlibgcrypt-ba892a0a874c8b2a83dbf0940608cd7e2911ce01.tar.gz
ecc: Add flags "noparam" and "comp".
* src/cipher.h (PUBKEY_FLAG_NOPARAM, PUBKEY_FLAG_COMP): New. * cipher/pubkey-util.c (_gcry_pk_util_parse_flaglist): Parse new flags and change code for possible faster parsing. * cipher/ecc.c (ecc_generate): Implement the "noparam" flag. (ecc_sign): Ditto. (ecc_verify): Ditto. * tests/keygen.c (check_ecc_keys): Use the "noparam" flag. * cipher/ecc.c (ecc_generate): Fix parsing of the deprecated transient-flag parameter. (ecc_verify): Do not make Q optional in the extract-param call. -- Note that the "comp" flag has not yet any effect. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'cipher/pubkey-util.c')
-rw-r--r--cipher/pubkey-util.c146
1 files changed, 92 insertions, 54 deletions
diff --git a/cipher/pubkey-util.c b/cipher/pubkey-util.c
index 0db5840b..88d6bb69 100644
--- a/cipher/pubkey-util.c
+++ b/cipher/pubkey-util.c
@@ -47,7 +47,7 @@ pss_verify_cmp (void *opaque, gcry_mpi_t tmp)
/* Parser for a flag list. On return the encoding is stored at
- R_ENCODING and the flags are stored at R_FLAGS. if any of them is
+ R_ENCODING and the flags are stored at R_FLAGS. If any of them is
not needed, NULL may be passed. The function returns 0 on success
or an error code. */
gpg_err_code_t
@@ -65,61 +65,99 @@ _gcry_pk_util_parse_flaglist (gcry_sexp_t list,
{
s = gcry_sexp_nth_data (list, i, &n);
if (!s)
- ; /* not a data element*/
- else if (n == 7 && !memcmp (s, "rfc6979", 7))
- {
- flags |= PUBKEY_FLAG_RFC6979;
- }
- else if (n == 5 && !memcmp (s, "eddsa", 5))
- {
- encoding = PUBKEY_ENC_RAW;
- flags |= PUBKEY_FLAG_EDDSA;
- }
- else if (n == 5 && !memcmp (s, "ecdsa", 5))
- {
- flags |= PUBKEY_FLAG_ECDSA;
- }
- else if (n == 4 && !memcmp (s, "gost", 4))
- {
- encoding = PUBKEY_ENC_RAW;
- flags |= PUBKEY_FLAG_GOST;
- }
- else if (n == 3 && !memcmp (s, "raw", 3)
- && encoding == PUBKEY_ENC_UNKNOWN)
- {
- encoding = PUBKEY_ENC_RAW;
- flags |= PUBKEY_FLAG_RAW_FLAG; /* Explicitly given. */
- }
- else if (n == 5 && !memcmp (s, "pkcs1", 5)
- && encoding == PUBKEY_ENC_UNKNOWN)
- {
- encoding = PUBKEY_ENC_PKCS1;
- flags |= PUBKEY_FLAG_FIXEDLEN;
- }
- else if (n == 4 && !memcmp (s, "oaep", 4)
- && encoding == PUBKEY_ENC_UNKNOWN)
- {
- encoding = PUBKEY_ENC_OAEP;
- flags |= PUBKEY_FLAG_FIXEDLEN;
- }
- else if (n == 3 && !memcmp (s, "pss", 3)
- && encoding == PUBKEY_ENC_UNKNOWN)
+ continue; /* Not a data element. */
+
+ switch (n)
{
- encoding = PUBKEY_ENC_PSS;
- flags |= PUBKEY_FLAG_FIXEDLEN;
+ case 3:
+ if (!memcmp (s, "pss", 3) && encoding == PUBKEY_ENC_UNKNOWN)
+ {
+ encoding = PUBKEY_ENC_PSS;
+ flags |= PUBKEY_FLAG_FIXEDLEN;
+ }
+ else if (!memcmp (s, "raw", 3) && encoding == PUBKEY_ENC_UNKNOWN)
+ {
+ encoding = PUBKEY_ENC_RAW;
+ flags |= PUBKEY_FLAG_RAW_FLAG; /* Explicitly given. */
+ }
+ else
+ rc = GPG_ERR_INV_FLAG;
+ break;
+
+ case 4:
+ if (!memcmp (s, "comp", 4))
+ flags |= PUBKEY_FLAG_COMP;
+ else if (!memcmp (s, "oaep", 4) && encoding == PUBKEY_ENC_UNKNOWN)
+ {
+ encoding = PUBKEY_ENC_OAEP;
+ flags |= PUBKEY_FLAG_FIXEDLEN;
+ }
+ else if (!memcmp (s, "gost", 4))
+ {
+ encoding = PUBKEY_ENC_RAW;
+ flags |= PUBKEY_FLAG_GOST;
+ }
+ else
+ rc = GPG_ERR_INV_FLAG;
+ break;
+
+ case 5:
+ if (!memcmp (s, "eddsa", 5))
+ {
+ encoding = PUBKEY_ENC_RAW;
+ flags |= PUBKEY_FLAG_EDDSA;
+ }
+ else if (!memcmp (s, "ecdsa", 5))
+ {
+ flags |= PUBKEY_FLAG_ECDSA;
+ }
+ else if (!memcmp (s, "pkcs1", 5) && encoding == PUBKEY_ENC_UNKNOWN)
+ {
+ encoding = PUBKEY_ENC_PKCS1;
+ flags |= PUBKEY_FLAG_FIXEDLEN;
+ }
+ else
+ rc = GPG_ERR_INV_FLAG;
+ break;
+
+ case 7:
+ if (!memcmp (s, "rfc6979", 7))
+ flags |= PUBKEY_FLAG_RFC6979;
+ else if (!memcmp (s, "noparam", 7))
+ flags |= PUBKEY_FLAG_NOPARAM;
+ else
+ rc = GPG_ERR_INV_FLAG;
+ break;
+
+ case 8:
+ if (!memcmp (s, "use-x931", 8))
+ flags |= PUBKEY_FLAG_USE_X931;
+ else
+ rc = GPG_ERR_INV_FLAG;
+ break;
+
+ case 11:
+ if (!memcmp (s, "no-blinding", 11))
+ flags |= PUBKEY_FLAG_NO_BLINDING;
+ else if (!memcmp (s, "use-fips186", 11))
+ flags |= PUBKEY_FLAG_USE_FIPS186;
+ else
+ rc = GPG_ERR_INV_FLAG;
+ break;
+
+ case 13:
+ if (!memcmp (s, "use-fips186-2", 13))
+ flags |= PUBKEY_FLAG_USE_FIPS186_2;
+ else if (!memcmp (s, "transient-key", 13))
+ flags |= PUBKEY_FLAG_TRANSIENT_KEY;
+ else
+ rc = GPG_ERR_INV_FLAG;
+ break;
+
+ default:
+ rc = GPG_ERR_INV_FLAG;
+ break;
}
- else if (n == 11 && ! memcmp (s, "no-blinding", 11))
- flags |= PUBKEY_FLAG_NO_BLINDING;
- else if (n == 13 && ! memcmp (s, "transient-key", 13))
- flags |= PUBKEY_FLAG_TRANSIENT_KEY;
- else if (n == 8 && ! memcmp (s, "use-x931", 8))
- flags |= PUBKEY_FLAG_USE_X931;
- else if (n == 11 && ! memcmp (s, "use-fips186", 11))
- flags |= PUBKEY_FLAG_USE_FIPS186;
- else if (n == 13 && ! memcmp (s, "use-fips186-2", 13))
- flags |= PUBKEY_FLAG_USE_FIPS186_2;
- else
- rc = GPG_ERR_INV_FLAG;
}
if (r_flags)