1 /* 2 * Author: Copyright (C) Andrzej Surowiec 2012 3 * Copyright (c) 2012-2018 Nitrokey UG 4 * 5 * This file is part of Nitrokey App. 6 * 7 * Nitrokey App is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * any later version. 11 * 12 * Nitrokey App is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with Nitrokey App. If not, see <http://www.gnu.org/licenses/>. 19 * 20 * SPDX-License-Identifier: GPL-3.0 21 */ 22 23 24 #ifndef HOTPSLOT_H 25 #define HOTPSLOT_H 26 27 #include <cstdint> 28 #include <vector> 29 #include <string> 30 31 #define TO_BASE32_LEN(x) ((x)/10*16) 32 33 static const unsigned int SECRET_LENGTH = 40; 34 static const unsigned int SECRET_LENGTH_BASE32 = TO_BASE32_LEN(SECRET_LENGTH); 35 static const unsigned int SECRET_LENGTH_HEX = SECRET_LENGTH * 2; 36 37 std::vector<uint8_t> decodeBase32Secret(const std::string secret, const bool debug_mode = false); 38 39 40 class OTPSlot { 41 public: 42 enum OTPType{ 43 UNKNOWN, HOTP, TOTP 44 }; 45 46 OTPSlot(); ~OTPSlot()47 ~OTPSlot(){ 48 volatile char* p; 49 p = slotName; 50 for (uint64_t i = 0; i < sizeof(slotName); ++i) { 51 p[i] = 0; 52 } 53 p = secret; 54 for (uint64_t i = 0; i < sizeof(secret); ++i) { 55 p[i] = 0; 56 } 57 slotNumber = 0; 58 type = OTPType::UNKNOWN; 59 } 60 61 OTPType type; 62 uint8_t slotNumber; 63 char slotName[15+1] = {}; 64 char secret[SECRET_LENGTH_HEX+1] = {}; 65 union { 66 uint8_t counter[8]; 67 uint64_t interval; 68 }; 69 union{ 70 uint8_t config; 71 struct { 72 bool useEightDigits :1; 73 bool useEnter :1; 74 bool useTokenID :1; 75 } config_st; 76 }; 77 char tokenID[13+1] = {}; 78 bool isProgrammed; 79 }; 80 81 #endif // HOTPSLOT_H 82