Browse Source

remove dh_export_radix.c dh_import_radix.c

Karel Miko 8 years ago
parent
commit
5eaff56d90
2 changed files with 0 additions and 158 deletions
  1. 0 68
      src/pk/dh/dh_export_radix.c
  2. 0 90
      src/pk/dh/dh_import_radix.c

+ 0 - 68
src/pk/dh/dh_export_radix.c

@@ -1,68 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
-
-#include "tomcrypt.h"
-
-#ifdef LTC_MDH
-
-static unsigned long _count_digits(int radix, void *num)
-{
-   void *r, *t;
-   unsigned long digits = 0;
-
-   if (mp_iszero(num) == LTC_MP_YES) return 1;
-   if (mp_init_multi(&t, &r, NULL) != CRYPT_OK) return 0;
-   mp_copy(num, t);
-   mp_set_int(r, radix);
-   while (mp_iszero(t) == LTC_MP_NO) {
-      if (mp_div(t, r, t, NULL) != CRYPT_OK) {
-         mp_clear_multi(t, r, NULL);
-         return 0;
-      }
-      digits++;
-   }
-   mp_clear_multi(t, r, NULL);
-   return digits;
-}
-
-/**
-  Export a DH key to a binary packet
-  @param out    [out] The destination for the key
-  @param outlen [in/out] The max size and resulting size of the DH key
-  @param type   Which type of key (PK_PRIVATE or PK_PUBLIC)
-  @param key    The key you wish to export
-  @return CRYPT_OK if successful
-*/
-int dh_export_radix(int radix, void *out, unsigned long *outlen, int type, dh_key *key)
-{
-   unsigned long len;
-   void *k;
-
-   LTC_ARGCHK(out    != NULL);
-   LTC_ARGCHK(outlen != NULL);
-   LTC_ARGCHK(key    != NULL);
-   LTC_ARGCHK((radix >= 2 && radix <= 64) || radix == 256);
-
-   k = (type == PK_PRIVATE) ? key->x : key->y;
-   len = (radix == 256) ? mp_unsigned_bin_size(k) : _count_digits(radix, k) + 1;
-
-   if (*outlen < len) {
-      *outlen = len;
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-   *outlen = len;
-
-   return (radix == 256) ? mp_to_unsigned_bin(k, out) : mp_toradix(k, out, radix);
-}
-
-#endif /* LTC_MDH */
-
-/* ref:         $Format:%D$ */
-/* git commit:  $Format:%H$ */
-/* commit time: $Format:%ai$ */

+ 0 - 90
src/pk/dh/dh_import_radix.c

@@ -1,90 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- */
-
-#include "tomcrypt.h"
-
-#ifdef LTC_MDH
-
-/**
-  Import a DH key from a binary string
-  @param in     The string to read
-  @param inlen  The length of the input packet
-  @param type   The type of key (PK_PRIVATE or PK_PUBLIC)
-  @param base   The base (generator) in hex string
-  @param prime  The prime in hex string
-  @param key    [out] Where to import the key to
-  @return CRYPT_OK if successful, on error all allocated memory is freed automatically
-*/
-int dh_import_radix(int radix,
-                    void *in,    unsigned long inlen,
-                    void *prime, unsigned long primelen,
-                    void *base,  unsigned long baselen,
-                    int type, dh_key *key)
-{
-   int err;
-
-   LTC_ARGCHK(in    != NULL);
-   LTC_ARGCHK(base  != NULL);
-   LTC_ARGCHK(prime != NULL);
-   LTC_ARGCHK(key   != NULL);
-
-   if ((err = mp_init_multi(&key->x, &key->y, &key->base, &key->prime, NULL)) != CRYPT_OK) {
-      goto error;
-   }
-   if (radix == 256) {
-      if ((err = mp_read_unsigned_bin(key->base, base, baselen)) != CRYPT_OK)     { goto error; }
-      if ((err = mp_read_unsigned_bin(key->prime, prime, primelen)) != CRYPT_OK)  { goto error; }
-   }
-   else {
-      if ((err = mp_read_radix(key->base, base, radix)) != CRYPT_OK)              { goto error; }
-      if ((err = mp_read_radix(key->prime, prime, radix)) != CRYPT_OK)            { goto error; }
-   }
-
-   if (type == PK_PRIVATE) {
-      /* load the x value */
-      if (radix == 256) {
-         if ((err = mp_read_unsigned_bin(key->x, in, inlen)) != CRYPT_OK)         { goto error; }
-      }
-      else {
-         if ((err = mp_read_radix(key->x, in, radix)) != CRYPT_OK)                { goto error; }
-      }
-      /* compute y value */
-      if ((err = mp_exptmod(key->base, key->x, key->prime, key->y)) != CRYPT_OK)  { goto error; }
-      key->type = PK_PRIVATE;
-   }
-   else {
-      /* load the y value */
-      if (radix == 256) {
-         if ((err = mp_read_unsigned_bin(key->y, in, inlen)) != CRYPT_OK)         { goto error; }
-      }
-      else {
-         if ((err = mp_read_radix(key->y, in, radix)) != CRYPT_OK)                { goto error; }
-      }
-      key->type = PK_PUBLIC;
-      mp_clear(key->x);
-      key->x = NULL;
-   }
-
-   /* check public key */
-   if ((err = dh_check_pubkey(key)) != CRYPT_OK) {
-      goto error;
-   }
-
-   return CRYPT_OK;
-
-error:
-   mp_clear_multi(key->prime, key->base, key->y, key->x, NULL);
-   return err;
-}
-
-#endif /* LTC_MDH */
-
-/* ref:         $Format:%D$ */
-/* git commit:  $Format:%H$ */
-/* commit time: $Format:%ai$ */