diff libtomcrypt/src/pk/ecc/ecc_import.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents f849a5ca2efc
children
line wrap: on
line diff
--- a/libtomcrypt/src/pk/ecc/ecc_import.c	Thu Feb 08 23:11:40 2018 +0800
+++ b/libtomcrypt/src/pk/ecc/ecc_import.c	Fri Feb 09 21:44:05 2018 +0800
@@ -5,8 +5,6 @@
  *
  * The library is free for all purposes without any express
  * guarantee it works.
- *
- * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b
@@ -19,34 +17,34 @@
 /**
   @file ecc_import.c
   ECC Crypto, Tom St Denis
-*/  
+*/
 
 #if defined(LTC_MECC) && defined(LTC_DER)
 
-static int is_point(ecc_key *key)
+static int _is_point(ecc_key *key)
 {
    void *prime, *b, *t1, *t2;
    int err;
-   
+
    if ((err = mp_init_multi(&prime, &b, &t1, &t2, NULL)) != CRYPT_OK) {
       return err;
    }
-   
+
    /* load prime and b */
    if ((err = mp_read_radix(prime, key->dp->prime, 16)) != CRYPT_OK)                          { goto error; }
    if ((err = mp_read_radix(b, key->dp->B, 16)) != CRYPT_OK)                                  { goto error; }
-   
+
    /* compute y^2 */
    if ((err = mp_sqr(key->pubkey.y, t1)) != CRYPT_OK)                                         { goto error; }
-   
+
    /* compute x^3 */
    if ((err = mp_sqr(key->pubkey.x, t2)) != CRYPT_OK)                                         { goto error; }
    if ((err = mp_mod(t2, prime, t2)) != CRYPT_OK)                                             { goto error; }
    if ((err = mp_mul(key->pubkey.x, t2, t2)) != CRYPT_OK)                                     { goto error; }
-   
+
    /* compute y^2 - x^3 */
    if ((err = mp_sub(t1, t2, t1)) != CRYPT_OK)                                                { goto error; }
-   
+
    /* compute y^2 - x^3 + 3x */
    if ((err = mp_add(t1, key->pubkey.x, t1)) != CRYPT_OK)                                     { goto error; }
    if ((err = mp_add(t1, key->pubkey.x, t1)) != CRYPT_OK)                                     { goto error; }
@@ -58,14 +56,14 @@
    while (mp_cmp(t1, prime) != LTC_MP_LT) {
       if ((err = mp_sub(t1, prime, t1)) != CRYPT_OK)                                          { goto error; }
    }
-   
+
    /* compare to b */
    if (mp_cmp(t1, b) != LTC_MP_EQ) {
       err = CRYPT_INVALID_PACKET;
    } else {
       err = CRYPT_OK;
    }
-   
+
 error:
    mp_clear_multi(prime, b, t1, t2, NULL);
    return err;
@@ -107,9 +105,9 @@
    }
 
    /* find out what type of key it is */
-   if ((err = der_decode_sequence_multi(in, inlen, 
-                                  LTC_ASN1_BIT_STRING, 1UL, &flags,
-                                  LTC_ASN1_EOL,        0UL, NULL)) != CRYPT_OK) {
+   err = der_decode_sequence_multi(in, inlen, LTC_ASN1_BIT_STRING, 1UL, flags,
+                                              LTC_ASN1_EOL,        0UL, NULL);
+   if (err != CRYPT_OK && err != CRYPT_INPUT_TOO_LONG) {
       goto done;
    }
 
@@ -126,7 +124,7 @@
                                      LTC_ASN1_EOL,             0UL, NULL)) != CRYPT_OK) {
          goto done;
       }
-   } else {
+   } else if (flags[0] == 0) {
       /* public key */
       key->type = PK_PUBLIC;
       if ((err = der_decode_sequence_multi(in, inlen,
@@ -138,6 +136,10 @@
          goto done;
       }
    }
+   else {
+      err = CRYPT_INVALID_PACKET;
+      goto done;
+   }
 
    if (dp == NULL) {
      /* find the idx */
@@ -153,9 +155,9 @@
    }
    /* set z */
    if ((err = mp_set(key->pubkey.z, 1)) != CRYPT_OK) { goto done; }
-   
+
    /* is it a point on the curve?  */
-   if ((err = is_point(key)) != CRYPT_OK) {
+   if ((err = _is_point(key)) != CRYPT_OK) {
       goto done;
    }
 
@@ -166,7 +168,7 @@
    return err;
 }
 #endif
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
+/* ref:         $Format:%D$ */
+/* git commit:  $Format:%H$ */
+/* commit time: $Format:%ai$ */