1 /* 2 * XML Security Library (http://www.aleksey.com/xmlsec). 3 * 4 * Simple Big Numbers processing. 5 * 6 * This is free software; see Copyright file in the source 7 * distribution for preciese wording. 8 * 9 * Copyright (C) 2002-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved. 10 */ 11 #ifndef __XMLSEC_BN_H__ 12 #define __XMLSEC_BN_H__ 13 14 #include <libxml/tree.h> 15 #include <xmlsec/xmlsec.h> 16 #include <xmlsec/buffer.h> 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif /* __cplusplus */ 21 22 typedef xmlSecBuffer xmlSecBn, 23 *xmlSecBnPtr; 24 25 /** 26 * xmlSecBnFormat: 27 * @xmlSecBnBase64: the base64 decoded binary blob. 28 * @xmlSecBnHex: the hex number. 29 * @xmlSecBnDec: the decimal number. 30 * 31 * The big numbers formats. 32 */ 33 typedef enum { 34 xmlSecBnBase64, 35 xmlSecBnHex, 36 xmlSecBnDec 37 } xmlSecBnFormat; 38 39 XMLSEC_EXPORT xmlSecBnPtr xmlSecBnCreate (xmlSecSize size); 40 XMLSEC_EXPORT void xmlSecBnDestroy (xmlSecBnPtr bn); 41 XMLSEC_EXPORT int xmlSecBnInitialize (xmlSecBnPtr bn, 42 xmlSecSize size); 43 XMLSEC_EXPORT void xmlSecBnFinalize (xmlSecBnPtr bn); 44 XMLSEC_EXPORT xmlSecByte* xmlSecBnGetData (xmlSecBnPtr bn); 45 XMLSEC_EXPORT int xmlSecBnSetData (xmlSecBnPtr bn, 46 const xmlSecByte* data, 47 xmlSecSize size); 48 XMLSEC_EXPORT xmlSecSize xmlSecBnGetSize (xmlSecBnPtr bn); 49 XMLSEC_EXPORT void xmlSecBnZero (xmlSecBnPtr bn); 50 51 XMLSEC_EXPORT int xmlSecBnFromString (xmlSecBnPtr bn, 52 const xmlChar* str, 53 xmlSecSize base); 54 XMLSEC_EXPORT xmlChar* xmlSecBnToString (xmlSecBnPtr bn, 55 xmlSecSize base); 56 XMLSEC_EXPORT int xmlSecBnFromHexString (xmlSecBnPtr bn, 57 const xmlChar* str); 58 XMLSEC_EXPORT xmlChar* xmlSecBnToHexString (xmlSecBnPtr bn); 59 60 XMLSEC_EXPORT int xmlSecBnFromDecString (xmlSecBnPtr bn, 61 const xmlChar* str); 62 XMLSEC_EXPORT xmlChar* xmlSecBnToDecString (xmlSecBnPtr bn); 63 64 XMLSEC_EXPORT int xmlSecBnMul (xmlSecBnPtr bn, 65 int multiplier); 66 XMLSEC_EXPORT int xmlSecBnDiv (xmlSecBnPtr bn, 67 int divider, 68 int* mod); 69 XMLSEC_EXPORT int xmlSecBnAdd (xmlSecBnPtr bn, 70 int delta); 71 XMLSEC_EXPORT int xmlSecBnReverse (xmlSecBnPtr bn); 72 XMLSEC_EXPORT int xmlSecBnCompare (xmlSecBnPtr bn, 73 const xmlSecByte* data, 74 xmlSecSize dataSize); 75 XMLSEC_EXPORT int xmlSecBnCompareReverse (xmlSecBnPtr bn, 76 const xmlSecByte* data, 77 xmlSecSize dataSize); 78 XMLSEC_EXPORT int xmlSecBnGetNodeValue (xmlSecBnPtr bn, 79 xmlNodePtr cur, 80 xmlSecBnFormat format, 81 int reverse); 82 XMLSEC_EXPORT int xmlSecBnSetNodeValue (xmlSecBnPtr bn, 83 xmlNodePtr cur, 84 xmlSecBnFormat format, 85 int reverse, 86 int addLineBreaks); 87 XMLSEC_EXPORT int xmlSecBnBlobSetNodeValue (const xmlSecByte* data, 88 xmlSecSize dataSize, 89 xmlNodePtr cur, 90 xmlSecBnFormat format, 91 int reverse, 92 int addLineBreaks); 93 94 #ifdef __cplusplus 95 } 96 #endif /* __cplusplus */ 97 98 #endif /* __XMLSEC_BN_H__ */ 99 100