1/* $OpenBSD: yubikey.h,v 1.3 2013/06/04 18:49:12 mcbride Exp $ */ 2 3/* 4 * Written by Simon Josefsson <simon@josefsson.org>. 5 * Copyright (c) 2006, 2007, 2008, 2009, 2010 Yubico AB 6 * Copyright (c) 2010 Daniel Hartmeier <daniel@benzedrine.cx> 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions are 11 * met: 12 * 13 * * Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 16 * * Redistributions in binary form must reproduce the above 17 * copyright notice, this list of conditions and the following 18 * disclaimer in the documentation and/or other materials provided 19 * with the distribution. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * 33 */ 34 35#ifndef __YUBIKEY_H__ 36#define __YUBIKEY_H__ 37 38#include <stdint.h> 39#include <string.h> 40 41#define YUBIKEY_BLOCK_SIZE 16 42#define YUBIKEY_KEY_SIZE 16 43#define YUBIKEY_TOKEN_SIZE 32 44#define YUBIKEY_UID_SIZE 6 45#define YUBIKEY_CRC_OK_RESIDUE 0xf0b8 46 47#define yubikey_counter(ctr) ((ctr) & 0x7FFF) 48#define yubikey_capslock(ctr) ((ctr) & 0x8000) 49#define yubikey_crc_ok_p(tok) \ 50 (yubikey_crc16 ((tok), YUBIKEY_BLOCK_SIZE) == YUBIKEY_CRC_OK_RESIDUE) 51 52typedef struct { 53 uint8_t uid[YUBIKEY_UID_SIZE]; 54 uint16_t ctr; 55 uint16_t tstpl; 56 uint8_t tstph; 57 uint8_t use; 58 uint16_t rnd; 59 uint16_t crc; 60} yubikey_token_st; 61 62typedef yubikey_token_st *yubikey_token_t; 63 64extern int yubikey_parse(const uint8_t token[YUBIKEY_BLOCK_SIZE], 65 const uint8_t key[YUBIKEY_KEY_SIZE], yubikey_token_t out, int index); 66 67extern void yubikey_modhex_decode(char *dst, const char *src, size_t dstsize); 68 69extern void yubikey_hex_encode(char *dst, const char *src, size_t srcsize); 70extern void yubikey_hex_decode(char *dst, const char *src, size_t dstsize); 71 72extern uint16_t yubikey_crc16(const uint8_t *buf, size_t buf_size); 73 74extern void yubikey_aes_decrypt(uint8_t *state, const uint8_t *key); 75 76#endif 77