~ubuntu-branches/ubuntu/precise/dropbear/precise

« back to all changes in this revision

Viewing changes to libtomcrypt/src/pk/ecc/ecc_export.c

  • Committer: Bazaar Package Importer
  • Author(s): Gerrit Pape
  • Date: 2007-03-02 20:48:18 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070302204818-ozmbou2sbyj7dus5
Tags: 0.49-1
* new upstream release, fixes
  * CVE-2007-1099: dropbear dbclient insufficient warning on hostkey
    mismatch (closes: #412899).
  * dbclient uses static "Password:" prompt instead of using the server's
    prompt (closes: #394996).
* debian/control: Suggests: openssh-client, not ssh (closes: #405686);
  Standards-Version: 3.7.2.2.
* debian/README.Debian: ssh -> openssh-server, openssh-client; remove
  'Replacing OpenSSH "sshd" with Dropbear' part, this is simply done by not
  installing the openssh-server package.
* debian/README.runit: runsvstat -> sv status.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
 
2
 *
 
3
 * LibTomCrypt is a library that provides various cryptographic
 
4
 * algorithms in a highly modular and flexible manner.
 
5
 *
 
6
 * The library is free for all purposes without any express
 
7
 * guarantee it works.
 
8
 *
 
9
 * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
 
10
 */
 
11
 
 
12
/* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b
 
13
 *
 
14
 * All curves taken from NIST recommendation paper of July 1999
 
15
 * Available at http://csrc.nist.gov/cryptval/dss.htm
 
16
 */
 
17
#include "tomcrypt.h"
 
18
 
 
19
/**
 
20
  @file ecc_export.c
 
21
  ECC Crypto, Tom St Denis
 
22
*/  
 
23
 
 
24
#ifdef MECC
 
25
 
 
26
/**
 
27
  Export an ECC key as a binary packet
 
28
  @param out     [out] Destination for the key
 
29
  @param outlen  [in/out] Max size and resulting size of the exported key
 
30
  @param type    The type of key you want to export (PK_PRIVATE or PK_PUBLIC)
 
31
  @param key     The key to export
 
32
  @return CRYPT_OK if successful
 
33
*/
 
34
int ecc_export(unsigned char *out, unsigned long *outlen, int type, ecc_key *key)
 
35
{
 
36
   int           err;
 
37
   unsigned char flags[1];
 
38
   unsigned long key_size;
 
39
 
 
40
   LTC_ARGCHK(out    != NULL);
 
41
   LTC_ARGCHK(outlen != NULL);
 
42
   LTC_ARGCHK(key    != NULL);
 
43
   
 
44
   /* type valid? */
 
45
   if (key->type != PK_PRIVATE && type == PK_PRIVATE) {
 
46
      return CRYPT_PK_TYPE_MISMATCH;
 
47
   }
 
48
 
 
49
   if (ltc_ecc_is_valid_idx(key->idx) == 0) {
 
50
      return CRYPT_INVALID_ARG;
 
51
   }
 
52
 
 
53
   /* we store the NIST byte size */
 
54
   key_size = key->dp->size;
 
55
 
 
56
   if (type == PK_PRIVATE) {
 
57
       flags[0] = 1;
 
58
       err = der_encode_sequence_multi(out, outlen,
 
59
                                 LTC_ASN1_BIT_STRING,      1UL, flags,
 
60
                                 LTC_ASN1_SHORT_INTEGER,   1UL, &key_size,
 
61
                                 LTC_ASN1_INTEGER,         1UL, key->pubkey.x,
 
62
                                 LTC_ASN1_INTEGER,         1UL, key->pubkey.y,
 
63
                                 LTC_ASN1_INTEGER,         1UL, key->k,
 
64
                                 LTC_ASN1_EOL,             0UL, NULL);
 
65
   } else {
 
66
       flags[0] = 0;
 
67
       err = der_encode_sequence_multi(out, outlen,
 
68
                                 LTC_ASN1_BIT_STRING,      1UL, flags,
 
69
                                 LTC_ASN1_SHORT_INTEGER,   1UL, &key_size,
 
70
                                 LTC_ASN1_INTEGER,         1UL, key->pubkey.x,
 
71
                                 LTC_ASN1_INTEGER,         1UL, key->pubkey.y,
 
72
                                 LTC_ASN1_EOL,             0UL, NULL);
 
73
   }
 
74
 
 
75
   return err;
 
76
}
 
77
 
 
78
#endif
 
79
/* $Source: /cvs/libtom/libtomcrypt/src/pk/ecc/ecc_export.c,v $ */
 
80
/* $Revision: 1.4 $ */
 
81
/* $Date: 2006/11/21 00:10:18 $ */
 
82