# # # delete "botan/mp_add.cpp" # # delete "botan/mp_sub.cpp" # # add_file "botan/mp_asm.cpp" # content [6bbc7da9aa14f2a3851944eb594a5c0500c637a3] # # add_file "botan/mp_asmi.h" # content [9a3768c28ba06cf6435a8131e52b5d01a73bcf3e] # # patch "ChangeLog" # from [beb22f4654fb059a63b906c468b9c8fed15af7cb] # to [699b1fe8d9b81daef54ea07926030da91efcaec8] # # patch "Makefile.am" # from [23f1c46e322bd2e9d8fc7660c7ac0c935c3acb76] # to [96aeccfaacab054815dd7a62e6caece2ba64d859] # # patch "botan/asn1_dn.cpp" # from [51b2ba4326c52163456a03becbc2249168ca3691] # to [c90dcbbb9b75257b4c1318de177368dffc807b1d] # # patch "botan/ber_code.cpp" # from [fca2b4d8e8ef99e4da32e42c4d3366b161d5723f] # to [52fb39f0609b280838f952b34c77300dc424b9f1] # # patch "botan/big_base.cpp" # from [7b7a61902c43b9488128d60b950a1a9ec6f667b8] # to [9a81e6579e4d5fa4eae67951d421e2257f990648] # # patch "botan/big_ops2.cpp" # from [600fa64bbc1306e4d48e6717baf28dccb97a4bd8] # to [a7129d4c1c8855a50906c6210a1e6b6d3c37d915] # # patch "botan/big_ops3.cpp" # from [ed35714c74e8a46cc83510b94aa88252759055ba] # to [af27d7710afd7dae10689bf007ceb29713c1ca32] # # patch "botan/bigint.h" # from [2f22d329675f1cdae7ab5c2824067e58a4467f30] # to [613fc3aec6f498730a3431ba1394b5e46eba1106] # # patch "botan/bit_ops.cpp" # from [9548063db26062adee735f47a045a2e8b246edf6] # to [b35d3f6d5f4ea883ba3551f958ac08ad3f028036] # # patch "botan/buf_es.cpp" # from [4ce4aba6edc36d7a36afe4c274d02134f641fed9] # to [2e725066213e388d4a875613b774203e8fda58d0] # # patch "botan/buf_filt.cpp" # from [acf427f400125c1e9427da10f35d2a1f435adc4e] # to [2e4113960addc661421f7166495f965485df97a6] # # patch "botan/cbc.cpp" # from [d2dba7243726bc71889bcfcf69aeae09bfae5f88] # to [c5fbfe43bba5f023c3b0d34d055d17371266a217] # # patch "botan/cfb.cpp" # from [16a90ba04269adf38b456ced5487f410d9a15511] # to [09210c773f789ae5217375ff32a8388b61166791] # # patch "botan/ctr.cpp" # from [68b39a43c1e77abc1e97b2c89fa3c5e4fa21b4ef] # to [e38e980590fc2dc1b69529f16843f425292627ab] # # patch "botan/cts.cpp" # from [48dc412226b16f2be5f7502b3fe7888816724866] # to [77c48b7d93e12da5a2caa08742008f512666b48b] # # patch "botan/data_src.cpp" # from [43ac60765c3ffa36be55d080827411575510bc3e] # to [e245dee359e2eee95aa98f26e0e44a80e2687207] # # patch "botan/def_powm.h" # from [5c47338822f1eec4e187c542df0529cb8b8ac173] # to [b86729eec211b555859a04b3179593f5e958f63a] # # patch "botan/der_code.cpp" # from [2a13e0688e91eaf456bdf5db60c77fa371060849] # to [3ab985dc95a691c267623fddb1c6a09666c36d81] # # patch "botan/divide.cpp" # from [40f8a31ed5731ea3bcabb611198c770e1f62774f] # to [b7ae7fc20fed92414c2adaa124c51d508785ba7f] # # patch "botan/eax.cpp" # from [e23c313cd6eaa3b5c0e3209f665d2bd5ef96085e] # to [4b44d043201c25ca048ed777d5ed5e911d225578] # # patch "botan/filter.cpp" # from [c38f149e29ece60b4d79fd2b4aa1746bc98ce37a] # to [24a13d191c5b20b1445a0b581fc8b0ca92dcda43] # # patch "botan/filters.cpp" # from [dce61805189ff431083613a331ab42b26aca64ec] # to [3d0d5434ca77537efee8bc7835c47e44e9faa38d] # # patch "botan/get_algo.cpp" # from [89ca5531b77ddcbf202cb930d4fd3f863ee38504] # to [aa65bc3017795f1ae58e8cf34e54ed881f30ee40] # # patch "botan/hex.cpp" # from [875cfbfe15cc074195bab031f907de885496f311] # to [4c302607fcd8788373c70e4f96b8746e64e85326] # # patch "botan/hmac.cpp" # from [219e669226db3c9f450e8d434bbfefc11876070e] # to [544b1c880365d3ca6c2e435a928af8647356d5ff] # # patch "botan/kdf.cpp" # from [65f28a1f1a94a55e816feb29eb219910dc92644e] # to [e6b66452265f1bfd7e865837bb283bcc1a16b78c] # # patch "botan/make_prm.cpp" # from [7c867a6d50b8d9d804900d2c634304693d8d5ce1] # to [92eadd5a0197ce5cdd5a80b7ef146e1c4beb737c] # # patch "botan/mem_pool.cpp" # from [4071bb398b36e883145b5d9d956ca14dd299f093] # to [008f77e32528d87b389a1de2122ed1deff9185df] # # patch "botan/mgf1.cpp" # from [bf33f05697c4578337fc9cc1410e1a4e84975990] # to [29ebaaf6613d812554b3d553f52aae167eaf3ea4] # # patch "botan/modules.cpp" # from [cd75a13013e5d6083d9425a9a753f4d92bf13af2] # to [0b5c64396972086e33fa6129a75afd81a3ee5de1] # # patch "botan/mp_asm.h" # from [a1f6a95c58b1a7036398fb843807d2016be2c438] # to [993bac9e1839b558d2679d07423b9c87797e8ec0] # # patch "botan/mp_comba.cpp" # from [ea841c092b0697f5297fb978cff5d71eee142149] # to [e01f37a78407405fa61444130fceeac7d8683097] # # patch "botan/mp_core.h" # from [af2e3afc3189ae2734b60216033ff361edbfda6c] # to [2247e0cd44d00ef46302f75bf74230b6bf4ba765] # # patch "botan/mp_misc.cpp" # from [403da43006f3563e3f7610b2ad6efff0034b5809] # to [da1628dfed644709a2b6e1ea22f0ee352e617b1b] # # patch "botan/mp_mul.cpp" # from [c22efb440d348bddd92f117a37a3296f112a92e9] # to [76e5669ba8841469d4bd5647f467a20094fe5e15] # # patch "botan/mp_numth.cpp" # from [4c55dcdaad744b0725dd5d7e489acdb6eb4039bd] # to [ee21088447a4ea56f7703a8f48428619f20f2c9e] # # patch "botan/mp_shift.cpp" # from [325a72292b8477bba5aecfede199e01b6ada1992] # to [653165b533aaac2ee1614862534acb920e0d2cfe] # # patch "botan/mp_sqr.cpp" # from [432313c19062bf16fd46c2f484b7ff2abde9e536] # to [e80b8be2f66892e1d9c161a54956a42df08975d5] # # patch "botan/numthry.cpp" # from [6a5d1c3ce4a22e0008ef01684c5b9d129dcd23ad] # to [dc52a7d8bd533fef023056d599d9791a0a932dab] # # patch "botan/ofb.cpp" # from [ce7e2a5f1d9f76971ad66c6b79015a7e894fb506] # to [a32bc675be00576ff4d42bdbdbb3ac747335c049] # # patch "botan/pbes1.cpp" # from [1d5afb55ee77c3cecac5c76f763c82315f82bf6a] # to [6ea97e63fdf2638cd51a315bcd0b212f8320147b] # # patch "botan/pbes2.cpp" # from [6aa65fd5356d5f5bbb3f5d645d9e0cce53b1484f] # to [8f5482302d7fce26c48dc539f3f1f499ba72f098] # # patch "botan/pk_core.cpp" # from [0389b1a4f1cd6c7c40ffb64d730529968ee58307] # to [460ac1a0935469301fcb2e28f7b2561340cc4ef7] # # patch "botan/pkcs5.cpp" # from [191a70d25a288701ed5be7d8898129dfe484e348] # to [573e3e5f7867ba0e29237a8ce982dd990d7151e8] # # patch "botan/policy.cpp" # from [6d7bcb9a5926060492333a307fcc21a0294821bb] # to [e6c56d910f2460a72d41603c4a32b99aa4a6c145] # # patch "botan/powm_fw.cpp" # from [47a558712cef903c7205aa7d19dfc9f3ce1f8488] # to [b1a47e40d185947a51ffcb41597568c748b5fdda] # # patch "botan/powm_mnt.cpp" # from [fb243f2b18a781bc9327a79a7e0cec0bd60b4d21] # to [a9e9d38aa4b3a66ef19d4974bb2e78625c77aa66] # # patch "botan/prf_x942.cpp" # from [8878753f4bcf9a5a1f71ac387b1a02c7f0acd23f] # to [714523e7a9aeb580bbdf6d098eab344e3ad7d1f7] # # patch "botan/randpool.cpp" # from [3e6ae9338b29a4a63d97b189a4184b9e18413038] # to [86c811993172d4b571739941f71b56ac51d85231] # # patch "botan/readme.txt" # from [5a24d1c1f9a0ab20413df3e5517d6c7f179c4158] # to [fcbc7ef51a881464e80d3638b2f8bbda8d81c345] # # patch "botan/secqueue.cpp" # from [980277872ed4f33cb3164ba90aa6f42e43bbd959] # to [5ccf8b1122fb6af815f4a56b424940d7cfaabc6e] # # patch "botan/symkey.cpp" # from [bf0815d2471b664035f262f40563c4eab7df9164] # to [9b1f5232e3ee804994d5d335879384b0a10e9d0a] # # patch "botan/x509_ca.cpp" # from [a94a371ac8b99d786f17441ffd6995ff5e1a6f49] # to [aa8c7dcf99a2c1e9e8db19bcdf7a6fe9bf18eecb] # # patch "botan/x509_ca.h" # from [06b345d0eea26ad6720442e1972a08604a668eee] # to [4867678a321798143b83d34c9d57519075e5bd50] # # patch "botan/x509self.cpp" # from [11382c4f93c3055cc2564138c9cdef0b5463caf9] # to [4bcf4f6cd7119e7943d858b207c6eddde4fc8ff1] # # patch "botan/x931_rng.cpp" # from [ee85f1d9ebc7be0d7f600386a1070641554a986c] # to [f8054903a29e41dfe9ba76291d8ffc5e26bc8166] # ============================================================ --- botan/mp_asm.cpp 6bbc7da9aa14f2a3851944eb594a5c0500c637a3 +++ botan/mp_asm.cpp 6bbc7da9aa14f2a3851944eb594a5c0500c637a3 @@ -0,0 +1,228 @@ +/************************************************* +* Lowest Level MPI Algorithms Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include +#include +#include +#include + +namespace Botan { + +extern "C" { + +/************************************************* +* Two Operand Addition, No Carry * +*************************************************/ +word bigint_add2_nc(word x[], u32bit x_size, const word y[], u32bit y_size) + { + word carry = 0; + + const u32bit blocks = y_size - (y_size % 4); + + for(u32bit j = 0; j != blocks; j += 4) + word4_add2(x + j, y + j, &carry); + + for(u32bit j = blocks; j != y_size; ++j) + x[j] = word_add(x[j], y[j], &carry); + + if(!carry) + return 0; + + for(u32bit j = y_size; j != x_size; ++j) + if(++x[j]) + return 0; + + return 1; + } + +/************************************************* +* Three Operand Addition, No Carry * +*************************************************/ +word bigint_add3_nc(word z[], const word x[], u32bit x_size, + const word y[], u32bit y_size) + { + if(x_size < y_size) + { return bigint_add3_nc(z, y, y_size, x, x_size); } + + word carry = 0; + + const u32bit blocks = y_size - (y_size % 4); + + for(u32bit j = 0; j != blocks; j += 4) + word4_add3(z + j, x + j, y + j, &carry); + + for(u32bit j = blocks; j != y_size; ++j) + z[j] = word_add(x[j], y[j], &carry); + + for(u32bit j = y_size; j != x_size; ++j) + { + word x_j = x[j] + carry; + if(carry && x_j) + carry = 0; + z[j] = x_j; + } + + return carry; + } + +/************************************************* +* Two Operand Addition * +*************************************************/ +void bigint_add2(word x[], u32bit x_size, const word y[], u32bit y_size) + { + x[x_size] += bigint_add2_nc(x, x_size, y, y_size); + } + +/************************************************* +* Three Operand Addition * +*************************************************/ +void bigint_add3(word z[], const word x[], u32bit x_size, + const word y[], u32bit y_size) + { + const u32bit top_word = (x_size > y_size ? x_size : y_size); + z[top_word] += bigint_add3_nc(z, x, x_size, y, y_size); + } + +/************************************************* +* Two Operand Subtraction * +*************************************************/ +void bigint_sub2(word x[], u32bit x_size, const word y[], u32bit y_size) + { + word carry = 0; + + const u32bit blocks = y_size - (y_size % 4); + + for(u32bit j = 0; j != blocks; j += 4) + word4_sub2(x + j, y + j, &carry); + + for(u32bit j = blocks; j != y_size; ++j) + x[j] = word_sub(x[j], y[j], &carry); + + if(!carry) return; + + for(u32bit j = y_size; j != x_size; ++j) + { + --x[j]; + if(x[j] != MP_WORD_MAX) return; + } + } + +/************************************************* +* Three Operand Subtraction * +*************************************************/ +void bigint_sub3(word z[], const word x[], u32bit x_size, + const word y[], u32bit y_size) + { + word carry = 0; + + const u32bit blocks = y_size - (y_size % 4); + + for(u32bit j = 0; j != blocks; j += 4) + word4_sub3(z + j, x + j, y + j, &carry); + + for(u32bit j = blocks; j != y_size; ++j) + z[j] = word_sub(x[j], y[j], &carry); + + for(u32bit j = y_size; j != x_size; ++j) + { + word x_j = x[j] - carry; + if(carry && x_j != MP_WORD_MAX) + carry = 0; + z[j] = x_j; + } + } + +/************************************************* +* Two Operand Linear Multiply * +*************************************************/ +void bigint_linmul2(word x[], u32bit x_size, word y) + { + const u32bit blocks = x_size - (x_size % 4); + + word carry = 0; + + for(u32bit j = 0; j != blocks; j += 4) + word4_linmul2(x + j, y, &carry); + + for(u32bit j = blocks; j != x_size; ++j) + x[j] = word_mul(x[j], y, &carry); + + x[x_size] = carry; + } + +/************************************************* +* Three Operand Linear Multiply * +*************************************************/ +void bigint_linmul3(word z[], const word x[], u32bit x_size, word y) + { + const u32bit blocks = x_size - (x_size % 4); + + word carry = 0; + + for(u32bit j = 0; j != blocks; j += 4) + word4_linmul3(z + j, x + j, y, &carry); + + for(u32bit j = blocks; j != x_size; ++j) + z[j] = word_mul(x[j], y, &carry); + + z[x_size] = carry; + } + +/************************************************* +* Fused Linear Multiply / Addition Operation * +*************************************************/ +void bigint_linmul_add(word z[], u32bit z_size, + const word x[], u32bit x_size, word y) + { + word carry = 0; + + const u32bit blocks = x_size - (x_size % 8); + + for(u32bit j = 0; j != blocks; j += 8) + word8_madd3(z + j, y, x + j, &carry); + + for(u32bit j = blocks; j != x_size; ++j) + word_madd(x[j], y, z[j], carry, z + j, &carry); + + word carry2 = 0; + z[x_size] = word_add(z[x_size], carry, &carry2); + carry = carry2; + + for(u32bit j = x_size + 1; carry && j != z_size; ++j) + { + ++z[j]; + carry = !z[j]; + } + z[z_size] += carry; + } + +/************************************************* +* Simple O(N^2) Multiplication * +*************************************************/ +void bigint_simple_mul(word z[], const word x[], u32bit x_size, + const word y[], u32bit y_size) + { + const u32bit blocks = y_size - (y_size % 8); + + clear_mem(z, x_size + y_size); + + for(u32bit j = 0; j != x_size; ++j) + { + const word x_j = x[j]; + word carry = 0; + + for(u32bit k = 0; k != blocks; k += 8) + word8_madd3(z + j + k, x_j, y + k, &carry); + + for(u32bit k = blocks; k != y_size; ++k) + word_madd(x_j, y[k], z[j+k], carry, z + (j+k), &carry); + + z[j+y_size] = carry; + } + } + +} + +} ============================================================ --- botan/mp_asmi.h 9a3768c28ba06cf6435a8131e52b5d01a73bcf3e +++ botan/mp_asmi.h 9a3768c28ba06cf6435a8131e52b5d01a73bcf3e @@ -0,0 +1,126 @@ +/************************************************* +* Lowest Level MPI Algorithms Header File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#ifndef BOTAN_MP_ASM_INTERNAL_H__ +#define BOTAN_MP_ASM_INTERNAL_H__ + +#include + +namespace Botan { + +extern "C" { + +/************************************************* +* Word Addition * +*************************************************/ +inline word word_add(word x, word y, word* carry) + { + word z = x + y; + word c1 = (z < x); + z += *carry; + *carry = c1 | (z < *carry); + return z; + } + +/************************************************* +* Four Word Block Addition, Two Argument * +*************************************************/ +inline void word4_add2(word x[4], const word y[4], word* carry) + { + x[0] = word_add(x[0], y[0], carry); + x[1] = word_add(x[1], y[1], carry); + x[2] = word_add(x[2], y[2], carry); + x[3] = word_add(x[3], y[3], carry); + } + +/************************************************* +* Four Word Block Addition, Three Argument * +*************************************************/ +inline void word4_add3(word z[4], const word x[4], + const word y[4], word* carry) + { + z[0] = word_add(x[0], y[0], carry); + z[1] = word_add(x[1], y[1], carry); + z[2] = word_add(x[2], y[2], carry); + z[3] = word_add(x[3], y[3], carry); + } + +/************************************************* +* Word Subtraction * +*************************************************/ +inline word word_sub(word x, word y, word* carry) + { + word t0 = x - y; + word c1 = (t0 > x); + word z = t0 - *carry; + *carry = c1 | (z > t0); + return z; + } + +/************************************************* +* Four Word Block Subtraction, Two Argument * +*************************************************/ +inline void word4_sub2(word x[4], const word y[4], word* carry) + { + x[0] = word_sub(x[0], y[0], carry); + x[1] = word_sub(x[1], y[1], carry); + x[2] = word_sub(x[2], y[2], carry); + x[3] = word_sub(x[3], y[3], carry); + } + +/************************************************* +* Four Word Block Subtraction, Three Argument * +*************************************************/ +inline void word4_sub3(word z[4], const word x[4], + const word y[4], word* carry) + { + z[0] = word_sub(x[0], y[0], carry); + z[1] = word_sub(x[1], y[1], carry); + z[2] = word_sub(x[2], y[2], carry); + z[3] = word_sub(x[3], y[3], carry); + } + +/************************************************* +* Four Word Block Linear Multiplication * +*************************************************/ +inline void word4_linmul2(word x[4], word y, word* carry) + { + x[0] = word_mul(x[0], y, carry); + x[1] = word_mul(x[1], y, carry); + x[2] = word_mul(x[2], y, carry); + x[3] = word_mul(x[3], y, carry); + } + +/************************************************* +* Four Word Block Linear Multiplication * +*************************************************/ +inline void word4_linmul3(word z[4], const word x[4], word y, word* carry) + { + z[0] = word_mul(x[0], y, carry); + z[1] = word_mul(x[1], y, carry); + z[2] = word_mul(x[2], y, carry); + z[3] = word_mul(x[3], y, carry); + } + +/************************************************* +* Eight Word Block Multiply-Add * +*************************************************/ +inline void word8_madd3(word z[], word x, const word y[], word* carry) + { + word_madd(x, y[0], z[0], *carry, z + 0, carry); + word_madd(x, y[1], z[1], *carry, z + 1, carry); + word_madd(x, y[2], z[2], *carry, z + 2, carry); + word_madd(x, y[3], z[3], *carry, z + 3, carry); + word_madd(x, y[4], z[4], *carry, z + 4, carry); + word_madd(x, y[5], z[5], *carry, z + 5, carry); + word_madd(x, y[6], z[6], *carry, z + 6, carry); + word_madd(x, y[7], z[7], *carry, z + 7, carry); + } + +} + +} + +#endif ============================================================ --- ChangeLog beb22f4654fb059a63b906c468b9c8fed15af7cb +++ ChangeLog 699b1fe8d9b81daef54ea07926030da91efcaec8 @@ -1,3 +1,7 @@ +2006-01-25 Matt Johnston + + * merged in Botan 1.5.3 experimental release + 2006-01-22 Matt Johnston * merged in Botan 1.5.2 experimental release ============================================================ --- Makefile.am 23f1c46e322bd2e9d8fc7660c7ac0c935c3acb76 +++ Makefile.am 96aeccfaacab054815dd7a62e6caece2ba64d859 @@ -123,9 +123,9 @@ botan/def_alg.cpp botan/def_mode.cpp botan/sha256.cpp \ botan/x931_rng.cpp botan/out_buf.cpp botan/bit_ops.cpp \ botan/big_rand.cpp botan/def_powm.cpp botan/libstate.cpp \ - botan/modules.cpp botan/mp_add.cpp botan/mp_numth.cpp \ - botan/mp_sqr.cpp botan/mp_sub.cpp botan/powm_fw.cpp \ - botan/powm_mnt.cpp \ + botan/modules.cpp botan/mp_numth.cpp \ + botan/mp_sqr.cpp botan/powm_fw.cpp \ + botan/powm_mnt.cpp botan/mp_asm.cpp \ \ botan/aes.h botan/botan.h botan/def_eng.h botan/es_win32.h \ botan/lookup.h botan/randpool.h botan/version.h \ @@ -162,7 +162,7 @@ botan/x931_rng.h botan/sha256.h \ botan/parsing.h botan/out_buf.h botan/bit_ops.h \ botan/def_powm.h botan/dl_group.h botan/libstate.h \ - botan/modules.h botan/mp_asm.h botan/pow_mod.h + botan/modules.h botan/mp_asm.h botan/pow_mod.h botan/mp_asmi.h ============================================================ --- botan/asn1_dn.cpp 51b2ba4326c52163456a03becbc2249168ca3691 +++ botan/asn1_dn.cpp c90dcbbb9b75257b4c1318de177368dffc807b1d @@ -197,7 +197,7 @@ if(attr1.size() < attr2.size()) return true; if(attr1.size() > attr2.size()) return false; - for(rdn_iter p1 = attr1.begin(); p1 != attr1.end(); p1++) + for(rdn_iter p1 = attr1.begin(); p1 != attr1.end(); ++p1) { std::multimap::const_iterator p2; p2 = attr2.find(p1->first); ============================================================ --- botan/ber_code.cpp fca2b4d8e8ef99e4da32e42c4d3366b161d5723f +++ botan/ber_code.cpp 52fb39f0609b280838f952b34c77300dc424b9f1 @@ -120,7 +120,7 @@ if(negative) { - for(u32bit j = obj.value.size(); j > 0; j--) + for(u32bit j = obj.value.size(); j > 0; --j) if(obj.value[j-1]--) break; for(u32bit j = 0; j != obj.value.size(); ++j) ============================================================ --- botan/big_base.cpp 7b7a61902c43b9488128d60b950a1a9ec6f667b8 +++ botan/big_base.cpp 9a81e6579e4d5fa4eae67951d421e2257f990648 @@ -23,7 +23,7 @@ const u32bit limbs_needed = sizeof(u64bit) / sizeof(word); - reg.create(2*limbs_needed); + reg.create(4*limbs_needed); for(u32bit j = 0; j != limbs_needed; ++j) reg[j] = (word)((n >> (j*MP_WORD_BITS)) & MP_WORD_MASK); } @@ -33,7 +33,7 @@ *************************************************/ BigInt::BigInt(Sign s, u32bit size) { - reg.create(round_up(size, 16)); + reg.create(round_up(size, 8)); signedness = s; } @@ -46,7 +46,7 @@ if(b_words) { - reg.create(round_up(b_words, 16)); + reg.create(round_up(b_words, 8)); reg.copy(b.data(), b_words); set_sign(b.sign()); } @@ -99,6 +99,14 @@ } /************************************************* +* Grow the internal storage * +*************************************************/ +void BigInt::grow_reg(u32bit n) const + { + reg.grow_by(round_up(n, 8)); + } + +/************************************************* * Comparison Function * *************************************************/ s32bit BigInt::cmp(const BigInt& n, bool check_signs) const @@ -302,11 +310,15 @@ *************************************************/ u32bit BigInt::bits() const { - if(sig_words() == 0) return 0; + if(sig_words() == 0) + return 0; + u32bit full_words = sig_words() - 1, top_bits = MP_WORD_BITS; word top_word = word_at(full_words), mask = MP_WORD_TOP_BIT; + while(top_bits && ((top_word & mask) == 0)) { mask >>= 1; top_bits--; } + return (full_words * MP_WORD_BITS + top_bits); } @@ -316,6 +328,7 @@ u32bit BigInt::encoded_size(Base base) const { static const double LOG_2_BASE_10 = 0.30102999566; + if(base == Binary) return bytes(); else if(base == Hexadecimal) @@ -403,12 +416,12 @@ void BigInt::binary_decode(const byte buf[], u32bit length) { const u32bit WORD_BYTES = sizeof(word); - reg.create(round_up(length / WORD_BYTES + 1, 4)); + reg.create(round_up((length / WORD_BYTES) + 1, 8)); for(u32bit j = 0; j != length / WORD_BYTES; ++j) { u32bit top = length - WORD_BYTES*j; - for(u32bit k = WORD_BYTES; k > 0; k--) + for(u32bit k = WORD_BYTES; k > 0; --k) reg[j] = (reg[j] << 8) | buf[top - k]; } for(u32bit j = 0; j != length % WORD_BYTES; ++j) ============================================================ --- botan/big_ops2.cpp 600fa64bbc1306e4d48e6717baf28dccb97a4bd8 +++ botan/big_ops2.cpp a7129d4c1c8855a50906c6210a1e6b6d3c37d915 @@ -7,6 +7,7 @@ #include #include #include +#include namespace Botan { @@ -91,9 +92,9 @@ } BigInt z(sign(), size() + n.size()); - bigint_mul3(z.get_reg(), z.size(), - data(), size(), words, - n.data(), n.size(), n_words); + bigint_mul(z.get_reg(), z.size(), + data(), size(), words, + n.data(), n.size(), n_words); (*this) = z; return (*this); } @@ -138,7 +139,7 @@ word remainder = 0; u32bit size = sig_words(); - for(u32bit j = size; j > 0; j--) + for(u32bit j = size; j > 0; --j) remainder = bigint_modop(remainder, word_at(j-1), mod); clear(); reg.grow_to(2); ============================================================ --- botan/big_ops3.cpp ed35714c74e8a46cc83510b94aa88252759055ba +++ botan/big_ops3.cpp af27d7710afd7dae10689bf007ceb29713c1ca32 @@ -7,6 +7,7 @@ #include #include #include +#include namespace Botan { @@ -89,9 +90,9 @@ } BigInt z(sign, x.size() + y.size()); - bigint_mul3(z.get_reg(), z.size(), - x.data(), x.size(), x_sw, - y.data(), y.size(), y_sw); + bigint_mul(z.get_reg(), z.size(), + x.data(), x.size(), x_sw, + y.data(), y.size(), y_sw); return z; } @@ -136,7 +137,7 @@ word remainder = 0; u32bit size = n.sig_words(); - for(u32bit j = size; j > 0; j--) + for(u32bit j = size; j > 0; --j) remainder = bigint_modop(remainder, n.word_at(j-1), mod); return remainder; } ============================================================ --- botan/bigint.h 2f22d329675f1cdae7ab5c2824067e58a4467f30 +++ botan/bigint.h 613fc3aec6f498730a3431ba1394b5e46eba1106 @@ -78,7 +78,7 @@ const word* data() const { return reg.begin(); } SecureVector& get_reg() { return reg; } - void grow_reg(u32bit n) const { reg.grow_by(n); } + void grow_reg(u32bit) const; word& operator[](u32bit index) { return reg[index]; } word operator[](u32bit index) const { return reg[index]; } ============================================================ --- botan/bit_ops.cpp 9548063db26062adee735f47a045a2e8b246edf6 +++ botan/bit_ops.cpp b35d3f6d5f4ea883ba3551f958ac08ad3f028036 @@ -55,7 +55,7 @@ *************************************************/ u32bit high_bit(u64bit n) { - for(u32bit count = 64; count > 0; count--) + for(u32bit count = 64; count > 0; --count) if((n >> (count - 1)) & 0x01) return count; return 0; @@ -66,7 +66,7 @@ *************************************************/ u32bit low_bit(u64bit n) { - for(u32bit count = 0; count != 64; count++) + for(u32bit count = 0; count != 64; ++count) if((n >> count) & 0x01) return (count + 1); return 0; ============================================================ --- botan/buf_es.cpp 4ce4aba6edc36d7a36afe4c274d02134f641fed9 +++ botan/buf_es.cpp 2e725066213e388d4a875613b774203e8fda58d0 @@ -6,6 +6,7 @@ #include #include #include +#include namespace Botan { ============================================================ --- botan/buf_filt.cpp acf427f400125c1e9427da10f35d2a1f435adc4e +++ botan/buf_filt.cpp 2e4113960addc661421f7166495f965485df97a6 @@ -1,9 +1,10 @@ /************************************************* * Buffering Filter Source File * * (C) 1999-2006 The Botan Project * *************************************************/ #include +#include namespace Botan { ============================================================ --- botan/cbc.cpp d2dba7243726bc71889bcfcf69aeae09bfae5f88 +++ botan/cbc.cpp c5fbfe43bba5f023c3b0d34d055d17371266a217 @@ -6,6 +6,7 @@ #include #include #include +#include namespace Botan { ============================================================ --- botan/cfb.cpp 16a90ba04269adf38b456ced5487f410d9a15511 +++ botan/cfb.cpp 09210c773f789ae5217375ff32a8388b61166791 @@ -7,6 +7,7 @@ #include #include #include +#include namespace Botan { ============================================================ --- botan/ctr.cpp 68b39a43c1e77abc1e97b2c89fa3c5e4fa21b4ef +++ botan/ctr.cpp e38e980590fc2dc1b69529f16843f425292627ab @@ -6,6 +6,7 @@ #include #include #include +#include namespace Botan { @@ -63,7 +64,7 @@ *************************************************/ void CTR_BE::increment_counter() { - for(s32bit j = BLOCK_SIZE - 1; j >= 0; j--) + for(s32bit j = BLOCK_SIZE - 1; j >= 0; --j) if(++state[j]) break; cipher->encrypt(state, buffer); ============================================================ --- botan/cts.cpp 48dc412226b16f2be5f7502b3fe7888816724866 +++ botan/cts.cpp 77c48b7d93e12da5a2caa08742008f512666b48b @@ -6,6 +6,7 @@ #include #include #include +#include namespace Botan { ============================================================ --- botan/data_src.cpp 43ac60765c3ffa36be55d080827411575510bc3e +++ botan/data_src.cpp e245dee359e2eee95aa98f26e0e44a80e2687207 @@ -5,6 +5,7 @@ #include #include +#include namespace Botan { ============================================================ --- botan/def_powm.h 5c47338822f1eec4e187c542df0529cb8b8ac173 +++ botan/def_powm.h b86729eec211b555859a04b3179593f5e958f63a @@ -45,9 +45,6 @@ Montgomery_Exponentiator(const BigInt&, Power_Mod::Usage_Hints); private: BigInt reduce(const BigInt&) const; - void square_and_reduce(BigInt&, MemoryRegion&) const; - void mul_and_reduce(BigInt&, const BigInt&, - MemoryRegion&) const; BigInt exp, modulus; BigInt R2, R_mod; ============================================================ --- botan/der_code.cpp 2a13e0688e91eaf456bdf5db60c77fa371060849 +++ botan/der_code.cpp 3ab985dc95a691c267623fddb1c6a09666c36d81 @@ -131,7 +131,7 @@ { for(u32bit j = 0; j != contents.size(); ++j) contents[j] = ~contents[j]; - for(u32bit j = contents.size(); j > 0; j--) + for(u32bit j = contents.size(); j > 0; --j) if(++contents[j-1]) break; } ============================================================ --- botan/divide.cpp 40f8a31ed5731ea3bcabb611198c770e1f62774f +++ botan/divide.cpp b7ae7fc20fed92414c2adaa124c51d508785ba7f @@ -72,7 +72,7 @@ while(x >= temp) { x -= temp; ++q[n-t]; } - for(u32bit j = n; j != t; j--) + for(u32bit j = n; j != t; --j) { const word x_j0 = x.word_at(j); const word x_j1 = x.word_at(j-1); @@ -85,13 +85,13 @@ while(bigint_divcore(q[j-t-1], y_t, y.word_at(t-1), x_j0, x_j1, x.word_at(j-2))) - q[j-t-1]--; + --q[j-t-1]; x -= (q[j-t-1] * y) << (MP_WORD_BITS * (j-t-1)); if(x.is_negative()) { x += y << (MP_WORD_BITS * (j-t-1)); - q[j-t-1]--; + --q[j-t-1]; } } x >>= shifts; ============================================================ --- botan/eax.cpp e23c313cd6eaa3b5c0e3209f665d2bd5ef96085e +++ botan/eax.cpp 4b44d043201c25ca048ed777d5ed5e911d225578 @@ -7,6 +7,7 @@ #include #include #include +#include namespace Botan { @@ -112,7 +113,7 @@ *************************************************/ void EAX_Base::increment_counter() { - for(s32bit j = BLOCK_SIZE - 1; j >= 0; j--) + for(s32bit j = BLOCK_SIZE - 1; j >= 0; --j) if(++state[j]) break; cipher->encrypt(state, buffer); ============================================================ --- botan/filter.cpp c38f149e29ece60b4d79fd2b4aa1746bc98ce37a +++ botan/filter.cpp 24a13d191c5b20b1445a0b581fc8b0ca92dcda43 @@ -104,7 +104,7 @@ void Filter::set_next(Filter* filters[], u32bit size) { while(size && filters && filters[size-1] == 0) - size--; + --size; next.clear(); next.resize(size); ============================================================ --- botan/filters.cpp dce61805189ff431083613a331ab42b26aca64ec +++ botan/filters.cpp 3d0d5434ca77537efee8bc7835c47e44e9faa38d @@ -5,6 +5,7 @@ #include #include +#include namespace Botan { ============================================================ --- botan/get_algo.cpp 89ca5531b77ddcbf202cb930d4fd3f863ee38504 +++ botan/get_algo.cpp aa65bc3017795f1ae58e8cf34e54ed881f30ee40 @@ -94,9 +94,7 @@ *************************************************/ bool have_block_cipher(const std::string& name) { - if(retrieve_block_cipher(name)) - return true; - return false; + return retrieve_block_cipher(name); } /************************************************* @@ -104,9 +102,7 @@ *************************************************/ bool have_stream_cipher(const std::string& name) { - if(retrieve_stream_cipher(name)) - return true; - return false; + return retrieve_stream_cipher(name); } /************************************************* @@ -114,9 +110,7 @@ *************************************************/ bool have_hash(const std::string& name) { - if(retrieve_hash(name)) - return true; - return false; + return retrieve_hash(name); } /************************************************* @@ -124,19 +118,22 @@ *************************************************/ bool have_mac(const std::string& name) { - if(retrieve_mac(name)) - return true; - return false; + return retrieve_mac(name); } /************************************************* -* Query the BLOCK_SIZE of a block cipher * +* Query the block size of a cipher or hash * *************************************************/ u32bit block_size_of(const std::string& name) { const BlockCipher* cipher = retrieve_block_cipher(name); if(cipher) return cipher->BLOCK_SIZE; + + const HashFunction* hash = retrieve_hash(name); + if(hash) + return hash->HASH_BLOCK_SIZE; + throw Algorithm_Not_Found(name); } ============================================================ --- botan/hex.cpp 875cfbfe15cc074195bab031f907de885496f311 +++ botan/hex.cpp 4c302607fcd8788373c70e4f96b8746e64e85326 @@ -6,6 +6,7 @@ #include #include #include +#include namespace Botan { ============================================================ --- botan/hmac.cpp 219e669226db3c9f450e8d434bbfefc11876070e +++ botan/hmac.cpp 544b1c880365d3ca6c2e435a928af8647356d5ff @@ -77,7 +77,8 @@ * HMAC Constructor * *************************************************/ HMAC::HMAC(const std::string& hash_name) : - MessageAuthenticationCode(output_length_of(hash_name), 1, 128), + MessageAuthenticationCode(output_length_of(hash_name), + 1, 2*block_size_of(hash_name)), hash(get_hash(hash_name)) { if(hash->HASH_BLOCK_SIZE == 0) ============================================================ --- botan/kdf.cpp 65f28a1f1a94a55e816feb29eb219910dc92644e +++ botan/kdf.cpp e6b66452265f1bfd7e865837bb283bcc1a16b78c @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace Botan { ============================================================ --- botan/make_prm.cpp 7c867a6d50b8d9d804900d2c634304693d8d5ce1 +++ botan/make_prm.cpp 92eadd5a0197ce5cdd5a80b7ef146e1c4beb737c @@ -9,6 +9,7 @@ #include #include #include +#include #include namespace Botan { @@ -20,7 +21,7 @@ *************************************************/ void increment(SecureVector& seed) { - for(u32bit j = seed.size(); j > 0; j--) + for(u32bit j = seed.size(); j > 0; --j) if(++seed[j-1]) break; } ============================================================ --- botan/mem_pool.cpp 4071bb398b36e883145b5d9d956ca14dd299f093 +++ botan/mem_pool.cpp 008f77e32528d87b389a1de2122ed1deff9185df @@ -34,9 +34,15 @@ u32bit emptiness_metric(u64bit bitmap) { u32bit metric = 0; + +#if 0 for(u32bit j = 0; j != 8; ++j) if(get_byte(j, bitmap) == 0) metric++; +#else + + +#endif return metric; } @@ -224,7 +230,7 @@ { const u32bit block_no = round_up(n, BLOCK_SIZE) / BLOCK_SIZE; - std::set::iterator i = blocks.begin(); + std::multiset::iterator i = blocks.begin(); while(i != blocks.end()) { if(i->contains(ptr, block_no)) @@ -250,7 +256,7 @@ *************************************************/ byte* Pooling_Allocator::allocate_blocks(u32bit n) { - std::set::iterator i = blocks.begin(); + std::multiset::iterator i = blocks.begin(); while(i != blocks.end()) { ============================================================ --- botan/mgf1.cpp bf33f05697c4578337fc9cc1410e1a4e84975990 +++ botan/mgf1.cpp 29ebaaf6613d812554b3d553f52aae167eaf3ea4 @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace Botan { ============================================================ --- botan/modules.cpp cd75a13013e5d6083d9425a9a753f4d92bf13af2 +++ botan/modules.cpp 0b5c64396972086e33fa6129a75afd81a3ee5de1 @@ -9,7 +9,7 @@ #if defined(BOTAN_EXT_MUTEX_PTHREAD) #include #elif defined(BOTAN_EXT_MUTEX_WIN32) - #include + #include #elif defined(BOTAN_EXT_MUTEX_QT) #include #endif ============================================================ --- botan/mp_asm.h a1f6a95c58b1a7036398fb843807d2016be2c438 +++ botan/mp_asm.h 993bac9e1839b558d2679d07423b9c87797e8ec0 @@ -22,27 +22,62 @@ namespace Botan { +extern "C" { + /************************************************* -* Multiply-Carry Operation * +* Word Multiply * *************************************************/ inline word word_mul(word a, word b, word* carry) { dword z = (dword)a * b + (*carry); - *carry = (word)((z >> BOTAN_MP_WORD_BITS) & MP_WORD_MAX); - return (word)(z & MP_WORD_MAX); + *carry = (word)(z >> BOTAN_MP_WORD_BITS); + return (word)z; } /************************************************* -* Multiply-Add Operation * +* Word Multiply/Add * *************************************************/ inline void word_madd(word a, word b, word c, word d, word* out_low, word* out_high) { dword z = (dword)a * b + c + d; - *out_low = (word)((z ) & MP_WORD_MAX); - *out_high = (word)((z >> BOTAN_MP_WORD_BITS) & MP_WORD_MAX); + *out_low = (word)z; + *out_high = (word)(z >> BOTAN_MP_WORD_BITS); } +/************************************************* +* Multiply-Add Accumulator * +*************************************************/ +inline void word3_muladd(word* w2, word* w1, word* w0, word a, word b) + { + dword z = (dword)a * b + (*w0); + *w0 = (word)z; + + word t1 = (word)(z >> BOTAN_MP_WORD_BITS); + *w1 += t1; + *w2 += (*w1 < t1) ? 1 : 0; + } + +/************************************************* +* Multiply-Add Accumulator * +*************************************************/ +inline void word3_muladd_2(word* w2, word* w1, word* w0, word a, word b) + { + dword z = (dword)a * b; + word t0 = (word)z; + word t1 = (word)(z >> BOTAN_MP_WORD_BITS); + + *w0 += t0; + *w1 += t1 + ((*w0 < t0) ? 1 : 0); + *w2 += (*w1 < t1) ? 1 : 0; + + *w0 += t0; + *w1 += t1 + ((*w0 < t0) ? 1 : 0); + *w2 += (*w1 < t1) ? 1 : 0; + } + } +} + #endif ============================================================ --- botan/mp_comba.cpp ea841c092b0697f5297fb978cff5d71eee142149 +++ botan/mp_comba.cpp e01f37a78407405fa61444130fceeac7d8683097 @@ -8,35 +8,6 @@ namespace Botan { -namespace { - -/************************************************* -* Multiply-Add Accumulators * -*************************************************/ -inline void word3_muladd(word* w2, word* w1, word* w0, word x, word y) - { - word t1 = 0; - word_madd(x, y, *w0, 0, w0, &t1); - *w1 += t1; - *w2 += (*w1 < t1) ? 1 : 0; - } - -inline void word3_muladd_2(word* w2, word* w1, word* w0, word x, word y) - { - word t0 = 0, t1 = 0; - word_madd(x, y, 0, 0, &t0, &t1); - - *w0 += t0; - *w1 += t1 + ((*w0 < t0) ? 1 : 0); - *w2 += (*w1 < t1) ? 1 : 0; - - *w0 += t0; - *w1 += t1 + ((*w0 < t0) ? 1 : 0); - *w2 += (*w1 < t1) ? 1 : 0; - } - -} - extern "C" { /************************************************* ============================================================ --- botan/mp_core.h af2e3afc3189ae2734b60216033ff361edbfda6c +++ botan/mp_core.h 2247e0cd44d00ef46302f75bf74230b6bf4ba765 @@ -38,11 +38,14 @@ void bigint_shr2(word[], const word[], u32bit, u32bit, u32bit); /************************************************* -* Linear Multiplication Operations * +* Multiplication and Squaring Operations * *************************************************/ void bigint_linmul2(word[], u32bit, word); void bigint_linmul3(word[], const word[], u32bit, word); +void bigint_simple_mul(word[], const word[], u32bit, const word[], u32bit); +void bigint_linmul_add(word[], u32bit, const word[], u32bit, word); + /************************************************* * Misc Utility Operations * *************************************************/ @@ -66,15 +69,12 @@ } /************************************************* -* Multiplication/Squaring Operations * +* High Level Multiplication/Squaring Interfaces * *************************************************/ -void bigint_mul3(word[], u32bit, const word[], u32bit, u32bit, - const word[], u32bit, u32bit); +void bigint_mul(word[], u32bit, const word[], u32bit, u32bit, + const word[], u32bit, u32bit); void bigint_sqr(word[], u32bit, const word[], u32bit, u32bit); -void bigint_simple_mul(word[], const word[], u32bit, const word[], u32bit); -void bigint_simple_sqr(word[], const word[], u32bit); - } #endif ============================================================ --- botan/mp_misc.cpp 403da43006f3563e3f7610b2ad6efff0034b5809 +++ botan/mp_misc.cpp da1628dfed644709a2b6e1ea22f0ee352e617b1b @@ -43,7 +43,7 @@ return 1; x_size--; } - for(u32bit j = x_size; j > 0; j--) + for(u32bit j = x_size; j > 0; --j) { if(x[j-1] > y[j-1]) return 1; if(x[j-1] < y[j-1]) return -1; ============================================================ --- botan/mp_mul.cpp c22efb440d348bddd92f117a37a3296f112a92e9 +++ botan/mp_mul.cpp 76e5669ba8841469d4bd5647f467a20094fe5e15 @@ -5,88 +5,11 @@ #include #include -#include -namespace Botan { +#include // remove -/************************************************* -* Two Operand Linear Multiply * -*************************************************/ -void bigint_linmul2(word x[], u32bit x_size, word y) - { - const u32bit blocks = x_size - (x_size % 4); +namespace Botan { - word carry = 0; - - for(u32bit j = 0; j != blocks; j += 4) - { - x[j ] = word_mul(x[j ], y, &carry); - x[j+1] = word_mul(x[j+1], y, &carry); - x[j+2] = word_mul(x[j+2], y, &carry); - x[j+3] = word_mul(x[j+3], y, &carry); - } - - for(u32bit j = blocks; j != x_size; ++j) - x[j] = word_mul(x[j], y, &carry); - - x[x_size] = carry; - } - -/************************************************* -* Three Operand Linear Multiply * -*************************************************/ -void bigint_linmul3(word z[], const word x[], u32bit x_size, word y) - { - const u32bit blocks = x_size - (x_size % 4); - - word carry = 0; - for(u32bit j = 0; j != blocks; j += 4) - { - z[j ] = word_mul(x[j ], y, &carry); - z[j+1] = word_mul(x[j+1], y, &carry); - z[j+2] = word_mul(x[j+2], y, &carry); - z[j+3] = word_mul(x[j+3], y, &carry); - } - - for(u32bit j = blocks; j != x_size; ++j) - z[j] = word_mul(x[j], y, &carry); - z[x_size] = carry; - } - -/************************************************* -* Simple O(N^2) Multiplication * -*************************************************/ -void bigint_simple_mul(word z[], const word x[], u32bit x_size, - const word y[], u32bit y_size) - { - const u32bit blocks = y_size - (y_size % 8); - - clear_mem(z, x_size + y_size); - - for(u32bit j = 0; j != x_size; ++j) - { - const word x_j = x[j]; - - word carry = 0; - - for(u32bit k = 0; k != blocks; k += 8) - { - word_madd(x_j, y[k+0], z[j+k+0], carry, z + (j+k+0), &carry); - word_madd(x_j, y[k+1], z[j+k+1], carry, z + (j+k+1), &carry); - word_madd(x_j, y[k+2], z[j+k+2], carry, z + (j+k+2), &carry); - word_madd(x_j, y[k+3], z[j+k+3], carry, z + (j+k+3), &carry); - word_madd(x_j, y[k+4], z[j+k+4], carry, z + (j+k+4), &carry); - word_madd(x_j, y[k+5], z[j+k+5], carry, z + (j+k+5), &carry); - word_madd(x_j, y[k+6], z[j+k+6], carry, z + (j+k+6), &carry); - word_madd(x_j, y[k+7], z[j+k+7], carry, z + (j+k+7), &carry); - } - - for(u32bit k = blocks; k != y_size; ++k) - word_madd(x_j, y[k], z[j+k], carry, z + (j+k), &carry); - z[j+y_size] = carry; - } - } - namespace { /************************************************* @@ -213,10 +136,14 @@ /************************************************* * Multiplication Algorithm Dispatcher * *************************************************/ -void bigint_mul3(word z[], u32bit z_size, - const word x[], u32bit x_size, u32bit x_sw, - const word y[], u32bit y_size, u32bit y_sw) +void bigint_mul(word z[], u32bit z_size, + const word x[], u32bit x_size, u32bit x_sw, + const word y[], u32bit y_size, u32bit y_sw) { + /* + if(x_size % 8 || y_size % 8) + printf("%d %d %d %d\n", x_size, x_sw, y_size, y_sw); + */ if(x_size <= 8 || y_size <= 8) { handle_small_mul(z, z_size, x, x_size, x_sw, y, y_size, y_sw); ============================================================ --- botan/mp_numth.cpp 4c55dcdaad744b0725dd5d7e489acdb6eb4039bd +++ botan/mp_numth.cpp ee21088447a4ea56f7703a8f48428619f20f2c9e @@ -5,6 +5,7 @@ #include #include +#include namespace Botan { @@ -37,9 +38,9 @@ const u32bit c_sw = c.sig_words(); BigInt r(sign, std::max(a.size() + b.size(), c_sw) + 1); - bigint_mul3(r.get_reg(), r.size(), - a.data(), a.size(), a_sw, - b.data(), b.size(), b_sw); + bigint_mul(r.get_reg(), r.size(), + a.data(), a.size(), a_sw, + b.data(), b.size(), b_sw); const u32bit r_size = std::max(r.sig_words(), c_sw); bigint_add2(r.get_reg(), r_size, c.data(), c_sw); return r; ============================================================ --- botan/mp_shift.cpp 325a72292b8477bba5aecfede199e01b6ada1992 +++ botan/mp_shift.cpp 653165b533aaac2ee1614862534acb920e0d2cfe @@ -53,7 +53,7 @@ if(bit_shift) { word carry = 0; - for(u32bit j = x_size - word_shift; j > 0; j--) + for(u32bit j = x_size - word_shift; j > 0; --j) { word temp = x[j-1]; x[j-1] = (temp >> bit_shift) | carry; @@ -95,7 +95,7 @@ if(bit_shift) { word carry = 0; - for(u32bit j = x_size - word_shift; j > 0; j--) + for(u32bit j = x_size - word_shift; j > 0; --j) { word temp = y[j-1]; y[j-1] = (temp >> bit_shift) | carry; ============================================================ --- botan/mp_sqr.cpp 432313c19062bf16fd46c2f484b7ff2abde9e536 +++ botan/mp_sqr.cpp e80b8be2f66892e1d9c161a54956a42df08975d5 @@ -5,43 +5,9 @@ #include #include -#include namespace Botan { -/************************************************* -* Simple O(N^2) Squaring * -*************************************************/ -void bigint_simple_sqr(word z[], const word x[], u32bit x_size) - { - const u32bit blocks = x_size - (x_size % 8); - - clear_mem(z, 2*x_size); - - for(u32bit j = 0; j != x_size; ++j) - { - const word x_j = x[j]; - - word carry = 0; - - for(u32bit k = 0; k != blocks; k += 8) - { - word_madd(x_j, x[k+0], z[j+k+0], carry, z + (j+k+0), &carry); - word_madd(x_j, x[k+1], z[j+k+1], carry, z + (j+k+1), &carry); - word_madd(x_j, x[k+2], z[j+k+2], carry, z + (j+k+2), &carry); - word_madd(x_j, x[k+3], z[j+k+3], carry, z + (j+k+3), &carry); - word_madd(x_j, x[k+4], z[j+k+4], carry, z + (j+k+4), &carry); - word_madd(x_j, x[k+5], z[j+k+5], carry, z + (j+k+5), &carry); - word_madd(x_j, x[k+6], z[j+k+6], carry, z + (j+k+6), &carry); - word_madd(x_j, x[k+7], z[j+k+7], carry, z + (j+k+7), &carry); - } - - for(u32bit k = blocks; k != x_size; ++k) - word_madd(x_j, x[k], z[j+k], carry, z + (j+k), &carry); - z[j+x_size] = carry; - } - } - namespace { /************************************************* @@ -56,7 +22,7 @@ else if(N == 8) bigint_comba_sqr8(z, x); else if(N < KARATSUBA_SQR_LOWER_SIZE || N % 2) - bigint_simple_sqr(z, x, N); + bigint_simple_mul(z, x, N, x, N); else { const u32bit N2 = N / 2; @@ -131,7 +97,7 @@ else if(x_sw <= 8 && x_size >= 8 && z_size >= 16) bigint_comba_sqr8(z, x); else - bigint_simple_sqr(z, x, x_sw); + bigint_simple_mul(z, x, x_sw, x, x_sw); } } @@ -161,7 +127,7 @@ delete[] workspace; } else - bigint_simple_sqr(z, x, x_sw); + bigint_simple_mul(z, x, x_sw, x, x_sw); } } ============================================================ --- botan/numthry.cpp 6a5d1c3ce4a22e0008ef01684c5b9d129dcd23ad +++ botan/numthry.cpp dc52a7d8bd533fef023056d599d9791a0a932dab @@ -6,6 +6,7 @@ #include #include #include +#include namespace Botan { ============================================================ --- botan/ofb.cpp ce7e2a5f1d9f76971ad66c6b79015a7e894fb506 +++ botan/ofb.cpp a32bc675be00576ff4d42bdbdbb3ac747335c049 @@ -6,6 +6,7 @@ #include #include #include +#include namespace Botan { ============================================================ --- botan/pbes1.cpp 1d5afb55ee77c3cecac5c76f763c82315f82bf6a +++ botan/pbes1.cpp 6ea97e63fdf2638cd51a315bcd0b212f8320147b @@ -8,6 +8,7 @@ #include #include #include +#include #include namespace Botan { ============================================================ --- botan/pbes2.cpp 6aa65fd5356d5f5bbb3f5d645d9e0cce53b1484f +++ botan/pbes2.cpp 8f5482302d7fce26c48dc539f3f1f499ba72f098 @@ -9,6 +9,7 @@ #include #include #include +#include #include namespace Botan { ============================================================ --- botan/pk_core.cpp 0389b1a4f1cd6c7c40ffb64d730529968ee58307 +++ botan/pk_core.cpp 460ac1a0935469301fcb2e28f7b2561340cc4ef7 @@ -7,6 +7,7 @@ #include #include #include +#include namespace Botan { ============================================================ --- botan/pkcs5.cpp 191a70d25a288701ed5be7d8898129dfe484e348 +++ botan/pkcs5.cpp 573e3e5f7867ba0e29237a8ce982dd990d7151e8 @@ -7,6 +7,7 @@ #include #include #include +#include #include namespace Botan { ============================================================ --- botan/policy.cpp 6d7bcb9a5926060492333a307fcc21a0294821bb +++ botan/policy.cpp e6c56d910f2460a72d41603c4a32b99aa4a6c145 @@ -221,7 +221,7 @@ state->set_option("conf", "x509/exts/subject_key_id", "yes"); state->set_option("conf", "x509/exts/authority_key_id", "yes"); state->set_option("conf", "x509/exts/subject_alternative_name", "yes"); - state->set_option("conf", "x509/exts/issuer_alternative_name", "yes"); + state->set_option("conf", "x509/exts/issuer_alternative_name", "no"); state->set_option("conf", "x509/exts/key_usage", "critical"); state->set_option("conf", "x509/exts/extended_key_usage", "yes"); state->set_option("conf", "x509/exts/crl_number", "yes"); ============================================================ --- botan/powm_fw.cpp 47a558712cef903c7205aa7d19dfc9f3ce1f8488 +++ botan/powm_fw.cpp b1a47e40d185947a51ffcb41597568c748b5fdda @@ -16,7 +16,7 @@ /************************************************* * Try to choose a good window size * *************************************************/ -u32bit choose_window_bits(u32bit exp_bits, u32bit base_bits, +u32bit choose_window_bits(u32bit exp_bits, u32bit, Power_Mod::Usage_Hints hints) { static const u32bit wsize[][2] = { @@ -78,7 +78,7 @@ const u32bit exp_nibbles = (exp.bits() + window_bits - 1) / window_bits; BigInt x = 1; - for(u32bit j = exp_nibbles; j > 0; j--) + for(u32bit j = exp_nibbles; j > 0; --j) { for(u32bit k = 0; k != window_bits; ++k) x = reducer->square(x); ============================================================ --- botan/powm_mnt.cpp fb243f2b18a781bc9327a79a7e0cec0bd60b4d21 +++ botan/powm_mnt.cpp a9e9d38aa4b3a66ef19d4974bb2e78625c77aa66 @@ -7,13 +7,29 @@ #include #include -#include // remove - namespace Botan { namespace { /************************************************* +* Perform the actual Montgomery reduction * +*************************************************/ +void montgomery_reduce(word* z, u32bit z_size, + const word* mod_bits, u32bit mod_size, + word mod_prime) + { + for(u32bit j = 0; j != mod_size; ++j) + bigint_linmul_add(z + j, z_size - j, + mod_bits, mod_size, z[j] * mod_prime); + + for(u32bit j = 0; j != mod_size + 1; ++j) + z[j] = z[j + mod_size]; + + if(bigint_cmp(z, mod_size + 1, mod_bits, mod_size) >= 0) + bigint_sub2(z, mod_size + 1, mod_bits, mod_size); + } + +/************************************************* * Try to choose a good window size * *************************************************/ u32bit choose_window_bits(u32bit exp_bits, u32bit base_bits, @@ -75,89 +91,51 @@ *************************************************/ BigInt Montgomery_Exponentiator::execute() const { - BigInt z = R_mod; - const u32bit exp_nibbles = (exp.bits() + window_bits - 1) / window_bits; - - SecureVector workspace(3 * (modulus.sig_words() + 1)); - for(u32bit j = exp_nibbles; j > 0; j--) - { - for(u32bit k = 0; k != window_bits; ++k) - square_and_reduce(z, workspace); - - u32bit nibble = exp.get_substring(window_bits*(j-1), window_bits); - if(nibble) - mul_and_reduce(z, g.at(nibble-1), workspace); - } - - return reduce(z); - } - -/************************************************* -* Square and Montgomery Reduction * -*************************************************/ -void Montgomery_Exponentiator::square_and_reduce(BigInt& x, - MemoryRegion& z) const - { const u32bit mod_size = modulus.sig_words(); - assert(z.size() == 3*mod_size + 3); - z.clear(); + BigInt z = R_mod; + SecureVector workspace(2 * (mod_size + 1)); - bigint_sqr(z.begin(), z.size(), x.data(), x.size(), x.sig_words()); - - const word* mod_bits = modulus.data(); - for(u32bit j = 0; j != mod_size; ++j) + for(u32bit j = exp_nibbles; j > 0; --j) { - word* workspace = z.begin() + 2 * (mod_size + 1); + for(u32bit k = 0; k != window_bits; ++k) + { + workspace.clear(); + bigint_sqr(workspace.begin(), workspace.size(), + z.data(), z.size(), z.sig_words()); - word u = z[j] * mod_prime; + const u32bit mod_size = modulus.sig_words(); + montgomery_reduce(workspace.begin(), workspace.size(), + modulus.data(), mod_size, mod_prime); + z.get_reg().set(workspace.begin(), mod_size + 1); + } - bigint_linmul3(workspace, mod_bits, mod_size, u); - bigint_add2(z + j, z.size() - j, workspace, mod_size+1); - } + u32bit nibble = exp.get_substring(window_bits*(j-1), window_bits); + if(nibble) + { + const BigInt& y = g.at(nibble-1); - for(u32bit j = 0; j != mod_size + 1; ++j) - z[j] = z[j + mod_size]; + workspace.clear(); + bigint_mul(workspace.begin(), workspace.size(), + z.data(), z.size(), z.sig_words(), + y.data(), y.size(), y.sig_words()); - if(bigint_cmp(z, mod_size + 1, mod_bits, mod_size) >= 0) - bigint_sub2(z, mod_size + 1, mod_bits, mod_size); - - x.get_reg().set(z, mod_size + 1); - } - -/************************************************* -* Multiply and Montgomery Reduction * -*************************************************/ -void Montgomery_Exponentiator::mul_and_reduce(BigInt& x, const BigInt& y, - MemoryRegion& z) const - { - const u32bit mod_size = modulus.sig_words(); - - assert(z.size() == 3*mod_size + 3); - z.clear(); - - bigint_mul3(z.begin(), z.size(), x.data(), x.size(), x.sig_words(), - y.data(), y.size(), y.sig_words()); - - const word* mod_bits = modulus.data(); - for(u32bit j = 0; j != mod_size; ++j) - { - word* workspace = z.begin() + 2 * (mod_size + 1); - - word u = z[j] * mod_prime; - - bigint_linmul3(workspace, mod_bits, mod_size, u); - bigint_add2(z + j, z.size() - j, workspace, mod_size+1); + montgomery_reduce(workspace.begin(), workspace.size(), + modulus.data(), mod_size, mod_prime); + z.get_reg().set(workspace.begin(), mod_size + 1); + } } - for(u32bit j = 0; j != mod_size + 1; ++j) - z[j] = z[j + mod_size]; + workspace.clear(); + workspace.copy(z.data(), z.size()); - if(bigint_cmp(z, mod_size + 1, mod_bits, mod_size) >= 0) - bigint_sub2(z, mod_size + 1, mod_bits, mod_size); + montgomery_reduce(workspace.begin(), workspace.size(), + modulus.data(), mod_size, mod_prime); - x.get_reg().set(z, mod_size + 1); + BigInt x; + x.get_reg().set(workspace.begin(), mod_size + 1); + return x; } /************************************************* @@ -165,29 +143,16 @@ *************************************************/ BigInt Montgomery_Exponentiator::reduce(const BigInt& n) const { - const word* mod_bits = modulus.data(); const u32bit mod_size = modulus.sig_words(); - SecureVector z(n.data(), n.size()), workspace(mod_size+1); - z.grow_to(2*mod_size + 2); + SecureVector z(2 * (mod_size + 1)); + z.copy(n.data(), n.size()); - for(u32bit j = 0; j != mod_size; ++j) - { - word u = z[j] * mod_prime; + montgomery_reduce(z.begin(), z.size(), modulus.data(), mod_size, mod_prime); - bigint_linmul3(workspace, mod_bits, mod_size, u); - bigint_add2(z + j, z.size() - j, workspace, mod_size+1); - } - - for(u32bit j = 0; j != mod_size + 1; ++j) - z[j] = z[j + mod_size]; - - if(bigint_cmp(z, mod_size + 1, mod_bits, mod_size) >= 0) - bigint_sub2(z, mod_size + 1, mod_bits, mod_size); - - BigInt r; - r.get_reg().set(z, mod_size + 1); - return r; + BigInt x; + x.get_reg().set(z.begin(), mod_size + 1); + return x; } /************************************************* ============================================================ --- botan/prf_x942.cpp 8878753f4bcf9a5a1f71ac387b1a02c7f0acd23f +++ botan/prf_x942.cpp 714523e7a9aeb580bbdf6d098eab344e3ad7d1f7 @@ -8,6 +8,7 @@ #include #include #include +#include #include namespace Botan { ============================================================ --- botan/randpool.cpp 3e6ae9338b29a4a63d97b189a4184b9e18413038 +++ botan/randpool.cpp 86c811993172d4b571739941f71b56ac51d85231 @@ -7,6 +7,7 @@ #include #include #include +#include namespace Botan { ============================================================ --- botan/readme.txt 5a24d1c1f9a0ab20413df3e5517d6c7f179c4158 +++ botan/readme.txt fcbc7ef51a881464e80d3638b2f8bbda8d81c345 @@ -1,4 +1,4 @@ -Botan: Version 1.5.2, January 15, 2006 +Botan: Version 1.5.3, January 24, 2006 Botan is a C++ class library for performing a wide variety of cryptographic operations, including encryption, hashing, authentication, public key ============================================================ --- botan/secqueue.cpp 980277872ed4f33cb3164ba90aa6f42e43bbd959 +++ botan/secqueue.cpp 5ccf8b1122fb6af815f4a56b424940d7cfaabc6e @@ -1,9 +1,10 @@ /************************************************* * SecureQueue Source File * * (C) 1999-2006 The Botan Project * *************************************************/ #include +#include namespace Botan { ============================================================ --- botan/symkey.cpp bf0815d2471b664035f262f40563c4eab7df9164 +++ botan/symkey.cpp 9b1f5232e3ee804994d5d335879384b0a10e9d0a @@ -8,6 +8,7 @@ #include #include #include +#include namespace Botan { ============================================================ --- botan/x509_ca.cpp a94a371ac8b99d786f17441ffd6995ff5e1a6f49 +++ botan/x509_ca.cpp aa8c7dcf99a2c1e9e8db19bcdf7a6fe9bf18eecb @@ -84,7 +84,7 @@ cert.subject_key_id(), not_before, not_after, cert.subject_dn(), req.subject_dn(), req.is_CA(), req.path_limit(), req.subject_alt_name(), - constraints, req.ex_constraints()); + AlternativeName(), constraints, req.ex_constraints()); } /************************************************* @@ -100,6 +100,7 @@ const X509_DN& subject_dn, bool is_CA, u32bit path_limit, const AlternativeName& subject_alt, + const AlternativeName& issuer_alt, Key_Constraints constraints, const std::vector& ex_constraints) { @@ -161,6 +162,13 @@ "subject_alternative_name"); } + if(issuer_alt.has_items()) + { + DER::encode(v3_ext, issuer_alt); + do_ext(tbs_cert, v3_ext, "X509v3.IssuerAlternativeName", + "issuer_alternative_name"); + } + if(constraints != NO_CONSTRAINTS) { DER::encode(v3_ext, constraints); @@ -213,7 +221,10 @@ } if(EXT_SETTING == "no") + { + extension = DER_Encoder(); return; + } else if(EXT_SETTING == "yes" || EXT_SETTING == "noncritical" || EXT_SETTING == "critical") { ============================================================ --- botan/x509_ca.h 06b345d0eea26ad6720442e1972a08604a668eee +++ botan/x509_ca.h 4867678a321798143b83d34c9d57519075e5bd50 @@ -34,6 +34,7 @@ const X509_Time&, const X509_Time&, const X509_DN&, const X509_DN&, bool, u32bit, const AlternativeName&, + const AlternativeName&, Key_Constraints, const std::vector&); ============================================================ --- botan/x509self.cpp 11382c4f93c3055cc2564138c9cdef0b5463caf9 +++ botan/x509self.cpp 4bcf4f6cd7119e7943d858b207c6eddde4fc8ff1 @@ -164,7 +164,8 @@ MemoryVector(), opts.start, opts.end, subject_dn, subject_dn, opts.is_CA, opts.path_limit, - subject_alt, constraints, opts.ex_constraints); + subject_alt, subject_alt, + constraints, opts.ex_constraints); } /************************************************* ============================================================ --- botan/x931_rng.cpp ee85f1d9ebc7be0d7f600386a1070641554a986c +++ botan/x931_rng.cpp f8054903a29e41dfe9ba76291d8ffc5e26bc8166 @@ -7,6 +7,7 @@ #include #include #include +#include namespace Botan {