From fdc480066929bebfc8c86f4ea1438569f27b57ff Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 11 Jan 2019 06:25:28 +0000 Subject: [PATCH] Build testcrypt on Windows. The bulk of this commit is the changes necessary to make testcrypt compile under Visual Studio. Unfortunately, I've had to remove my fiddly clever uses of C99 variadic macros, because Visual Studio does something unexpected when a variadic macro's expansion puts __VA_ARGS__ in the argument list of a further macro invocation: the commas don't separate further arguments. In other words, if you write #define INNER(x,y,z) some expansion involving x, y and z #define OUTER(...) INNER(__VA_ARGS__) OUTER(1,2,3) then gcc and clang will translate OUTER(1,2,3) into INNER(1,2,3) in the obvious way, and the inner macro will be expanded with x=1, y=2 and z=3. But try this in Visual Studio, and you'll get the macro parameter x expanding to the entire string 1,2,3 and the other two empty (with warnings complaining that INNER didn't get the number of arguments it expected). It's hard to cite chapter and verse of the standard to say which of those is _definitely_ right, though my reading leans towards the gcc/clang behaviour. But I do know I can't depend on it in code that has to compile under both! So I've removed the system that allowed me to declare everything in testcrypt.h as FUNC(ret,fn,arg,arg,arg), and now I have to use a different macro for each arity (FUNC0, FUNC1, FUNC2 etc). Also, the WRAPPED_NAME system is gone (because that too depended on the use of a comma to shift macro arguments along by one), and now I put a custom C wrapper around a function by simply re-#defining that function's own name (and therefore the subsequent code has to be a little more careful to _not_ pass functions' names between several macros before stringifying them). That's all a bit tedious, and commits me to a small amount of ongoing annoyance because now I'll have to add an explicit argument count every time I add something to testcrypt.h. But then again, perhaps it will make the code less incomprehensible to someone trying to understand it! --- Recipe | 5 +- test/testcrypt.py | 7 +- testcrypt.c | 93 ++++++++----- testcrypt.h | 320 ++++++++++++++++++++++----------------------- windows/winmiscs.c | 12 ++ 5 files changed, 237 insertions(+), 200 deletions(-) diff --git a/Recipe b/Recipe index 8d4aae27..a87db32d 100644 --- a/Recipe +++ b/Recipe @@ -380,6 +380,7 @@ osxlaunch : [UT] osxlaunch fuzzterm : [UT] UXTERM CHARSET MISC version uxmisc uxucs fuzzterm time settings + uxstore be_none uxnogtk memory testcrypt : [UT] testcrypt SSHCRYPTO marshal utils memory tree234 +testcrypt : [C] testcrypt SSHCRYPTO marshal utils memory tree234 winmiscs testzlib : [UT] testzlib sshzlib memory uppity : [UT] uxserver SSHSERVER UXMISC uxsignal uxnoise uxgss uxnogtk @@ -391,9 +392,9 @@ uppity : [UT] uxserver SSHSERVER UXMISC uxsignal uxnoise uxgss uxnogtk # in the first place, so that we find out about build breakage early.) !begin vc cleantestprogs: - -del $(BUILDDIR)testbn.exe + -del $(BUILDDIR)testcrypt.exe !end !begin clangcl cleantestprogs: - -rm -f $(BUILDDIR)testbn.exe + -rm -f $(BUILDDIR)testcrypt.exe !end diff --git a/test/testcrypt.py b/test/testcrypt.py index 69706d7a..0ebc5cd7 100644 --- a/test/testcrypt.py +++ b/test/testcrypt.py @@ -187,7 +187,7 @@ class Function(object): def _setup(scope): header_file = os.path.join(putty_srcdir, "testcrypt.h") - prefix, suffix = "FUNC(", ")" + linere = re.compile(r'^FUNC\d+\((.*)\)$') valprefix = "val_" outprefix = "out_" optprefix = "opt_" @@ -206,8 +206,9 @@ def _setup(scope): with open(header_file) as f: for line in iter(f.readline, ""): line = line.rstrip("\r\n").replace(" ", "") - if line.startswith(prefix) and line.endswith(suffix): - words = line[len(prefix):-len(suffix)].split(",") + m = linere.match(line) + if m is not None: + words = m.group(1).split(",") function = words[1] rettypes = [] argtypes = [] diff --git a/testcrypt.c b/testcrypt.c index c6f6f0d9..507253ef 100644 --- a/testcrypt.c +++ b/testcrypt.c @@ -598,19 +598,18 @@ static void random_clear(void) bufchain_clear(&random_data_queue); } -#define WRAP_monty_identity , mp_int *monty_identity_wrapper(MontyContext *mc) { return mp_copy(monty_identity(mc)); } +#define monty_identity monty_identity_wrapper -#define WRAP_monty_modulus , mp_int *monty_modulus_wrapper(MontyContext *mc) { return mp_copy(monty_modulus(mc)); } +#define monty_modulus monty_modulus_wrapper -#define WRAP_ssh_hash_final , strbuf *ssh_hash_final_wrapper(ssh_hash *h) { strbuf *sb = strbuf_new(); @@ -618,16 +617,18 @@ strbuf *ssh_hash_final_wrapper(ssh_hash *h) ssh_hash_final(h, p); return sb; } +#undef ssh_hash_final +#define ssh_hash_final ssh_hash_final_wrapper -#define WRAP_ssh1_cipher_sesskey , void ssh1_cipher_sesskey_wrapper(ssh1_cipher *c, ptrlen key) { if (key.len != 32) fatal_error("ssh1_cipher_sesskey: needs exactly 32 bytes"); ssh1_cipher_sesskey(c, key.ptr); } +#undef ssh1_cipher_sesskey +#define ssh1_cipher_sesskey ssh1_cipher_sesskey_wrapper -#define WRAP_ssh1_cipher_encrypt , strbuf *ssh1_cipher_encrypt_wrapper(ssh1_cipher *c, ptrlen input) { if (input.len % c->vt->blksize) @@ -638,8 +639,9 @@ strbuf *ssh1_cipher_encrypt_wrapper(ssh1_cipher *c, ptrlen input) ssh1_cipher_encrypt(c, sb->u, sb->len); return sb; } +#undef ssh1_cipher_encrypt +#define ssh1_cipher_encrypt ssh1_cipher_encrypt_wrapper -#define WRAP_ssh1_cipher_decrypt , strbuf *ssh1_cipher_decrypt_wrapper(ssh1_cipher *c, ptrlen input) { if (input.len % c->vt->blksize) @@ -650,8 +652,9 @@ strbuf *ssh1_cipher_decrypt_wrapper(ssh1_cipher *c, ptrlen input) ssh1_cipher_decrypt(c, sb->u, sb->len); return sb; } +#undef ssh1_cipher_decrypt +#define ssh1_cipher_decrypt ssh1_cipher_decrypt_wrapper -#define WRAP_ssh2_cipher_setiv , void ssh2_cipher_setiv_wrapper(ssh2_cipher *c, ptrlen key) { if (key.len != ssh2_cipher_alg(c)->blksize) @@ -659,8 +662,9 @@ void ssh2_cipher_setiv_wrapper(ssh2_cipher *c, ptrlen key) ssh2_cipher_alg(c)->blksize); ssh2_cipher_setiv(c, key.ptr); } +#undef ssh2_cipher_setiv +#define ssh2_cipher_setiv ssh2_cipher_setiv_wrapper -#define WRAP_ssh2_cipher_setkey , void ssh2_cipher_setkey_wrapper(ssh2_cipher *c, ptrlen key) { if (key.len != ssh2_cipher_alg(c)->padded_keybytes) @@ -668,8 +672,9 @@ void ssh2_cipher_setkey_wrapper(ssh2_cipher *c, ptrlen key) ssh2_cipher_alg(c)->padded_keybytes); ssh2_cipher_setkey(c, key.ptr); } +#undef ssh2_cipher_setkey +#define ssh2_cipher_setkey ssh2_cipher_setkey_wrapper -#define WRAP_ssh2_cipher_encrypt , strbuf *ssh2_cipher_encrypt_wrapper(ssh2_cipher *c, ptrlen input) { if (input.len % ssh2_cipher_alg(c)->blksize) @@ -680,8 +685,9 @@ strbuf *ssh2_cipher_encrypt_wrapper(ssh2_cipher *c, ptrlen input) ssh2_cipher_encrypt(c, sb->u, sb->len); return sb; } +#undef ssh2_cipher_encrypt +#define ssh2_cipher_encrypt ssh2_cipher_encrypt_wrapper -#define WRAP_ssh2_cipher_decrypt , strbuf *ssh2_cipher_decrypt_wrapper(ssh2_cipher *c, ptrlen input) { if (input.len % ssh2_cipher_alg(c)->blksize) @@ -692,8 +698,9 @@ strbuf *ssh2_cipher_decrypt_wrapper(ssh2_cipher *c, ptrlen input) ssh2_cipher_decrypt(c, sb->u, sb->len); return sb; } +#undef ssh2_cipher_decrypt +#define ssh2_cipher_decrypt ssh2_cipher_decrypt_wrapper -#define WRAP_ssh2_cipher_encrypt_length , strbuf *ssh2_cipher_encrypt_length_wrapper(ssh2_cipher *c, ptrlen input, unsigned long seq) { @@ -704,8 +711,9 @@ strbuf *ssh2_cipher_encrypt_length_wrapper(ssh2_cipher *c, ptrlen input, ssh2_cipher_encrypt_length(c, sb->u, sb->len, seq); return sb; } +#undef ssh2_cipher_encrypt_length +#define ssh2_cipher_encrypt_length ssh2_cipher_encrypt_length_wrapper -#define WRAP_ssh2_cipher_decrypt_length , strbuf *ssh2_cipher_decrypt_length_wrapper(ssh2_cipher *c, ptrlen input, unsigned long seq) { @@ -716,8 +724,9 @@ strbuf *ssh2_cipher_decrypt_length_wrapper(ssh2_cipher *c, ptrlen input, ssh2_cipher_decrypt_length(c, sb->u, sb->len, seq); return sb; } +#undef ssh2_cipher_decrypt_length +#define ssh2_cipher_decrypt_length ssh2_cipher_decrypt_length_wrapper -#define WRAP_ssh2_mac_genresult , strbuf *ssh2_mac_genresult_wrapper(ssh2_mac *m) { strbuf *sb = strbuf_new(); @@ -725,12 +734,14 @@ strbuf *ssh2_mac_genresult_wrapper(ssh2_mac *m) ssh2_mac_genresult(m, u); return sb; } +#undef ssh2_mac_genresult +#define ssh2_mac_genresult ssh2_mac_genresult_wrapper -#define WRAP_dh_validate_f , bool dh_validate_f_wrapper(dh_ctx *dh, mp_int *f) { return dh_validate_f(dh, f) == NULL; } +#define dh_validate_f dh_validate_f_wrapper void ssh_hash_update(ssh_hash *h, ptrlen pl) { @@ -749,7 +760,6 @@ static RSAKey *rsa_new(void) return rsa; } -#define WRAP_rsa_ssh1_encrypt , strbuf *rsa_ssh1_encrypt_wrapper(ptrlen input, RSAKey *key) { /* Fold the boolean return value in C into the string return value @@ -760,8 +770,8 @@ strbuf *rsa_ssh1_encrypt_wrapper(ptrlen input, RSAKey *key) sb->len = 0; return sb; } +#define rsa_ssh1_encrypt rsa_ssh1_encrypt_wrapper -#define WRAP_rsa_ssh1_decrypt_pkcs1 , strbuf *rsa_ssh1_decrypt_pkcs1_wrapper(mp_int *input, RSAKey *key) { /* Again, return "" on failure */ @@ -770,8 +780,8 @@ strbuf *rsa_ssh1_decrypt_pkcs1_wrapper(mp_int *input, RSAKey *key) sb->len = 0; return sb; } +#define rsa_ssh1_decrypt_pkcs1 rsa_ssh1_decrypt_pkcs1_wrapper -#define WRAP_des_encrypt_xdmauth , strbuf *des_encrypt_xdmauth_wrapper(ptrlen key, ptrlen data) { if (key.len != 7) @@ -783,8 +793,8 @@ strbuf *des_encrypt_xdmauth_wrapper(ptrlen key, ptrlen data) des_encrypt_xdmauth(key.ptr, sb->u, sb->len); return sb; } +#define des_encrypt_xdmauth des_encrypt_xdmauth_wrapper -#define WRAP_des_decrypt_xdmauth , strbuf *des_decrypt_xdmauth_wrapper(ptrlen key, ptrlen data) { if (key.len != 7) @@ -796,6 +806,7 @@ strbuf *des_decrypt_xdmauth_wrapper(ptrlen key, ptrlen data) des_decrypt_xdmauth(key.ptr, sb->u, sb->len); return sb; } +#define des_decrypt_xdmauth des_decrypt_xdmauth_wrapper #define return_void(out, expression) (expression) @@ -832,26 +843,22 @@ typedef const ssh_kex *TD_dh_group; typedef const ssh_kex *TD_ecdh_alg; typedef RsaSsh1Order TD_rsaorder; -#define WRAPPED_NAME_INNER(a, b, ...) b -#define WRAPPED_NAME_OUTER(...) WRAPPED_NAME_INNER(__VA_ARGS__) -#define WRAPPED_NAME(func) WRAPPED_NAME_OUTER(WRAP_##func func##_wrapper, func) - #define FUNC0(rettype, function) \ static void handle_##function(BinarySource *in, strbuf *out) { \ - return_##rettype(out, WRAPPED_NAME(function)()); \ + return_##rettype(out, function()); \ } #define FUNC1(rettype, function, type1) \ static void handle_##function(BinarySource *in, strbuf *out) { \ TD_##type1 arg1 = get_##type1(in); \ - return_##rettype(out, WRAPPED_NAME(function)(arg1)); \ + return_##rettype(out, function(arg1)); \ } #define FUNC2(rettype, function, type1, type2) \ static void handle_##function(BinarySource *in, strbuf *out) { \ TD_##type1 arg1 = get_##type1(in); \ TD_##type2 arg2 = get_##type2(in); \ - return_##rettype(out, WRAPPED_NAME(function)(arg1, arg2)); \ + return_##rettype(out, function(arg1, arg2)); \ } #define FUNC3(rettype, function, type1, type2, type3) \ @@ -859,7 +866,7 @@ typedef RsaSsh1Order TD_rsaorder; TD_##type1 arg1 = get_##type1(in); \ TD_##type2 arg2 = get_##type2(in); \ TD_##type3 arg3 = get_##type3(in); \ - return_##rettype(out, WRAPPED_NAME(function)(arg1, arg2, arg3)); \ + return_##rettype(out, function(arg1, arg2, arg3)); \ } #define FUNC4(rettype, function, type1, type2, type3, type4) \ @@ -868,16 +875,16 @@ typedef RsaSsh1Order TD_rsaorder; TD_##type2 arg2 = get_##type2(in); \ TD_##type3 arg3 = get_##type3(in); \ TD_##type4 arg4 = get_##type4(in); \ - return_##rettype(out, WRAPPED_NAME(function)(arg1, arg2, arg3, arg4)); \ + return_##rettype(out, function(arg1, arg2, arg3, arg4)); \ } -#define FUNC_SELECT_OUTER(...) \ - FUNC_SELECT_INNER(__VA_ARGS__,FUNC4,FUNC3,FUNC2,FUNC1,FUNC0)(__VA_ARGS__) -#define FUNC_SELECT_INNER(r,f,a1,a2,a3,a4,m,...) m - -#define FUNC FUNC_SELECT_OUTER #include "testcrypt.h" -#undef FUNC + +#undef FUNC4 +#undef FUNC3 +#undef FUNC2 +#undef FUNC1 +#undef FUNC0 static void process_line(BinarySource *in, strbuf *out) { @@ -895,9 +902,25 @@ static void process_line(BinarySource *in, strbuf *out) DISPATCH_COMMAND(mp_literal); DISPATCH_COMMAND(mp_dump); -#define FUNC(rettype, function, ...) DISPATCH_COMMAND(function); +#define FUNC(rettype, function, ...) \ + if (ptrlen_eq_string(id, #function)) { \ + handle_##function(in, out); \ + return; \ + } + +#define FUNC0 FUNC +#define FUNC1 FUNC +#define FUNC2 FUNC +#define FUNC3 FUNC +#define FUNC4 FUNC + #include "testcrypt.h" -#undef FUNC + +#undef FUNC4 +#undef FUNC3 +#undef FUNC2 +#undef FUNC1 +#undef FUNC0 fatal_error("command '%.*s': unrecognised", PTRLEN_PRINTF(id)); } diff --git a/testcrypt.h b/testcrypt.h index 74220e61..db5c83e8 100644 --- a/testcrypt.h +++ b/testcrypt.h @@ -1,112 +1,112 @@ /* * mpint.h functions. */ -FUNC(val_mpint, mp_new, uint) -FUNC(void, mp_clear, val_mpint) -FUNC(val_mpint, mp_from_bytes_le, val_string_ptrlen) -FUNC(val_mpint, mp_from_bytes_be, val_string_ptrlen) -FUNC(val_mpint, mp_from_integer, uint) -FUNC(val_mpint, mp_from_decimal_pl, val_string_ptrlen) -FUNC(val_mpint, mp_from_decimal, val_string_asciz) -FUNC(val_mpint, mp_from_hex_pl, val_string_ptrlen) -FUNC(val_mpint, mp_from_hex, val_string_asciz) -FUNC(val_mpint, mp_copy, val_mpint) -FUNC(val_mpint, mp_power_2, uint) -FUNC(uint, mp_get_byte, val_mpint, uint) -FUNC(uint, mp_get_bit, val_mpint, uint) -FUNC(void, mp_set_bit, val_mpint, uint, uint) -FUNC(uint, mp_max_bytes, val_mpint) -FUNC(uint, mp_max_bits, val_mpint) -FUNC(uint, mp_get_nbits, val_mpint) -FUNC(val_string_asciz, mp_get_decimal, val_mpint) -FUNC(val_string_asciz, mp_get_hex, val_mpint) -FUNC(val_string_asciz, mp_get_hex_uppercase, val_mpint) -FUNC(uint, mp_cmp_hs, val_mpint, val_mpint) -FUNC(uint, mp_cmp_eq, val_mpint, val_mpint) -FUNC(uint, mp_hs_integer, val_mpint, uint) -FUNC(uint, mp_eq_integer, val_mpint, uint) -FUNC(void, mp_min_into, val_mpint, val_mpint, val_mpint) -FUNC(val_mpint, mp_min, val_mpint, val_mpint) -FUNC(void, mp_copy_into, val_mpint, val_mpint) -FUNC(void, mp_select_into, val_mpint, val_mpint, val_mpint, uint) -FUNC(void, mp_add_into, val_mpint, val_mpint, val_mpint) -FUNC(void, mp_sub_into, val_mpint, val_mpint, val_mpint) -FUNC(void, mp_mul_into, val_mpint, val_mpint, val_mpint) -FUNC(val_mpint, mp_add, val_mpint, val_mpint) -FUNC(val_mpint, mp_sub, val_mpint, val_mpint) -FUNC(val_mpint, mp_mul, val_mpint, val_mpint) -FUNC(void, mp_add_integer_into, val_mpint, val_mpint, uint) -FUNC(void, mp_sub_integer_into, val_mpint, val_mpint, uint) -FUNC(void, mp_mul_integer_into, val_mpint, val_mpint, uint) -FUNC(void, mp_cond_add_into, val_mpint, val_mpint, val_mpint, uint) -FUNC(void, mp_cond_sub_into, val_mpint, val_mpint, val_mpint, uint) -FUNC(void, mp_cond_swap, val_mpint, val_mpint, uint) -FUNC(void, mp_cond_clear, val_mpint, uint) -FUNC(void, mp_divmod_into, val_mpint, val_mpint, val_mpint, val_mpint) -FUNC(val_mpint, mp_div, val_mpint, val_mpint) -FUNC(val_mpint, mp_mod, val_mpint, val_mpint) -FUNC(void, mp_reduce_mod_2to, val_mpint, uint) -FUNC(val_mpint, mp_invert_mod_2to, val_mpint, uint) -FUNC(val_mpint, mp_invert, val_mpint, val_mpint) -FUNC(val_modsqrt, modsqrt_new, val_mpint, val_mpint) +FUNC1(val_mpint, mp_new, uint) +FUNC1(void, mp_clear, val_mpint) +FUNC1(val_mpint, mp_from_bytes_le, val_string_ptrlen) +FUNC1(val_mpint, mp_from_bytes_be, val_string_ptrlen) +FUNC1(val_mpint, mp_from_integer, uint) +FUNC1(val_mpint, mp_from_decimal_pl, val_string_ptrlen) +FUNC1(val_mpint, mp_from_decimal, val_string_asciz) +FUNC1(val_mpint, mp_from_hex_pl, val_string_ptrlen) +FUNC1(val_mpint, mp_from_hex, val_string_asciz) +FUNC1(val_mpint, mp_copy, val_mpint) +FUNC1(val_mpint, mp_power_2, uint) +FUNC2(uint, mp_get_byte, val_mpint, uint) +FUNC2(uint, mp_get_bit, val_mpint, uint) +FUNC3(void, mp_set_bit, val_mpint, uint, uint) +FUNC1(uint, mp_max_bytes, val_mpint) +FUNC1(uint, mp_max_bits, val_mpint) +FUNC1(uint, mp_get_nbits, val_mpint) +FUNC1(val_string_asciz, mp_get_decimal, val_mpint) +FUNC1(val_string_asciz, mp_get_hex, val_mpint) +FUNC1(val_string_asciz, mp_get_hex_uppercase, val_mpint) +FUNC2(uint, mp_cmp_hs, val_mpint, val_mpint) +FUNC2(uint, mp_cmp_eq, val_mpint, val_mpint) +FUNC2(uint, mp_hs_integer, val_mpint, uint) +FUNC2(uint, mp_eq_integer, val_mpint, uint) +FUNC3(void, mp_min_into, val_mpint, val_mpint, val_mpint) +FUNC2(val_mpint, mp_min, val_mpint, val_mpint) +FUNC2(void, mp_copy_into, val_mpint, val_mpint) +FUNC4(void, mp_select_into, val_mpint, val_mpint, val_mpint, uint) +FUNC3(void, mp_add_into, val_mpint, val_mpint, val_mpint) +FUNC3(void, mp_sub_into, val_mpint, val_mpint, val_mpint) +FUNC3(void, mp_mul_into, val_mpint, val_mpint, val_mpint) +FUNC2(val_mpint, mp_add, val_mpint, val_mpint) +FUNC2(val_mpint, mp_sub, val_mpint, val_mpint) +FUNC2(val_mpint, mp_mul, val_mpint, val_mpint) +FUNC3(void, mp_add_integer_into, val_mpint, val_mpint, uint) +FUNC3(void, mp_sub_integer_into, val_mpint, val_mpint, uint) +FUNC3(void, mp_mul_integer_into, val_mpint, val_mpint, uint) +FUNC4(void, mp_cond_add_into, val_mpint, val_mpint, val_mpint, uint) +FUNC4(void, mp_cond_sub_into, val_mpint, val_mpint, val_mpint, uint) +FUNC3(void, mp_cond_swap, val_mpint, val_mpint, uint) +FUNC2(void, mp_cond_clear, val_mpint, uint) +FUNC4(void, mp_divmod_into, val_mpint, val_mpint, val_mpint, val_mpint) +FUNC2(val_mpint, mp_div, val_mpint, val_mpint) +FUNC2(val_mpint, mp_mod, val_mpint, val_mpint) +FUNC2(void, mp_reduce_mod_2to, val_mpint, uint) +FUNC2(val_mpint, mp_invert_mod_2to, val_mpint, uint) +FUNC2(val_mpint, mp_invert, val_mpint, val_mpint) +FUNC2(val_modsqrt, modsqrt_new, val_mpint, val_mpint) /* The modsqrt functions' 'success' pointer becomes a second return value */ -FUNC(val_mpint, mp_modsqrt, val_modsqrt, val_mpint, out_uint) -FUNC(val_monty, monty_new, val_mpint) -FUNC(val_mpint, monty_modulus, val_monty) -FUNC(val_mpint, monty_identity, val_monty) -FUNC(void, monty_import_into, val_monty, val_mpint, val_mpint) -FUNC(val_mpint, monty_import, val_monty, val_mpint) -FUNC(void, monty_export_into, val_monty, val_mpint, val_mpint) -FUNC(val_mpint, monty_export, val_monty, val_mpint) -FUNC(void, monty_mul_into, val_monty, val_mpint, val_mpint, val_mpint) -FUNC(val_mpint, monty_add, val_monty, val_mpint, val_mpint) -FUNC(val_mpint, monty_sub, val_monty, val_mpint, val_mpint) -FUNC(val_mpint, monty_mul, val_monty, val_mpint, val_mpint) -FUNC(val_mpint, monty_pow, val_monty, val_mpint, val_mpint) -FUNC(val_mpint, monty_invert, val_monty, val_mpint) -FUNC(val_mpint, monty_modsqrt, val_modsqrt, val_mpint, out_uint) -FUNC(val_mpint, mp_modpow, val_mpint, val_mpint, val_mpint) -FUNC(val_mpint, mp_modmul, val_mpint, val_mpint, val_mpint) -FUNC(val_mpint, mp_modadd, val_mpint, val_mpint, val_mpint) -FUNC(val_mpint, mp_modsub, val_mpint, val_mpint, val_mpint) -FUNC(val_mpint, mp_rshift_safe, val_mpint, uint) -FUNC(void, mp_lshift_fixed_into, val_mpint, val_mpint, uint) -FUNC(void, mp_rshift_fixed_into, val_mpint, val_mpint, uint) -FUNC(val_mpint, mp_rshift_fixed, val_mpint, uint) -FUNC(val_mpint, mp_random_bits, uint) -FUNC(val_mpint, mp_random_in_range, val_mpint, val_mpint) +FUNC3(val_mpint, mp_modsqrt, val_modsqrt, val_mpint, out_uint) +FUNC1(val_monty, monty_new, val_mpint) +FUNC1(val_mpint, monty_modulus, val_monty) +FUNC1(val_mpint, monty_identity, val_monty) +FUNC3(void, monty_import_into, val_monty, val_mpint, val_mpint) +FUNC2(val_mpint, monty_import, val_monty, val_mpint) +FUNC3(void, monty_export_into, val_monty, val_mpint, val_mpint) +FUNC2(val_mpint, monty_export, val_monty, val_mpint) +FUNC4(void, monty_mul_into, val_monty, val_mpint, val_mpint, val_mpint) +FUNC3(val_mpint, monty_add, val_monty, val_mpint, val_mpint) +FUNC3(val_mpint, monty_sub, val_monty, val_mpint, val_mpint) +FUNC3(val_mpint, monty_mul, val_monty, val_mpint, val_mpint) +FUNC3(val_mpint, monty_pow, val_monty, val_mpint, val_mpint) +FUNC2(val_mpint, monty_invert, val_monty, val_mpint) +FUNC3(val_mpint, monty_modsqrt, val_modsqrt, val_mpint, out_uint) +FUNC3(val_mpint, mp_modpow, val_mpint, val_mpint, val_mpint) +FUNC3(val_mpint, mp_modmul, val_mpint, val_mpint, val_mpint) +FUNC3(val_mpint, mp_modadd, val_mpint, val_mpint, val_mpint) +FUNC3(val_mpint, mp_modsub, val_mpint, val_mpint, val_mpint) +FUNC2(val_mpint, mp_rshift_safe, val_mpint, uint) +FUNC3(void, mp_lshift_fixed_into, val_mpint, val_mpint, uint) +FUNC3(void, mp_rshift_fixed_into, val_mpint, val_mpint, uint) +FUNC2(val_mpint, mp_rshift_fixed, val_mpint, uint) +FUNC1(val_mpint, mp_random_bits, uint) +FUNC2(val_mpint, mp_random_in_range, val_mpint, val_mpint) /* * ecc.h functions. */ -FUNC(val_wcurve, ecc_weierstrass_curve, val_mpint, val_mpint, val_mpint, opt_val_mpint) -FUNC(val_wpoint, ecc_weierstrass_point_new_identity, val_wcurve) -FUNC(val_wpoint, ecc_weierstrass_point_new, val_wcurve, val_mpint, val_mpint) -FUNC(val_wpoint, ecc_weierstrass_point_new_from_x, val_wcurve, val_mpint, uint) -FUNC(val_wpoint, ecc_weierstrass_point_copy, val_wpoint) -FUNC(uint, ecc_weierstrass_point_valid, val_wpoint) -FUNC(val_wpoint, ecc_weierstrass_add_general, val_wpoint, val_wpoint) -FUNC(val_wpoint, ecc_weierstrass_add, val_wpoint, val_wpoint) -FUNC(val_wpoint, ecc_weierstrass_double, val_wpoint) -FUNC(val_wpoint, ecc_weierstrass_multiply, val_wpoint, val_mpint) -FUNC(uint, ecc_weierstrass_is_identity, val_wpoint) +FUNC4(val_wcurve, ecc_weierstrass_curve, val_mpint, val_mpint, val_mpint, opt_val_mpint) +FUNC1(val_wpoint, ecc_weierstrass_point_new_identity, val_wcurve) +FUNC3(val_wpoint, ecc_weierstrass_point_new, val_wcurve, val_mpint, val_mpint) +FUNC3(val_wpoint, ecc_weierstrass_point_new_from_x, val_wcurve, val_mpint, uint) +FUNC1(val_wpoint, ecc_weierstrass_point_copy, val_wpoint) +FUNC1(uint, ecc_weierstrass_point_valid, val_wpoint) +FUNC2(val_wpoint, ecc_weierstrass_add_general, val_wpoint, val_wpoint) +FUNC2(val_wpoint, ecc_weierstrass_add, val_wpoint, val_wpoint) +FUNC1(val_wpoint, ecc_weierstrass_double, val_wpoint) +FUNC2(val_wpoint, ecc_weierstrass_multiply, val_wpoint, val_mpint) +FUNC1(uint, ecc_weierstrass_is_identity, val_wpoint) /* The output pointers in get_affine all become extra output values */ -FUNC(void, ecc_weierstrass_get_affine, val_wpoint, out_val_mpint, out_val_mpint) -FUNC(val_mcurve, ecc_montgomery_curve, val_mpint, val_mpint, val_mpint) -FUNC(val_mpoint, ecc_montgomery_point_new, val_mcurve, val_mpint) -FUNC(val_mpoint, ecc_montgomery_point_copy, val_mpoint) -FUNC(val_mpoint, ecc_montgomery_diff_add, val_mpoint, val_mpoint, val_mpoint) -FUNC(val_mpoint, ecc_montgomery_double, val_mpoint) -FUNC(val_mpoint, ecc_montgomery_multiply, val_mpoint, val_mpint) -FUNC(void, ecc_montgomery_get_affine, val_mpoint, out_val_mpint) -FUNC(val_ecurve, ecc_edwards_curve, val_mpint, val_mpint, val_mpint, opt_val_mpint) -FUNC(val_epoint, ecc_edwards_point_new, val_ecurve, val_mpint, val_mpint) -FUNC(val_epoint, ecc_edwards_point_new_from_y, val_ecurve, val_mpint, uint) -FUNC(val_epoint, ecc_edwards_point_copy, val_epoint) -FUNC(val_epoint, ecc_edwards_add, val_epoint, val_epoint) -FUNC(val_epoint, ecc_edwards_multiply, val_epoint, val_mpint) -FUNC(uint, ecc_edwards_eq, val_epoint, val_epoint) -FUNC(void, ecc_edwards_get_affine, val_epoint, out_val_mpint, out_val_mpint) +FUNC3(void, ecc_weierstrass_get_affine, val_wpoint, out_val_mpint, out_val_mpint) +FUNC3(val_mcurve, ecc_montgomery_curve, val_mpint, val_mpint, val_mpint) +FUNC2(val_mpoint, ecc_montgomery_point_new, val_mcurve, val_mpint) +FUNC1(val_mpoint, ecc_montgomery_point_copy, val_mpoint) +FUNC3(val_mpoint, ecc_montgomery_diff_add, val_mpoint, val_mpoint, val_mpoint) +FUNC1(val_mpoint, ecc_montgomery_double, val_mpoint) +FUNC2(val_mpoint, ecc_montgomery_multiply, val_mpoint, val_mpint) +FUNC2(void, ecc_montgomery_get_affine, val_mpoint, out_val_mpint) +FUNC4(val_ecurve, ecc_edwards_curve, val_mpint, val_mpint, val_mpint, opt_val_mpint) +FUNC3(val_epoint, ecc_edwards_point_new, val_ecurve, val_mpint, val_mpint) +FUNC3(val_epoint, ecc_edwards_point_new_from_y, val_ecurve, val_mpint, uint) +FUNC1(val_epoint, ecc_edwards_point_copy, val_epoint) +FUNC2(val_epoint, ecc_edwards_add, val_epoint, val_epoint) +FUNC2(val_epoint, ecc_edwards_multiply, val_epoint, val_mpint) +FUNC2(uint, ecc_edwards_eq, val_epoint, val_epoint) +FUNC3(void, ecc_edwards_get_affine, val_epoint, out_val_mpint, out_val_mpint) /* * The ssh_hash abstraction. Note the 'consumed', indicating that @@ -115,21 +115,21 @@ FUNC(void, ecc_edwards_get_affine, val_epoint, out_val_mpint, out_val_mpint) * ssh_hash_update is an invention of testcrypt, handled in the real C * API by the hash object also functioning as a BinarySink. */ -FUNC(val_hash, ssh_hash_new, hashalg) -FUNC(val_hash, ssh_hash_copy, val_hash) -FUNC(val_string, ssh_hash_final, consumed_val_hash) -FUNC(void, ssh_hash_update, val_hash, val_string_ptrlen) +FUNC1(val_hash, ssh_hash_new, hashalg) +FUNC1(val_hash, ssh_hash_copy, val_hash) +FUNC1(val_string, ssh_hash_final, consumed_val_hash) +FUNC2(void, ssh_hash_update, val_hash, val_string_ptrlen) /* * The ssh2_mac abstraction. Note the optional ssh2_cipher parameter * to ssh2_mac_new. Also, again, I've invented an ssh2_mac_update so * you can put data into the MAC. */ -FUNC(val_mac, ssh2_mac_new, macalg, opt_val_ssh2cipher) -FUNC(void, ssh2_mac_setkey, val_mac, val_string_ptrlen) -FUNC(void, ssh2_mac_start, val_mac) -FUNC(void, ssh2_mac_update, val_mac, val_string_ptrlen) -FUNC(val_string, ssh2_mac_genresult, val_mac) +FUNC2(val_mac, ssh2_mac_new, macalg, opt_val_ssh2cipher) +FUNC2(void, ssh2_mac_setkey, val_mac, val_string_ptrlen) +FUNC1(void, ssh2_mac_start, val_mac) +FUNC2(void, ssh2_mac_update, val_mac, val_string_ptrlen) +FUNC1(val_string, ssh2_mac_genresult, val_mac) /* * The ssh_key abstraction. All the uses of BinarySink and @@ -138,91 +138,91 @@ FUNC(val_string, ssh2_mac_genresult, val_mac) * all the functions that output key and signature blobs do it by * returning a string. */ -FUNC(val_key, ssh_key_new_pub, keyalg, val_string_ptrlen) -FUNC(val_key, ssh_key_new_priv, keyalg, val_string_ptrlen, val_string_ptrlen) -FUNC(val_key, ssh_key_new_priv_openssh, keyalg, val_string_binarysource) -FUNC(void, ssh_key_sign, val_key, val_string_ptrlen, uint, out_val_string_binarysink) -FUNC(boolean, ssh_key_verify, val_key, val_string_ptrlen, val_string_ptrlen) -FUNC(void, ssh_key_public_blob, val_key, out_val_string_binarysink) -FUNC(void, ssh_key_private_blob, val_key, out_val_string_binarysink) -FUNC(void, ssh_key_openssh_blob, val_key, out_val_string_binarysink) -FUNC(val_string_asciz, ssh_key_cache_str, val_key) -FUNC(uint, ssh_key_public_bits, keyalg, val_string_ptrlen) +FUNC2(val_key, ssh_key_new_pub, keyalg, val_string_ptrlen) +FUNC3(val_key, ssh_key_new_priv, keyalg, val_string_ptrlen, val_string_ptrlen) +FUNC2(val_key, ssh_key_new_priv_openssh, keyalg, val_string_binarysource) +FUNC4(void, ssh_key_sign, val_key, val_string_ptrlen, uint, out_val_string_binarysink) +FUNC3(boolean, ssh_key_verify, val_key, val_string_ptrlen, val_string_ptrlen) +FUNC2(void, ssh_key_public_blob, val_key, out_val_string_binarysink) +FUNC2(void, ssh_key_private_blob, val_key, out_val_string_binarysink) +FUNC2(void, ssh_key_openssh_blob, val_key, out_val_string_binarysink) +FUNC1(val_string_asciz, ssh_key_cache_str, val_key) +FUNC2(uint, ssh_key_public_bits, keyalg, val_string_ptrlen) /* * The ssh1_cipher abstraction. The in-place encrypt and decrypt * functions are wrapped to replace them with a pair that take one * string and return a separate string. */ -FUNC(val_ssh1cipher, ssh1_cipher_new, ssh1_cipheralg) -FUNC(void, ssh1_cipher_sesskey, val_ssh1cipher, val_string_ptrlen) -FUNC(val_string, ssh1_cipher_encrypt, val_ssh1cipher, val_string_ptrlen) -FUNC(val_string, ssh1_cipher_decrypt, val_ssh1cipher, val_string_ptrlen) +FUNC1(val_ssh1cipher, ssh1_cipher_new, ssh1_cipheralg) +FUNC2(void, ssh1_cipher_sesskey, val_ssh1cipher, val_string_ptrlen) +FUNC2(val_string, ssh1_cipher_encrypt, val_ssh1cipher, val_string_ptrlen) +FUNC2(val_string, ssh1_cipher_decrypt, val_ssh1cipher, val_string_ptrlen) /* * The ssh2_cipher abstraction, with similar modifications. */ -FUNC(val_ssh2cipher, ssh2_cipher_new, ssh2_cipheralg) -FUNC(void, ssh2_cipher_setiv, val_ssh2cipher, val_string_ptrlen) -FUNC(void, ssh2_cipher_setkey, val_ssh2cipher, val_string_ptrlen) -FUNC(val_string, ssh2_cipher_encrypt, val_ssh2cipher, val_string_ptrlen) -FUNC(val_string, ssh2_cipher_decrypt, val_ssh2cipher, val_string_ptrlen) -FUNC(val_string, ssh2_cipher_encrypt_length, val_ssh2cipher, val_string_ptrlen, uint) -FUNC(val_string, ssh2_cipher_decrypt_length, val_ssh2cipher, val_string_ptrlen, uint) +FUNC1(val_ssh2cipher, ssh2_cipher_new, ssh2_cipheralg) +FUNC2(void, ssh2_cipher_setiv, val_ssh2cipher, val_string_ptrlen) +FUNC2(void, ssh2_cipher_setkey, val_ssh2cipher, val_string_ptrlen) +FUNC2(val_string, ssh2_cipher_encrypt, val_ssh2cipher, val_string_ptrlen) +FUNC2(val_string, ssh2_cipher_decrypt, val_ssh2cipher, val_string_ptrlen) +FUNC3(val_string, ssh2_cipher_encrypt_length, val_ssh2cipher, val_string_ptrlen, uint) +FUNC3(val_string, ssh2_cipher_decrypt_length, val_ssh2cipher, val_string_ptrlen, uint) /* * Integer Diffie-Hellman. */ -FUNC(val_dh, dh_setup_group, dh_group) -FUNC(val_dh, dh_setup_gex, val_mpint, val_mpint) -FUNC(uint, dh_modulus_bit_size, val_dh) -FUNC(val_mpint, dh_create_e, val_dh, uint) -FUNC(boolean, dh_validate_f, val_dh, val_mpint) -FUNC(val_mpint, dh_find_K, val_dh, val_mpint) +FUNC1(val_dh, dh_setup_group, dh_group) +FUNC2(val_dh, dh_setup_gex, val_mpint, val_mpint) +FUNC1(uint, dh_modulus_bit_size, val_dh) +FUNC2(val_mpint, dh_create_e, val_dh, uint) +FUNC2(boolean, dh_validate_f, val_dh, val_mpint) +FUNC2(val_mpint, dh_find_K, val_dh, val_mpint) /* * Elliptic-curve Diffie-Hellman. */ -FUNC(val_ecdh, ssh_ecdhkex_newkey, ecdh_alg) -FUNC(void, ssh_ecdhkex_getpublic, val_ecdh, out_val_string_binarysink) -FUNC(val_mpint, ssh_ecdhkex_getkey, val_ecdh, val_string_ptrlen) +FUNC1(val_ecdh, ssh_ecdhkex_newkey, ecdh_alg) +FUNC2(void, ssh_ecdhkex_getpublic, val_ecdh, out_val_string_binarysink) +FUNC2(val_mpint, ssh_ecdhkex_getkey, val_ecdh, val_string_ptrlen) /* * RSA key exchange. */ -FUNC(val_rsakex, ssh_rsakex_newkey, val_string_ptrlen) -FUNC(uint, ssh_rsakex_klen, val_rsakex) -FUNC(val_string, ssh_rsakex_encrypt, val_rsakex, hashalg, val_string_ptrlen) -FUNC(val_mpint, ssh_rsakex_decrypt, val_rsakex, hashalg, val_string_ptrlen) +FUNC1(val_rsakex, ssh_rsakex_newkey, val_string_ptrlen) +FUNC1(uint, ssh_rsakex_klen, val_rsakex) +FUNC3(val_string, ssh_rsakex_encrypt, val_rsakex, hashalg, val_string_ptrlen) +FUNC3(val_mpint, ssh_rsakex_decrypt, val_rsakex, hashalg, val_string_ptrlen) /* * Bare RSA keys as used in SSH-1. The construction API functions * write into an existing RSAKey object, so I've invented an 'rsa_new' * function to make one in the first place. */ -FUNC(val_rsa, rsa_new) -FUNC(void, get_rsa_ssh1_pub, val_string_binarysource, val_rsa, rsaorder) -FUNC(void, get_rsa_ssh1_priv, val_string_binarysource, val_rsa) -FUNC(val_string, rsa_ssh1_encrypt, val_string_ptrlen, val_rsa) -FUNC(val_mpint, rsa_ssh1_decrypt, val_mpint, val_rsa) -FUNC(val_string, rsa_ssh1_decrypt_pkcs1, val_mpint, val_rsa) -FUNC(val_string_asciz, rsastr_fmt, val_rsa) -FUNC(val_string_asciz, rsa_ssh1_fingerprint, val_rsa) -FUNC(void, rsa_ssh1_public_blob, out_val_string_binarysink, val_rsa, rsaorder) -FUNC(int, rsa_ssh1_public_blob_len, val_string_ptrlen) +FUNC0(val_rsa, rsa_new) +FUNC3(void, get_rsa_ssh1_pub, val_string_binarysource, val_rsa, rsaorder) +FUNC2(void, get_rsa_ssh1_priv, val_string_binarysource, val_rsa) +FUNC2(val_string, rsa_ssh1_encrypt, val_string_ptrlen, val_rsa) +FUNC2(val_mpint, rsa_ssh1_decrypt, val_mpint, val_rsa) +FUNC2(val_string, rsa_ssh1_decrypt_pkcs1, val_mpint, val_rsa) +FUNC1(val_string_asciz, rsastr_fmt, val_rsa) +FUNC1(val_string_asciz, rsa_ssh1_fingerprint, val_rsa) +FUNC3(void, rsa_ssh1_public_blob, out_val_string_binarysink, val_rsa, rsaorder) +FUNC1(int, rsa_ssh1_public_blob_len, val_string_ptrlen) /* * Miscellaneous. */ -FUNC(val_wpoint, ecdsa_public, val_mpint, keyalg) -FUNC(val_epoint, eddsa_public, val_mpint, keyalg) -FUNC(val_string, des_encrypt_xdmauth, val_string_ptrlen, val_string_ptrlen) -FUNC(val_string, des_decrypt_xdmauth, val_string_ptrlen, val_string_ptrlen) +FUNC2(val_wpoint, ecdsa_public, val_mpint, keyalg) +FUNC2(val_epoint, eddsa_public, val_mpint, keyalg) +FUNC2(val_string, des_encrypt_xdmauth, val_string_ptrlen, val_string_ptrlen) +FUNC2(val_string, des_decrypt_xdmauth, val_string_ptrlen, val_string_ptrlen) /* * These functions aren't part of PuTTY's own API, but are additions * by testcrypt itself for administrative purposes. */ -FUNC(void, random_queue, val_string_ptrlen) -FUNC(uint, random_queue_len) -FUNC(void, random_clear) +FUNC1(void, random_queue, val_string_ptrlen) +FUNC0(uint, random_queue_len) +FUNC0(void, random_clear) diff --git a/windows/winmiscs.c b/windows/winmiscs.c index bd6d6cac..4fdac154 100644 --- a/windows/winmiscs.c +++ b/windows/winmiscs.c @@ -263,3 +263,15 @@ void *minefield_c_realloc(void *p, size_t size) } #endif /* MINEFIELD */ + +#if defined _MSC_VER && _MSC_VER < 1800 + +/* + * Work around lack of strtoumax in older MSVC libraries + */ +uintmax_t strtoumax(const char *nptr, char **endptr, int base) +{ + return _strtoui64(nptr, endptr, base); +} + +#endif