Changeset 655 in openpam for trunk/include/security/oath_constants.h


Ignore:
Timestamp:
Mar 6, 2013, 2:10:09 PM (8 years ago)
Author:
Dag-Erling Smørgrav
Message:

Split up the liboath header files.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/include/security/oath_constants.h

    r654 r655  
    3030 */
    3131
    32 #ifndef OATH_H_INCLUDED
    33 #define OATH_H_INCLUDED
     32#ifndef OATH_CONSTANTS_H_INCLUDED
     33#define OATH_CONSTANTS_H_INCLUDED
     34
     35/*
     36 * OATH modes
     37 */
     38enum oath_mode {
     39        om_undef,               /* not set / default */
     40        om_hotp,                /* RFC 4226 HOTP */
     41        om_totp,                /* RFC 6238 TOTP */
     42        om_max
     43};
     44
     45/*
     46 * Hash functions
     47 */
     48enum oath_hash {
     49        oh_undef,               /* not set / default */
     50        oh_md5,                 /* RFC 1321 MD5 */
     51        oh_sha1,                /* FIPS 180 SHA-1 */
     52        oh_sha256,              /* FIPS 180 SHA-256 */
     53        oh_sha512,              /* FIPS 180 SHA-512 */
     54        oh_max
     55};
    3456
    3557/*
     
    5072#define OATH_MAX_KEYLEN         64
    5173
    52 /* estimate of output length for base32 encoding / decoding */
    53 #define base32_enclen(l) (size_t)(((l + 4) / 5) * 8)
    54 #define base32_declen(l) (size_t)(((l + 7) / 8) * 5)
    55 
    56 /* base32 encoding / decoding */
    57 int base32_enc(const uint8_t *, size_t, char *, size_t *);
    58 int base32_dec(const char *, size_t, uint8_t *, size_t *);
    59 
    60 /* estimate of output length for base64 encoding / decoding */
    61 #define base64_enclen(l) (size_t)(((l + 2) / 3) * 4)
    62 #define base64_declen(l) (size_t)(((l + 3) / 4) * 3)
    63 
    64 /* base64 encoding / decoding */
    65 int base64_enc(const uint8_t *, size_t, char *, size_t *);
    66 int base64_dec(const char *, size_t, uint8_t *, size_t *);
    67 
    68 /* mode: hotp (event mode) or totp (time-synch mode) */
    69 enum oath_mode { om_undef, om_hotp, om_totp };
    70 
    71 /* hash function */
    72 enum oath_hash { oh_undef, oh_sha1, oh_sha256, oh_sha512, oh_md5 };
    73 
    74 /* key structure */
    75 struct oath_key {
    76         /* mode and parameters */
    77         enum oath_mode   mode;
    78         unsigned int     digits;
    79         uint64_t         counter;
    80         unsigned int     timestep; /* in seconds */
    81 
    82         /* hash algorithm */
    83         enum oath_hash   hash;
    84 
    85         /* label */
    86         size_t           labellen; /* bytes incl. NUL */
    87         char            *label;
    88 
    89         /* key */
    90         size_t           keylen; /* bytes */
    91         uint8_t         *key;
    92 
    93         /* buffer for label + NUL + key */
    94         size_t           datalen; /* bytes */
    95         uint8_t          data[];
    96 };
    97 
    98 struct oath_key *oath_key_alloc(size_t);
    99 void oath_key_free(struct oath_key *);
    100 struct oath_key *oath_key_from_uri(const char *);
    101 struct oath_key *oath_key_from_file(const char *);
    102 char *oath_key_to_uri(const struct oath_key *);
    103 
    104 #define DUMMY_LABEL     ("oath-dummy-key")
    105 #define DUMMY_LABELLEN  (sizeof DUMMY_LABEL)
    106 #define DUMMY_KEYLEN    80
    107 
    108 struct oath_key *oath_dummy_key(enum oath_mode, enum oath_hash, unsigned int);
    109 
    110 unsigned int oath_hotp(const uint8_t *, size_t, uint64_t, unsigned int);
    111 int oath_hotp_current(struct oath_key *);
    112 int oath_hotp_match(struct oath_key *, unsigned int, int);
    113 
    114 unsigned int oath_totp(const uint8_t *, size_t, unsigned int);
    115 int oath_totp_match(const struct oath_key *, unsigned int, int);
    116 unsigned int oath_totp_current(const struct oath_key *);
    117 
    11874#endif
Note: See TracChangeset for help on using the changeset viewer.