Changeset 755 in openpam for trunk/lib


Ignore:
Timestamp:
Jan 22, 2014, 3:12:15 PM (7 years ago)
Author:
Dag-Erling Smørgrav
Message:
  • The key length is in bytes, not bits, so the correct default is 20 and not 160 (which would actually overflow). This should probably be a macro.
  • Implement random key generation using OpenSSL's RAND_bytes(3).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/liboath/oath_key_create.c

    r752 r755  
    3737#include <string.h>
    3838
     39#include <openssl/rand.h>
     40
    3941#include <security/oath.h>
    4042
     
    5052    const char *keydata, size_t keylen)
    5153{
     54        char keybuf[OATH_MAX_KEYLEN];
    5255        struct oath_key *key;
    53         int fd, labellen;
     56        int labellen;
    5457
    5558        /* check label */
     
    6366                return (NULL);
    6467        if (keylen == 0)
    65                 keylen = 160;
     68                keylen = 20;
    6669
    6770        /* check mode */
     
    8891        }
    8992
     93        /* generate key data if necessary */
     94        if (keydata == NULL) {
     95                if (RAND_bytes((void *)keybuf, keylen) != 1)
     96                        return (NULL);
     97                keydata = keybuf;
     98        }
     99
    90100        /* allocate */
    91101        if ((key = oath_key_alloc()) == NULL)
     
    107117
    108118        /* key */
    109         if (keydata == NULL) {
    110                 /* XXX generate random key */
    111                 (void)(fd = 0);
    112         } else {
    113                 memcpy(key->key, keydata, keylen);
    114         }
     119        memcpy(key->key, keydata, keylen);
    115120        key->keylen = keylen;
    116121
Note: See TracChangeset for help on using the changeset viewer.