Changeset 626 in openpam for trunk/modules/pam_oath/oath.h


Ignore:
Timestamp:
Feb 27, 2013, 4:19:56 PM (8 years ago)
Author:
Dag-Erling Smørgrav
Message:

Implement otpauth URI parsing (untested)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/pam_oath/oath.h

    r623 r626  
    3333#define OATH_H_INCLUDED
    3434
    35 #define base32_enclen(l) (((l + 4) / 5) * 8)
    36 #define base32_declen(l) (((l + 7) / 8) * 5)
     35/*
     36 * Maximum time step for TOTP: 10 minutes, which RFC 6238 cites as an
     37 * example of an unreasonably large time step.
     38 */
     39#define OATH_MAX_TIMESTEP       600
     40
     41/*
     42 * Maximum key length in bytes.  HMAC has a 64-byte block size; if the key
     43 * K is longer than that, HMAC derives a new key K' = H(K).
     44 */
     45#define OATH_MAX_KEYLEN         64
     46
     47/* estimate of output length for base32 encoding / decoding */
     48#define base32_enclen(l) (size_t)(((l + 4) / 5) * 8)
     49#define base32_declen(l) (size_t)(((l + 7) / 8) * 5)
     50
     51/* base32 encoding / decoding */
    3752int base32_enc(const uint8_t *, size_t, char *, size_t *);
    3853int base32_dec(const char *, size_t, uint8_t *, size_t *);
    3954
    40 #define base64_enclen(l) (((l + 2) / 3) * 4)
    41 #define base64_declen(l) (((l + 3) / 4) * 3)
     55/* estimate of output length for base64 encoding / decoding */
     56#define base64_enclen(l) (size_t)(((l + 2) / 3) * 4)
     57#define base64_declen(l) (size_t)(((l + 3) / 4) * 3)
     58
     59/* base64 encoding / decoding */
    4260int base64_enc(const uint8_t *, size_t, char *, size_t *);
    4361int base64_dec(const char *, size_t, uint8_t *, size_t *);
    4462
    45 enum oath_alg { undef, hotp, totp };
     63/* mode: hotp (event mode) or totp (time-synch mode) */
     64enum oath_mode { om_undef, om_hotp, om_totp };
    4665
    47 struct oath {
    48         enum oath_alg    alg;
    49         unsigned int     seq;
    50         size_t           keylen;
    51         uint8_t          key[];
     66/* hash function */
     67enum oath_hash { oh_undef, oh_sha1, oh_sha256, oh_sha512, oh_md5 };
     68
     69/* key structure */
     70struct oath_key {
     71        /* mode and parameters */
     72        enum oath_mode   mode;
     73        unsigned int     digits;
     74        uint64_t         counter;
     75        unsigned int     timestep; /* in seconds */
     76
     77        /* hash algorithm */
     78        enum oath_hash   hash;
     79
     80        /* label */
     81        size_t           labellen; /* bytes incl. NUL */
     82        char            *label;
     83
     84        /* key */
     85        size_t           keylen; /* bytes */
     86        uint8_t         *key;
     87
     88        /* buffer for label + NUL + key */
     89        size_t           datalen; /* bytes */
     90        uint8_t          data[];
    5291};
    5392
Note: See TracChangeset for help on using the changeset viewer.