| 1 | #cxx . . $ `<file>/libfastmint.h`/if !defined( _libfastmint_h ) |
| 2 | #define _libfastmint_hcxx . . $ `libfastmint.h:2:9`! |
| 3 | |
| 4 | #if defined(WIN32) |
| 5 | #include <windows.h> |
| 6 | #undef small |
| 7 | #else |
| 8 | #include <sys/time.h> |
| 9 | #endif |
| 10 | #include "hashcash.h"cxx . . $ `<file>/hashcash.h`/ |
| 11 | |
| 12 | #if defined(WIN32) |
| 13 | #define MILLISEC 1 |
| 14 | #define TIMETYPE DWORD |
| 15 | #define TIME0 0 |
| 16 | #define timer(x) (*(x)=GetTickCount()) |
| 17 | #else |
| 18 | #define MILLISECcxx . . $ `libfastmint.h:18:9`! 1000 |
| 19 | #define TIME0cxx . . $ `libfastmint.h:19:9`! {0,0} |
| 20 | #define TIMETYPEcxx . . $ `libfastmint.h:20:9`! struct timeval |
| 21 | #define timercxx . . $ `libfastmint.h:21:9`!(x) gettimeofday(x,NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 22 | #endif |
| 23 | |
| 24 | #define MINTER_CALLBACK_ARGScxx . . $ `libfastmint.h:24:9`! hashcash_callback cb, void* user_args, \ |
| 25 | double counter, double expected |
| 26 | |
| 27 | #define MINTER_CALLBACK_VARScxx . . $ `libfastmint.h:27:9`! double percent; \ |
| 28 | TIMETYPEcxx . . $ `libfastmint.h:20:9`! prev=TIME0cxx . . $ `libfastmint.h:19:9`!, curr; \ |
| 29 | int lastBits = *best |
| 30 | |
| 31 | /* in minter if have to do something for acces to floating point |
| 32 | * operations override this */ |
| 33 | |
| 34 | /* eg mmx minter sets to this: __builtin_ia32_emms() */ |
| 35 | |
| 36 | #define MINTER_CALLBACK_CLEANUP_FPcxx . . $ `libfastmint.h:36:9`! /**/ |
| 37 | |
| 38 | |
| 39 | #if defined(WIN32) |
| 40 | #define small_time_diff_gt( c, p, intv ) \ |
| 41 | ((c>p?c-p:(c+(((TIMETYPE)-1)-p)))>(intv)) |
| 42 | #else |
| 43 | /* works for intervals < 1 second */ |
| 44 | #define small_time_diff_gtcxx . . $ `libfastmint.h:44:9`!( c, p, intv ) \ |
| 45 | (c.tv_sec-p.tv_sec>1 || \ |
| 46 | (c.tv_usec+((c.tv_sec - p.tv_sec)?1000000:0))-p.tv_usec>(intv)) |
| 47 | #endif |
| 48 | |
| 49 | #define MINTER_CALLBACKcxx . . $ `libfastmint.h:49:9`!() \ |
| 50 | do { \ |
| 51 | if (cb != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! && (iters & 0xFFFF) == 0) { \ |
| 52 | timercxx . . $ `libfastmint.h:21:9`!(&curr); \ |
| 53 | if (gotBits > lastBits || \ |
| 54 | small_time_diff_gtcxx . . $ `libfastmint.h:44:9`!(curr,prev,100*MILLISECcxx . . $ `libfastmint.h:18:9`!)) { \ |
| 55 | MINTER_CALLBACK_CLEANUP_FPcxx . . $ `libfastmint.h:36:9`!; \ |
| 56 | percent = (int)(((counter+iters)/ \ |
| 57 | expected*100)+0.5); \ |
| 58 | if (!cb(percent,*best,bits, \ |
| 59 | counter+iters,expected,user_args)) { \ |
| 60 | *best = -1; \ |
| 61 | return 0; \ |
| 62 | } \ |
| 63 | prev = curr; \ |
| 64 | lastBits = gotBits; \ |
| 65 | } \ |
| 66 | } \ |
| 67 | } while (0) |
| 68 | |
| 69 | typedef unsigned int uInt32cxx . . $ uInt32#; |
| 70 | typedef unsigned long (* HC_Mint_Routinecxx . . $ HC_Mint_Routine#)(int bits, int* best, unsigned char *block, const uInt32cxx . . $ uInt32# IV[5], int tailIndex, unsigned long maxIter, MINTER_CALLBACK_ARGScxx . . $ `libfastmint.h:24:9`!); |
| 71 | typedef int (* HC_Mint_Capable_Routinecxx . . $ HC_Mint_Capable_Routine#)(void); |
| 72 | |
| 73 | typedef enumcxx . . $ $anonymous_type_1d012c4871d7ce83_0# { |
| 74 | EncodeHexUppercxx . . $ EncodeHexUpper., /* 0123456789ABCDEF */ |
| 75 | EncodeHexLowercxx . . $ EncodeHexLower., /* 0123456789abcdef */ |
| 76 | EncodeAlpha16Uppercxx . . $ EncodeAlpha16Upper., /* ABCDEFGHIJKLMNOP */ |
| 77 | EncodeAlpha16Lowercxx . . $ EncodeAlpha16Lower., /* abcdefghijklmnop */ |
| 78 | EncodeBase64cxx . . $ EncodeBase64. /* 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/ */ |
| 79 | } EncodeAlphabetcxx . . $ EncodeAlphabet#; |
| 80 | |
| 81 | |
| 82 | typedef structcxx . . $ $anonymous_type_1d012c4871d7ce83_1# { |
| 83 | const char *namecxx . . $ $anonymous_type_1d012c4871d7ce83_1#name.; |
| 84 | EncodeAlphabetcxx . . $ EncodeAlphabet# encodingcxx . . $ $anonymous_type_1d012c4871d7ce83_1#encoding.; |
| 85 | HC_Mint_Routinecxx . . $ HC_Mint_Routine# funccxx . . $ $anonymous_type_1d012c4871d7ce83_1#func.; |
| 86 | HC_Mint_Capable_Routinecxx . . $ HC_Mint_Capable_Routine# testcxx . . $ $anonymous_type_1d012c4871d7ce83_1#test.; |
| 87 | } HC_Mintercxx . . $ HC_Minter#; |
| 88 | |
| 89 | #define HC_CPU_SUPPORTS_ALTIVECcxx . . $ `libfastmint.h:89:9`! 0x01 |
| 90 | #define HC_CPU_SUPPORTS_MMXcxx . . $ `libfastmint.h:90:9`! 0x02 |
| 91 | extern int gProcessorSupportFlagscxx . . $ gProcessorSupportFlags.; |
| 92 | |
| 93 | extern const char *encodeAlphabetscxx . . $ encodeAlphabets.[]; |
| 94 | extern const int EncodeBitRatecxx . . $ EncodeBitRate.[]; |
| 95 | |
| 96 | extern void hashcash_select_mintercxx . . $ hashcash_select_minter(d878ad36e69247c7).(); |
| 97 | |
| 98 | /* Portably write a word into a byte array */ |
| 99 | #define PUT_WORDcxx . . $ `libfastmint.h:99:9`!(_dst, _src) { \ |
| 100 | *((unsigned char*)(_dst)+0) = ((_src) >> 24) & 0xFF; \ |
| 101 | *((unsigned char*)(_dst)+1) = ((_src) >> 16) & 0xFF; \ |
| 102 | *((unsigned char*)(_dst)+2) = ((_src) >> 8) & 0xFF; \ |
| 103 | *((unsigned char*)(_dst)+3) = ((_src) ) & 0xFF; \ |
| 104 | } |
| 105 | |
| 106 | /* Portably load bytes into a word */ |
| 107 | #define GET_WORDcxx . . $ `libfastmint.h:107:9`!(_src) ( \ |
| 108 | (*((unsigned char*)(_src)+0) << 24) | \ |
| 109 | (*((unsigned char*)(_src)+1) << 16) | \ |
| 110 | (*((unsigned char*)(_src)+2) << 8) | \ |
| 111 | (*((unsigned char*)(_src)+3) ) ) |
| 112 | |
| 113 | /* Attempt to mint a hashcash token with a given bit-value. |
| 114 | * Will append a random string to token that produces the required preimage, |
| 115 | * then return a pointer to the resultant string in result. Caller must free() |
| 116 | * result buffer after use. |
| 117 | * Returns the number of bits actually minted (may be more or less than requested). |
| 118 | */ |
| 119 | extern double hashcash_fastmintcxx . . $ hashcash_fastmint(687e310f9cbda0fd).(const int bits, const char *token, int small, char **result, hashcash_callbackcxx . . $ hashcash_callback# cb, void* user_arg); |
| 120 | |
| 121 | /* Perform a quick benchmark of the selected minting backend. Returns speed. */ |
| 122 | extern unsigned long hashcash_per_seccxx . . $ hashcash_per_sec(f708dce9a8856c70).(void); |
| 123 | |
| 124 | /* Test and benchmark available hashcash minting backends. Returns the speed |
| 125 | * of the fastest valid routine, and updates fastest_minter as appropriate. |
| 126 | * Uses one or more known solutions to gauge both speed and accuracy. |
| 127 | * Optionally displays status and benchmark results on console. |
| 128 | */ |
| 129 | extern unsigned long hashcash_benchtestcxx . . $ hashcash_benchtest(beccc266862daf71).(int verbose, int core); |
| 130 | |
| 131 | /* Minting backend routines. |
| 132 | * These are in two parts: |
| 133 | * - HC_Mint_Routine is the actual backend. Attempts to produce at least N-bit |
| 134 | * preimage by incrementing the tail section of the block. Block need not |
| 135 | * be initial block, as custom IV is provided, but must be terminal block. |
| 136 | * Tail index points just after last character - ie. to beginning of SHA-1 |
| 137 | * padding - do not overwrite padding. At least 8 characters will be present. |
| 138 | * Will bail out after maxIter attempts, within some reasonable tolerance. |
| 139 | * - HC_Mint_Capable_Routine is a trivial test to see if the current machine |
| 140 | * supports necessary hardware features for the backend. Returns boolean. |
| 141 | */ |
| 142 | |
| 143 | /* Standard ANSI-C 1-pipe "compact" implementation - for use on x86 and other |
| 144 | * register-limited architectures. |
| 145 | */ |
| 146 | extern unsigned long minter_ansi_compact_1cxx . . $ minter_ansi_compact_1(94cd71c2afe1c3a5).(int bits, int* best, unsigned char *block, const uInt32cxx . . $ uInt32# IV[5], int tailIndex, unsigned long maxIter, MINTER_CALLBACK_ARGScxx . . $ hashcash_callback#); |
| 147 | extern int minter_ansi_compact_1_testcxx . . $ minter_ansi_compact_1_test(b126dc7c1de90089).(void); |
| 148 | |
| 149 | /* Standard ANSI-C 1-pipe "Method B" implementation - for use on register-rich architectures. |
| 150 | */ |
| 151 | extern unsigned long minter_ansi_standard_1cxx . . $ minter_ansi_standard_1(94cd71c2afe1c3a5).(int bits, int* best, unsigned char *block, const uInt32cxx . . $ uInt32# IV[5], int tailIndex, unsigned long maxIter, MINTER_CALLBACK_ARGScxx . . $ `libfastmint.h:24:9`!); |
| 152 | extern int minter_ansi_standard_1_testcxx . . $ minter_ansi_standard_1_test(b126dc7c1de90089).(void); |
| 153 | |
| 154 | /* Standard ANSI-C 1-pipe "ultra-compact" implementation - for use on architectures with |
| 155 | * severely limited L1 caches (eg. M68K). |
| 156 | */ |
| 157 | extern unsigned long minter_ansi_ultracompact_1cxx . . $ minter_ansi_ultracompact_1(94cd71c2afe1c3a5).(int bits, int* best, unsigned char *block, const uInt32cxx . . $ uInt32# IV[5], int tailIndex, unsigned long maxIter, MINTER_CALLBACK_ARGScxx . . $ `libfastmint.h:24:9`!); |
| 158 | extern int minter_ansi_ultracompact_1_testcxx . . $ minter_ansi_ultracompact_1_test(b126dc7c1de90089).(void); |
| 159 | |
| 160 | /* Standard ANSI-C 2-pipe "compact" implementation - for use on register-rich architectures. |
| 161 | */ |
| 162 | extern unsigned long minter_ansi_compact_2cxx . . $ minter_ansi_compact_2(94cd71c2afe1c3a5).(int bits, int* best, unsigned char *block, const uInt32cxx . . $ uInt32# IV[5], int tailIndex, unsigned long maxIter, MINTER_CALLBACK_ARGScxx . . $ hashcash_callback#); |
| 163 | extern int minter_ansi_compact_2_testcxx . . $ minter_ansi_compact_2_test(b126dc7c1de90089).(void); |
| 164 | |
| 165 | /* Standard ANSI-C 2-pipe "Method B" implementation - for use on register-rich architectures. |
| 166 | */ |
| 167 | extern unsigned long minter_ansi_standard_2cxx . . $ minter_ansi_standard_2(94cd71c2afe1c3a5).(int bits, int* best, unsigned char *block, const uInt32cxx . . $ uInt32# IV[5], int tailIndex, unsigned long maxIter, MINTER_CALLBACK_ARGScxx . . $ `libfastmint.h:24:9`!); |
| 168 | extern int minter_ansi_standard_2_testcxx . . $ minter_ansi_standard_2_test(b126dc7c1de90089).(void); |
| 169 | |
| 170 | /* PowerPC Altivec 1x4-pipe "Method B" implementation - for use on G4 and higher systems. |
| 171 | */ |
| 172 | extern unsigned long minter_altivec_standard_1cxx . . $ minter_altivec_standard_1(94cd71c2afe1c3a5).(int bits, int* best, unsigned char *block, const uInt32cxx . . $ uInt32# IV[5], int tailIndex, unsigned long maxIter, MINTER_CALLBACK_ARGScxx . . $ hashcash_callback#); |
| 173 | extern int minter_altivec_standard_1_testcxx . . $ minter_altivec_standard_1_test(b126dc7c1de90089).(void); |
| 174 | |
| 175 | /* PowerPC Altivec 2x4-pipe "Method B" implementation - for use on G4 and higher systems. Hand-optimised. |
| 176 | */ |
| 177 | extern unsigned long minter_altivec_standard_2cxx . . $ minter_altivec_standard_2(94cd71c2afe1c3a5).(int bits, int* best, unsigned char *block, const uInt32cxx . . $ uInt32# IV[5], int tailIndex, unsigned long maxIter, MINTER_CALLBACK_ARGScxx . . $ hashcash_callback#); |
| 178 | extern int minter_altivec_standard_2_testcxx . . $ minter_altivec_standard_2_test(b126dc7c1de90089).(void); |
| 179 | |
| 180 | /* PowerPC Altivec 2x4-pipe "compact" implementation - for use on G4 and higher systems. Hand-optimised. |
| 181 | */ |
| 182 | extern unsigned long minter_altivec_compact_2cxx . . $ minter_altivec_compact_2(94cd71c2afe1c3a5).(int bits, int* best, unsigned char *block, const uInt32cxx . . $ uInt32# IV[5], int tailIndex, unsigned long maxIter, MINTER_CALLBACK_ARGScxx . . $ `libfastmint.h:24:9`!); |
| 183 | extern int minter_altivec_compact_2_testcxx . . $ minter_altivec_compact_2_test(b126dc7c1de90089).(void); |
| 184 | |
| 185 | /* AMD64/x86 MMX 1x2-pipe "Method B" implementation - for use on Pentium-MMX/2/3/4, K6-2/3, |
| 186 | * Athlon, Athlon64, Opteron, and compatible systems. Hand-optimised. |
| 187 | */ |
| 188 | extern unsigned long minter_mmx_standard_1cxx . . $ minter_mmx_standard_1(94cd71c2afe1c3a5).(int bits, int* best, unsigned char *block, const uInt32cxx . . $ uInt32# IV[5], int tailIndex, unsigned long maxIter, MINTER_CALLBACK_ARGScxx . . $ `libfastmint.h:24:9`!); |
| 189 | |
| 190 | extern int minter_mmx_standard_1_testcxx . . $ minter_mmx_standard_1_test(b126dc7c1de90089).(void); |
| 191 | |
| 192 | /* AMD64/x86 MMX 1x2-pipe "compact" implementation - for use on Pentium-MMX/2/3/4, K6-2/3, |
| 193 | * Athlon, Athlon64, Opteron, and compatible systems. Hand-optimised. |
| 194 | */ |
| 195 | extern unsigned long minter_mmx_compact_1cxx . . $ minter_mmx_compact_1(94cd71c2afe1c3a5).(int bits, int* best, unsigned char *block, const uInt32cxx . . $ uInt32# IV[5], int tailIndex, unsigned long maxIter, MINTER_CALLBACK_ARGScxx . . $ hashcash_callback#); |
| 196 | extern int minter_mmx_compact_1_testcxx . . $ minter_mmx_compact_1_test(b126dc7c1de90089).(void); |
| 197 | |
| 198 | /* use SHA1 library (integrated or openSSL depending on how compiled) */ |
| 199 | |
| 200 | extern int minter_library_testcxx . . $ minter_library_test(b126dc7c1de90089).(void); |
| 201 | |
| 202 | extern unsigned long minter_librarycxx . . $ minter_library(94cd71c2afe1c3a5).(int bits, int* best, unsigned char *block, const uInt32cxx . . $ uInt32# IV[5], int tailIndex, unsigned long maxIter, MINTER_CALLBACK_ARGScxx . . $ hashcash_callback#); |
| 203 | |
| 204 | |
| 205 | #endif |