1 /* Software-based Trusted Platform Module (TPM) Emulator 2 * Copyright (C) 2004-2010 Mario Strasser <mast@gmx.net> 3 * 4 * This module is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published 6 * by the Free Software Foundation; either version 2 of the License, 7 * or (at your option) any later version. 8 * 9 * This module is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * $Id: bn.h 464 2011-07-09 14:57:41Z mast $ 15 */ 16 17 #ifndef _BN_H_ 18 #define _BN_H_ 19 20 #include <stddef.h> 21 #include <stdint.h> 22 23 #ifdef USE_OPENSSL 24 #include <openssl/bn.h> 25 typedef BIGNUM tpm_bn_t[1]; 26 #else 27 #include <gmp.h> 28 typedef mpz_t tpm_bn_t; 29 #endif 30 31 void tpm_bn_init(tpm_bn_t a); 32 33 void tpm_bn_init2(tpm_bn_t a, size_t nbits); 34 35 void tpm_bn_init_set(tpm_bn_t a, tpm_bn_t val); 36 37 void tpm_bn_init_set_ui(tpm_bn_t a, uint32_t val); 38 39 void tpm_bn_set_ui(tpm_bn_t a, uint32_t val); 40 41 void tpm_bn_clear(tpm_bn_t a); 42 43 void tpm_bn_swap(tpm_bn_t a, tpm_bn_t b); 44 45 uint32_t tpm_bn_bitsize(tpm_bn_t a); 46 47 void tpm_bn_import(tpm_bn_t out, size_t count, int order, const void *in); 48 49 void tpm_bn_export(void *out, size_t *count, int order, tpm_bn_t in); 50 51 int tpm_bn_cmp(tpm_bn_t a, tpm_bn_t b); 52 53 int tpm_bn_cmp_ui(tpm_bn_t a, uint32_t b); 54 55 int tpm_bn_sgn(tpm_bn_t a); 56 57 void tpm_bn_setbit(tpm_bn_t res, uint32_t bit); 58 59 void tpm_bn_add(tpm_bn_t res, tpm_bn_t a, tpm_bn_t b); 60 61 void tpm_bn_add_ui(tpm_bn_t res, tpm_bn_t a, uint32_t b); 62 63 void tpm_bn_sub(tpm_bn_t res, tpm_bn_t a, tpm_bn_t b); 64 65 void tpm_bn_sub_ui(tpm_bn_t res, tpm_bn_t a, uint32_t b); 66 67 void tpm_bn_mul(tpm_bn_t res, tpm_bn_t a, tpm_bn_t b); 68 69 void tpm_bn_mod(tpm_bn_t res, tpm_bn_t a, tpm_bn_t mod); 70 71 void tpm_bn_powm(tpm_bn_t res, tpm_bn_t base, tpm_bn_t exp, tpm_bn_t mod); 72 73 void tpm_bn_ui_pow_ui(tpm_bn_t res, uint32_t base, uint32_t exp); 74 75 void tpm_bn_fdiv_q_2exp(tpm_bn_t res, tpm_bn_t n, uint32_t b); 76 77 void tpm_bn_tdiv_q(tpm_bn_t res, tpm_bn_t a, tpm_bn_t b); 78 79 void tpm_bn_gcd(tpm_bn_t res, tpm_bn_t a, tpm_bn_t b); 80 81 void tpm_bn_invert(tpm_bn_t res, tpm_bn_t a, tpm_bn_t b); 82 83 void tpm_bn_nextprime(tpm_bn_t res, tpm_bn_t a); 84 85 #endif /* _BN_H_ */ 86