Browse Source

minor changes

print MP_DIGIT_BIT when running test
der_test: improve error output of 'short integer' test
Steffen Jaeckel 11 years ago
parent
commit
c1e81ad469
3 changed files with 9 additions and 3 deletions
  1. 1 0
      demos/test.c
  2. 4 0
      src/headers/tomcrypt_pk.h
  3. 4 3
      testprof/der_tests.c

+ 1 - 0
demos/test.c

@@ -17,6 +17,7 @@ int main(void)
 #endif
 
    printf("build == \n%s\n", crypt_build_settings);
+   printf("MP_DIGIT_BIT = %d\n", MP_DIGIT_BIT);
    printf("\nstore_test...."); fflush(stdout); x = store_test();       printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE);
    printf("\nmisc_test....."); fflush(stdout); x = misc_test();        printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE);
    printf("\ncipher_test..."); fflush(stdout); x = cipher_hash_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE);

+ 4 - 0
src/headers/tomcrypt_pk.h

@@ -439,21 +439,25 @@ int dsa_shared_secret(void          *private_key, void *base,
 /* DER handling */
 
 typedef enum ltc_asn1_type_ {
+ /*  0 */
  LTC_ASN1_EOL,
  LTC_ASN1_BOOLEAN,
  LTC_ASN1_INTEGER,
  LTC_ASN1_SHORT_INTEGER,
  LTC_ASN1_BIT_STRING,
+ /*  5 */
  LTC_ASN1_OCTET_STRING,
  LTC_ASN1_NULL,
  LTC_ASN1_OBJECT_IDENTIFIER,
  LTC_ASN1_IA5_STRING,
  LTC_ASN1_PRINTABLE_STRING,
+ /* 10 */
  LTC_ASN1_UTF8_STRING,
  LTC_ASN1_UTCTIME,
  LTC_ASN1_CHOICE,
  LTC_ASN1_SEQUENCE,
  LTC_ASN1_SET,
+ /* 15 */
  LTC_ASN1_SETOF,
  LTC_ASN1_RAW_BIT_STRING,
  LTC_ASN1_TELETEX_STRING,

+ 4 - 3
testprof/der_tests.c

@@ -549,12 +549,12 @@ int der_tests(void)
 /* test short integer */
    for (zz = 0; zz < 256; zz++) {
       for (z = 1; z < 4; z++) {
-         if (yarrow_read(buf[0], z, &yarrow_prng) != z) {
+         if (yarrow_read(buf[2], z, &yarrow_prng) != z) {
             fprintf(stderr, "Failed to read %lu bytes from yarrow\n", z);
             return 1;
          }
          /* encode with normal */
-         DO(mp_read_unsigned_bin(a, buf[0], z));
+         DO(mp_read_unsigned_bin(a, buf[2], z));
 
          x = sizeof(buf[0]);
          DO(der_encode_integer(a, buf[0], &x));
@@ -563,7 +563,8 @@ int der_tests(void)
          y = sizeof(buf[1]);
          DO(der_encode_short_integer(mp_get_int(a), buf[1], &y));
          if (x != y || memcmp(buf[0], buf[1], x)) {
-            fprintf(stderr, "DER INTEGER short encoding failed, %lu, %lu\n", x, y);
+            fprintf(stderr, "DER INTEGER short encoding failed, %lu, %lu, 0x%lX\n", x, y, mp_get_int(a));
+            for (zz = 0; zz < z; zz++) fprintf(stderr, "%02x ", buf[2][zz]); fprintf(stderr, "\n");
             for (z = 0; z < x; z++) fprintf(stderr, "%02x ", buf[0][z]); fprintf(stderr, "\n");
             for (z = 0; z < y; z++) fprintf(stderr, "%02x ", buf[1][z]); fprintf(stderr, "\n");
             mp_clear_multi(a, b, c, d, e, f, g, NULL);