# # # delete "botan/algolist.cpp" # # delete "botan/algolist.h" # # delete "botan/barrett.cpp" # # delete "botan/barrett.h" # # delete "botan/dl_cache.cpp" # # delete "botan/dl_param.cpp" # # delete "botan/dl_param.h" # # delete "botan/fused.cpp" # # delete "botan/lookup.cpp" # # delete "botan/mod_exp.cpp" # # delete "botan/mod_exp.h" # # delete "botan/mp_core.cpp" # # delete "botan/mp_fkmul.cpp" # # delete "botan/mp_madd.h" # # delete "botan/mp_smul.cpp" # # add_file "botan/big_rand.cpp" # content [2409e28c2f9eccf2f08383be22454bd462bb3584] # # add_file "botan/def_powm.cpp" # content [973942544f22958b8db2cf0fd91eb6e588b732de] # # add_file "botan/def_powm.h" # content [5c47338822f1eec4e187c542df0529cb8b8ac173] # # add_file "botan/dl_group.h" # content [bf3839e75b8ec5d4d8b805f74c2098ee7b4f9140] # # add_file "botan/libstate.cpp" # content [0c010d07846f8903044e1d56b158314c00a93bc8] # # add_file "botan/libstate.h" # content [7fb554cb2261eecafd96ba55ab777c2ac452ae24] # # add_file "botan/map_util.h" # content [4e6b06047d8fb0b0e35ae08b7983c57575814831] # # add_file "botan/modules.cpp" # content [cd75a13013e5d6083d9425a9a753f4d92bf13af2] # # add_file "botan/modules.h" # content [b28353b556b87a4f69147ee066bdbd12b2235038] # # add_file "botan/mp_add.cpp" # content [cb49c8919e7eccd7f65de3bef85d2a143a1c726c] # # add_file "botan/mp_asm.h" # content [a1f6a95c58b1a7036398fb843807d2016be2c438] # # add_file "botan/mp_numth.cpp" # content [4c55dcdaad744b0725dd5d7e489acdb6eb4039bd] # # add_file "botan/mp_sqr.cpp" # content [432313c19062bf16fd46c2f484b7ff2abde9e536] # # add_file "botan/mp_sub.cpp" # content [ad4d6e96032c60c4e8a5237dd3642263516b0978] # # add_file "botan/pow_mod.h" # content [d01bdba0bdab4579b8c0ac0df3d05b4054bb409c] # # add_file "botan/powm_fw.cpp" # content [47a558712cef903c7205aa7d19dfc9f3ce1f8488] # # add_file "botan/powm_mnt.cpp" # content [fb243f2b18a781bc9327a79a7e0cec0bd60b4d21] # # patch "ChangeLog" # from [c151668264b7969dafddfd7e2d3d363aa40a614c] # to [beb22f4654fb059a63b906c468b9c8fed15af7cb] # # patch "Makefile.am" # from [1086b6f0ea35d96bdd46455c7d97c5934fb77e5a] # to [23f1c46e322bd2e9d8fc7660c7ac0c935c3acb76] # # patch "botan/aes.cpp" # from [ea31ea6f8b2b7dc8edebeceaf6cd76dcea951c43] # to [36910ce25c53f6e23f10415c653d2e7a54f58b83] # # patch "botan/aes.h" # from [dacdc0de1fe5484610985ef059e9368f0d7244a0] # to [d49ff5b7d6e4e8d9ccf868ddf5bcf73b6a1d2b40] # # patch "botan/aes_tab.cpp" # from [475c0caff88d72d21371d3f0435634a375f1fa4b] # to [ef5e48c69d986f8fa73967194f5b4759c9e13882] # # patch "botan/allocate.cpp" # from [00af600bc30ed8c6ecfdea3fe716cd169626b05f] # to [56a088b78ca5962099fd16a131a08de2e903fa31] # # patch "botan/allocate.h" # from [825e8e9e89e22aba9d30c55f4e142b98bbab5dfd] # to [9129902ea8a05219f75168eb9272188efad37f4c] # # patch "botan/arc4.cpp" # from [7e17884686141d3b361384b0368c41ec4538411e] # to [f7ce3d818c61afd4802635c5c442c6d1e17e7384] # # patch "botan/arc4.h" # from [86febd85b9edfbe8a1ca0719659171b65f67bcab] # to [7c4390562e4ef982824e249298873a59d25c266e] # # patch "botan/asn1.h" # from [a15a8ffd094119897e5490f155ca642d31ef803e] # to [334088388bdaeaedb3be9e412eba21f1948af0e2] # # patch "botan/asn1_alg.cpp" # from [ecf1238bbee1ff0c59910a3baa65581f90683678] # to [665b7aba742c9e8b143a634c45377e287511fe1b] # # patch "botan/asn1_alt.cpp" # from [2fc51199398f1163aee5a7b4d67e43824c7d4031] # to [87e52c4c5cf8b39d0df5274453b0f6a8643c9ec8] # # patch "botan/asn1_att.cpp" # from [636c751ebe11b317a810f0fbd8b0a024f05c0e97] # to [58c6fe82ac89ac485b0c61fb628d838813d549ff] # # patch "botan/asn1_dn.cpp" # from [348a2b7b12c6a85b3cbb9e063781ed2112629072] # to [51b2ba4326c52163456a03becbc2249168ca3691] # # patch "botan/asn1_ext.cpp" # from [a8cc362726b13e9e81757a214fd39b684253a0ef] # to [f3680a101a9166ae78cf8a0eda8a73c9fb62f629] # # patch "botan/asn1_ku.cpp" # from [e6ef3eb1cd606ca2b6d063ffc7daa8dcb4f74fb6] # to [fe99df71ef816d3da3e2bd849ee41686553883c6] # # patch "botan/asn1_obj.h" # from [16357c964a2e7ee51e5501db6ff05971fa737aa5] # to [3ad02bee70f5b366cf0ba4db02242239a2ad4871] # # patch "botan/asn1_oid.cpp" # from [e52090928114f5d6012df44b91b02c0c353cd2a2] # to [cc34e0af65d596314b5f0cda21a766b591d3298c] # # patch "botan/asn1_oid.h" # from [f9678be8147d4e32f1836282704fd63060171924] # to [4d25477139ae7c1cc8524d89f44f5238fd6887df] # # patch "botan/asn1_str.cpp" # from [91c1b106a979607e99985bf4cc0b1378cf0d441a] # to [bfc6d126540833320f8929b6dabed7008d5c98d2] # # patch "botan/asn1_tm.cpp" # from [1c88ddb515e255c648e05944abf4eed36d03b518] # to [61b38e0a5379a4fb1f6331ecd404c3f30fac26e0] # # patch "botan/base.cpp" # from [6f45870998d3f60d680be03512d0ed1a40345316] # to [296db55bc172f248ad5effe0001475b37a04b64f] # # patch "botan/base.h" # from [f15a3205c8851a4a7413154b940c1ba0cab9c66d] # to [dc0a0fa5199199f4d79c37359fc2e72c9d6b1ab1] # # patch "botan/base64.cpp" # from [397126d19a42c0fb831b4201828be936e55fa2a5] # to [98965c9a7f80c7fb11bc863fdb60f27ade0a841a] # # patch "botan/base64.h" # from [a230286f7ddfefab2e317197aed37cfa407e4494] # to [7d3b17fd067410d4f45630b62f288d3b77c00c7e] # # patch "botan/basefilt.cpp" # from [18aab554ecbec7a50c1606b283c636e75f9bd1a9] # to [762c9f006ae634c2d935fbd34a86e8566f71077c] # # patch "botan/basefilt.h" # from [ba3cd0d8a3f0dc1ddeab8a7641cac1eed8f8b2cd] # to [1c2652eaa8d52203589e94003df6b89172530b1b] # # patch "botan/ber_code.cpp" # from [5142a48f04a95643b2b6cbb273e3d72b9c66be5e] # to [fca2b4d8e8ef99e4da32e42c4d3366b161d5723f] # # patch "botan/ber_dec.cpp" # from [c15980c2152172bdd3f82953e8f631799512ff23] # to [cece03873562a6e12275e03485f249afb4e25628] # # patch "botan/ber_dec.h" # from [380987e05bd500b7663f5954bdb4a7c8b0e84241] # to [7455c840d03e605912f08c95535bb31ce18ecf3b] # # patch "botan/big_base.cpp" # from [457e25de9b908c143815af89388f873a9ed57d1c] # to [7b7a61902c43b9488128d60b950a1a9ec6f667b8] # # patch "botan/big_code.cpp" # from [9b6b6e6f233069e72f4b621d7e2a867bbed3d5b1] # to [016dac5924166630ef4d213ce59811a7725247a7] # # patch "botan/big_io.cpp" # from [17083ec29a3235fba2817a5117cc4c303434df3d] # to [69a6680403cf935f3cff67a9a0fd9709d7dc77dc] # # patch "botan/big_ops2.cpp" # from [7cb04ca6277c03495e7e1035f4f0c5d3ca652e60] # to [600fa64bbc1306e4d48e6717baf28dccb97a4bd8] # # patch "botan/big_ops3.cpp" # from [033d775b361c8e20acd3d6b67faff41519e0a4d5] # to [ed35714c74e8a46cc83510b94aa88252759055ba] # # patch "botan/bigint.h" # from [0f4e2101aad1e358bfbba6a7e5b136c42566786c] # to [2f22d329675f1cdae7ab5c2824067e58a4467f30] # # patch "botan/bit_ops.cpp" # from [d07b224e9e1d15bb7ce59d0a374e236cd803e895] # to [9548063db26062adee735f47a045a2e8b246edf6] # # patch "botan/bit_ops.h" # from [15f92e1769a8715806856e0d5a64b571779f44bc] # to [322ee2eec0304c996d7816aba3d735a47db66b47] # # patch "botan/blinding.cpp" # from [409b0a4f351117490772f07a5328ce0ec88a420b] # to [4b2356d837f6957a9997bd35e2334a044e3ed5f6] # # patch "botan/blinding.h" # from [93d726432666ec51edd74003647882948261d9fd] # to [ac3050bb8acdb4d1fa77680e7c4602ef30778021] # # patch "botan/botan.h" # from [b67160e0ce2e91677445439823e4e020963551d9] # to [76631677430121056a988cfa6e8c53112a813a5c] # # patch "botan/buf_es.cpp" # from [9d7a0ba8efe806a4088786015e31a41bcf73a433] # to [4ce4aba6edc36d7a36afe4c274d02134f641fed9] # # patch "botan/buf_es.h" # from [92c7fed684a29fa220d3320c0b3ca431874ddc8e] # to [b2d0dfcc87c0ef93a415b96460fb91650bab50ce] # # patch "botan/buf_filt.cpp" # from [42c8a97f415ccacfe8b3ddaa29df18151b5dc6a7] # to [acf427f400125c1e9427da10f35d2a1f435adc4e] # # patch "botan/buf_filt.h" # from [82b9c858e60af6bf816750888764e9330a6125c4] # to [7282bd3d30c910df817e76a6c9946c129ebfce26] # # patch "botan/cbc.cpp" # from [482ead7cd979dedb9264dee265141f3f62cd8b24] # to [d2dba7243726bc71889bcfcf69aeae09bfae5f88] # # patch "botan/cbc.h" # from [0ea0edd6d72aa5c8baec83cf46d075e326b05006] # to [8d0a2b5c936d2be6750f3870cab6f4f262358751] # # patch "botan/certstor.h" # from [0ac4c8644a5d17b7adb2868f37fe9fcc8adc310c] # to [f76ddb23c18ad7da273da838831ce1b4f9e99e1f] # # patch "botan/certstore.cpp" # from [d9840e20d737606905f1b846de1faa49870e4357] # to [4decdbbea3ecee7c3db7a80ba2d58a2aed60a61f] # # patch "botan/cfb.cpp" # from [fd5cc8fd41bf529237261b94a0c07749130aa71f] # to [16a90ba04269adf38b456ced5487f410d9a15511] # # patch "botan/cfb.h" # from [283d95f7f0336c5c97242104439f666b5d190e13] # to [bb45d558c81fc04ab816789c2c8c83eab422e979] # # patch "botan/charset.cpp" # from [4eefedeea00d833c01b8968cf09a391821389bfe] # to [f095fd1d76e6ae1d4458edb8eaa602b0fdf4f3b9] # # patch "botan/charset.h" # from [0a2fc0cf36512cdfbe8725d7a08cf7c239638cc5] # to [3fa5c0845715e76ec0b071b5b550fea6d533ad43] # # patch "botan/conf.cpp" # from [5f2a4cb8d45511ae6ee082231974fc5da0150ef4] # to [c5eecb1961bdb03dae462c2fc13958a225e269ce] # # patch "botan/conf.h" # from [5d5aea8872719a387a22c036edf441fe140d0a60] # to [7b0d0cce1b5ead63091611fad7a2e9cdb840ee94] # # patch "botan/config.h" # from [985b707216c13e7cb2684c869166c4dc4e007a45] # to [8ba878178154ac468e2db83883314b2a9a3a223e] # # patch "botan/crc32.cpp" # from [dcbaf9e6729d96e7218e16761f4fdbd1e86a8348] # to [37a171205e892360539205e21f099fcf788cd33f] # # patch "botan/crc32.h" # from [14797da7c705de3d822da4419a90d8eced1dbd1f] # to [f0b4e516463a6bb833eaa5cbfe6717b831860e14] # # patch "botan/crl_ent.cpp" # from [4198f9e3689fab5978bded5b64f8f71a8f1a1ea0] # to [7bd2c10f75bc3aeeeb35b9c70c63d5e1fb8bac87] # # patch "botan/crl_ent.h" # from [cec8c4510b2505708ff6dd2bb2a6d8e60ec792eb] # to [6da618c04c39d66ac775a4c7483410ba0b8619cd] # # patch "botan/ctr.cpp" # from [e76cf9a87a8daa959b65e3ddc66014b6bef46427] # to [68b39a43c1e77abc1e97b2c89fa3c5e4fa21b4ef] # # patch "botan/ctr.h" # from [60b1b31f804d1f2808420b3869f6c1141ae5ba19] # to [de9842ca4641c8e4c759178799af038053da3516] # # patch "botan/cts.cpp" # from [76480a05851111771df7fb35dbe1f01a0caa3d3f] # to [48dc412226b16f2be5f7502b3fe7888816724866] # # patch "botan/cts.h" # from [c458d765007da986f16e0775a69a8635b8f69742] # to [b3629ba48d49a2501e447a48eda76850f34130f9] # # patch "botan/data_snk.cpp" # from [9b5fa3d71ac32b238fcdc22f8ae1af48ebf141e2] # to [72e9615bb9e131d1ffa6f97e19f280a26d407617] # # patch "botan/data_snk.h" # from [5ff5db19807ce5b4bec7589a89e670b8801c01a2] # to [2f0b3b675f98fb0e5133a998790fc0dd55b4c30d] # # patch "botan/data_src.cpp" # from [3d9619006e9ea1a111e099ba7d4738887485a36c] # to [43ac60765c3ffa36be55d080827411575510bc3e] # # patch "botan/data_src.h" # from [e60fe6c6f970926fbac49b25bdad2e1465dd11f9] # to [3c1805ef300f5650a79f4ad6c1d0151f478cdf3b] # # patch "botan/def_alg.cpp" # from [6149d258796a049d0bd371a8b537a35fccb4d09d] # to [b3f2228ad990d77ed9f3c44715153b2993cb5cf5] # # patch "botan/def_eng.h" # from [cb6c6b9768a0e7c77e67e9eef6598904d85f3b0e] # to [22f1fd366a3b8480b4101127aaca73ead0efda57] # # patch "botan/def_mode.cpp" # from [70796fa32f99c175755d464b29b9ebed8be84d79] # to [a1267f1d3cc1c225d91dd630ff5231f6af48bae2] # # patch "botan/def_ops.cpp" # from [18c63eab3d6ada615f8988fd13f0a4d39d218ae3] # to [367e4d60c52f360117249e7b6c1d3804ca0db1f4] # # patch "botan/defalloc.cpp" # from [0a8c4ea4f0ff0831f906e30415ab78d3fe0678b9] # to [d856af43a6ef36e704887ff86d7639d7d7de274a] # # patch "botan/defalloc.h" # from [f3cbe94e43909da2f169b34e04217b2946fc429e] # to [f543c96588ec45e303a700a3014cafb3a66b6e56] # # patch "botan/der_code.cpp" # from [7d1a406cbfb6bef841797d6c44fe49d5dd730c03] # to [2a13e0688e91eaf456bdf5db60c77fa371060849] # # patch "botan/der_enc.cpp" # from [f5bb0bb31a85670d626e3c02c35850438a8fee4d] # to [e70973207fdf7ce3ad5a9c7c5c48f51a5de10ea1] # # patch "botan/der_enc.h" # from [612aef07516329e81624156d1481208dd64a88f7] # to [93f8ef503b4a79e882c9ca9e6a4f3018b61d9821] # # patch "botan/des.cpp" # from [93600b024d9dbb9dea04535016120e4ae8f1aa3c] # to [789f5036773e7a823b36016967f0b351686f0e5a] # # patch "botan/des.h" # from [37d4e302b7efcd7abbdb1a5100350bddad8af1c9] # to [fa8ae2ada50a692c3eb15d3e6b21e4186ffaed3c] # # patch "botan/des_tab.cpp" # from [dcdc96f398b9788d6b10c5fc08e942a6cc65b87e] # to [a45c36b824fabc92baa7a6d2e4b2d1a99f5218b7] # # patch "botan/dh.cpp" # from [52df677e2549c49115b537a9bcb7d99073c4e7f1] # to [27a34a0adc82564aeaa30832cea48fa4bf2d7aee] # # patch "botan/dh.h" # from [0eb696b0a935052659c8a3bd123d0e0f4f965a65] # to [4fc7d2c0deac3d48e36292dbd26e6a7d625d0882] # # patch "botan/divide.cpp" # from [71a6766759d8ea7a4f148fc7187b99c17168502c] # to [40f8a31ed5731ea3bcabb611198c770e1f62774f] # # patch "botan/dl_algo.cpp" # from [407d1a5e155d69d0248bdf003b1d4ae1c59eb07e] # to [d9f8c515eae2c8c6ebf98824b3207a55d7ad9068] # # patch "botan/dl_algo.h" # from [ba177f21543053329ffa01070970973d5db39a52] # to [33a24d8853cd27257f062bdcdc0c0d638e727301] # # patch "botan/dl_group.cpp" # from [c335b79e38e853a394fd76e734ea102480cf6042] # to [df34a048f075aba4a2fb9d27c2e40e219d3cbd4a] # # patch "botan/dlies.cpp" # from [b390b695f810705238efe69a61dd63b6ad945135] # to [17ac2bfa1bf4c527c5b5ed886da76c9c8ea1df4c] # # patch "botan/dlies.h" # from [220cf9a63bc846e59dbe6c10b59207b25259131e] # to [0a3b5f38ec3c4216823fd8fbab906ff8697a8558] # # patch "botan/eax.cpp" # from [8dadb5fff8caa3da4342acb2206ba165873564cb] # to [e23c313cd6eaa3b5c0e3209f665d2bd5ef96085e] # # patch "botan/eax.h" # from [616ac13b534dbba4144a76bd601259cc59187bc7] # to [193bbdd18e398ac054a8e05ae553afbdec291c24] # # patch "botan/ecb.cpp" # from [519758ea66834c37ce4da85b634e1f54fe1e67f1] # to [281a354f3c97e99d8e808137d78c7dce5abff8ee] # # patch "botan/ecb.h" # from [43b8217ca2da247c5d3f5169e227ef0a2cd09ce5] # to [37d5e3f25deeb99b34c17b492649c422e1aaae24] # # patch "botan/eme.h" # from [4412c54e61d8e70e2d1f42e5bb48ffb1ab1fb92a] # to [b22fa5c9c91835dcc5f0915ef6f7ddad2ffb1c4d] # # patch "botan/eme1.cpp" # from [096712e2e91e96d4684e5cc447bd44ade28e349c] # to [e90e2aba0e7cc71829a641ee4f9077a5bede20b6] # # patch "botan/eme_pkcs.cpp" # from [0300e9b5bff3abc77f2550e099f9079adcc27535] # to [b6d2dcbe4674c075e759ada4d4f8a3ff8759977e] # # patch "botan/emsa.h" # from [8aed2c73d0d4b9b0e8dd48331d00d99475d62b17] # to [b2b17af13aba1286f993907e80aae49e4c3fb071] # # patch "botan/emsa1.cpp" # from [3256c2a0d2f330e83926775165e5727a69db8c89] # to [c1f50b7abac1a37e8bf7dfcb06e36beda025dc85] # # patch "botan/emsa2.cpp" # from [cc579ea8d68707008de96718e57aa45744ba7d2f] # to [a4d8301f23805ba4bb2554591dfc20e373bce4ca] # # patch "botan/emsa3.cpp" # from [7ceb6622645006dbf646a9597260a04167bfd248] # to [367b509f38995bb4978b8f514239c97989fb63b3] # # patch "botan/emsa4.cpp" # from [e34dfab00b372e779b31be6b6d935d88177e144c] # to [a45dd0f15cdb2cb8f81d8493b44248f206bf44f2] # # patch "botan/emsa_raw.cpp" # from [4f061b051bf6e32e48f4e56ee2f2b9a12054e076] # to [3b8914e43991c3700e12a01185d057491c08db11] # # patch "botan/eng_base.cpp" # from [470b429437811de062b605a3eef110f890be77c4] # to [9eac0e75637f3f720e8557654829d8e5833646ff] # # patch "botan/engine.cpp" # from [f9f3e140d9d596fba3bdee49d93f3348cc02c799] # to [af6d1fb7827625d968315b490b84756861c17f7c] # # patch "botan/engine.h" # from [bf1afaedad957edbc26e34b4a0490cc156e6789c] # to [f3677aebcf825ab278fc89ad154646b7133ae76a] # # patch "botan/enums.h" # from [d11810103ab6a83b78ec6248a12f8e40db56121d] # to [c04f2e670414dd7dfe11091e7f63e82bf4242fd4] # # patch "botan/es_capi.cpp" # from [2d8b12afebb00cf798cb8d4c42defad1dcd8b181] # to [4ac7b3e52f1d7a16aed591cde28ae620df18e5c2] # # patch "botan/es_capi.h" # from [addcb8c601219d5a95e9d8b5e8b93026269b6075] # to [72dab1a57f7e67a2eb34eeb6a43a35441a2a9b47] # # patch "botan/es_egd.cpp" # from [16c13a4ab4865ebcb771d9ddd251e4a2838fb64c] # to [b5a2e16b8872dcd26f83064797a8398a8fe0a307] # # patch "botan/es_egd.h" # from [e5d389bab5e622f5438183f92778c314347f6565] # to [b81212d62810f7b8758c76192e746ff403d4a9a1] # # patch "botan/es_file.cpp" # from [0ccbd0d7f16404e39f3a7a3c664a867801cf39ce] # to [8485aab5b2589450af2d7915919db7b03b2a7fa8] # # patch "botan/es_file.h" # from [a375d7011922508810394364ac39a357a5a75b83] # to [fa7288fe9d295666330e1b7f8207ecf32a3c072b] # # patch "botan/es_win32.cpp" # from [e9b9c76342a863825e2a60c12de29627e4f7057d] # to [701187eda7ca149bb8c42e72f3bb523954b2d54e] # # patch "botan/es_win32.h" # from [1c730fe9b6a9a522c7b61e45c055b1f60cf2a8f9] # to [0251e175291cd4029ae60cbcf588a04dfe62c76c] # # patch "botan/exceptn.cpp" # from [f16b034aa7a23055e0b00613752e762e3c5edcb7] # to [d83be5a04572fbed2adad3785431999aad9b7017] # # patch "botan/exceptn.h" # from [0f90c643393d85de7e81ae26d6a57e0f52fad8b4] # to [2f717eeccaa793dd63844070e3c5a072fa55bae6] # # patch "botan/filter.cpp" # from [5df2e58f9ed1de853a151ba0ab43fa0faa50a0d1] # to [c38f149e29ece60b4d79fd2b4aa1746bc98ce37a] # # patch "botan/filter.h" # from [aaa4e5977156b60de4d6cff9aee6d6ff0352d939] # to [7b951b0e26db1861c7a779fdc8e5cf83dc743cbb] # # patch "botan/filters.cpp" # from [d8f8d8e488482d394b59ffbe7d666ab190698914] # to [dce61805189ff431083613a331ab42b26aca64ec] # # patch "botan/filters.h" # from [dba4116f6d25355809ef86ea71b64a4d031029af] # to [32de15889ec656110b6a1b5a27f22fc86dc65622] # # patch "botan/fips140.cpp" # from [19b5950901dd4973dc066cab00220fda9bd34d1f] # to [e42e938b93faaa82ff8d6861ce80d2bf6ab78048] # # patch "botan/fips140.h" # from [b975066cc64ce52da09af0ba5ed907e786e426b8] # to [a48903c8bea50db118624d398d335d506967608b] # # patch "botan/get_algo.cpp" # from [83b4c671f852dbf233ce7da7c81c1f8e63e92e46] # to [89ca5531b77ddcbf202cb930d4fd3f863ee38504] # # patch "botan/get_enc.cpp" # from [3691eb8c87161a3ec8897faaf12e6a081aaca466] # to [8840ce2708a4b2989efef886d8a2c9f63c21993b] # # patch "botan/get_pbe.cpp" # from [ce4d99a19ec0e893483d458e57c8ff86a32c167d] # to [4d13f684cca1485575401f3bf3c0563dac19a318] # # patch "botan/hash_id.cpp" # from [30976df969f81420191833f90bfe0f20941a6c8f] # to [ff0dd27712838713d976bd0f5e13875c9f73ea1c] # # patch "botan/hash_id.h" # from [518f07b3e6f9ec8ebce5e01bcaa41d005fc509de] # to [e807331d09c89bd23cdbeceda4ede53f1f2f18f1] # # patch "botan/hex.cpp" # from [cb1b85c614144b7cd3ab2308a1c5221ca43a98bd] # to [875cfbfe15cc074195bab031f907de885496f311] # # patch "botan/hex.h" # from [2bba7745b808634f2ff705e21ad9a6d20f6be763] # to [065a18cbf522daf1c6283587bec607f788be2e46] # # patch "botan/hmac.cpp" # from [f382822b6dfacb4472e9b4568289023ffab33f89] # to [219e669226db3c9f450e8d434bbfefc11876070e] # # patch "botan/hmac.h" # from [d608aecb93bd9d0d3a9fa47443696c766e0c7a14] # to [953953c1a07de51d1333f2370b515799642a26b4] # # patch "botan/if_algo.cpp" # from [4ee708729d33713d47c64828d1d43c646690b4b2] # to [b7a2ae76d1318d2e3b0e61d8c9ba50a2b5e23c0f] # # patch "botan/if_algo.h" # from [d8597f0265745faa4743802b44de16660e326e5e] # to [825399a5fbc274c40ae764c0ba85fc89654c2091] # # patch "botan/inifile.cpp" # from [98bff4e028a824b8233181bd06a12b5ecb652e7b] # to [7df6bc16b85ae545ef9ea941a185f7993d5b0321] # # patch "botan/init.cpp" # from [fcd3ebd72fbe0bbd544a43cdabe5dfada6d3905d] # to [9ea095587401c32f31aadec310130f6865711409] # # patch "botan/init.h" # from [78786baa62040f7edeed7524e9529dfdce70401e] # to [825be479b4ab221415be4b0fcd663df176337c5e] # # patch "botan/kdf.cpp" # from [da6521d210af842b78eaf9a32e6f51a80009b079] # to [65f28a1f1a94a55e816feb29eb219910dc92644e] # # patch "botan/kdf.h" # from [7d0cda0fb2a44516987c1e1508df26cf1016e355] # to [1124198e5c3117544d112eede2a0d4bfa772341c] # # patch "botan/keypair.cpp" # from [95b67905dbc153558bdd0d8addee5eb6b1568356] # to [91cccf8c1a165d8e0d4da18b36d38b1b0e06210d] # # patch "botan/keypair.h" # from [50f23526d06bebe6b49881342da49dc2fb0a19f3] # to [a0310efb60669a0abd04b9065c8b7e50e4e10e7c] # # patch "botan/license.txt" # from [8c0441f989ad0c3c9cb5a463dd4382154187e04e] # to [0cac4d68711b77376ac6b70d8ca304da89cc613c] # # patch "botan/look_add.h" # from [18561a6954c6011dd60b458c5affe02e73a6a0c0] # to [4f1e00b7a693a682a64f80a61d2a56aa63d6f37a] # # patch "botan/look_pk.cpp" # from [870251a124f84ba2c175753b2946377abbd2c4c9] # to [13453c6cbd7be65bf71e38b40f14a8e8c3851c85] # # patch "botan/look_pk.h" # from [b868af6a79123e844310d943647cd21b63fe5d34] # to [a579cb37238f0eddb5e33277379c676e724f235a] # # patch "botan/lookup.h" # from [aa7bce79307989caf3699175148af3d3d3ab6481] # to [7265880bb34e5c13431307e2e57a57813540a5fa] # # patch "botan/make_prm.cpp" # from [e7b6ad43b9f2620d6993fc1c991918b541b5dc14] # to [7c867a6d50b8d9d804900d2c634304693d8d5ce1] # # patch "botan/mdx_hash.cpp" # from [7549dd02bb181e14f09af48923bd39f47ea7d235] # to [e1df6c859d3220d0d6dc4347f366e13b08e2ef9f] # # patch "botan/mdx_hash.h" # from [a38578d1f39ffd7ffea279a92e3a6d9e42f3f74c] # to [5bdd8beb52cdaf9e8ac1106a542604bb7c309c64] # # patch "botan/mem_ops.h" # from [02ab0ae42b9c6bf677886935d8dfb85e447ab6ba] # to [92bb05e9488560a8270d4a78b8fbb1ab78fc2eba] # # patch "botan/mem_pool.cpp" # from [cc2313bdb2ed78668efea720ddd78929c8afb461] # to [4071bb398b36e883145b5d9d956ca14dd299f093] # # patch "botan/mem_pool.h" # from [96e6c390b555075bc0335932142680360ef49f8b] # to [dbc05bb8b4dfc24bd07cfef84fd84d5541e8ff43] # # patch "botan/mgf1.cpp" # from [495b1312a4936391dc3d0b246f3849e02eb830a2] # to [bf33f05697c4578337fc9cc1410e1a4e84975990] # # patch "botan/mgf1.h" # from [07c9dbfb8d70d446eb0735b9e7a0109334a728e6] # to [289afacc20735881b14bd084a4d170fac8703c9f] # # patch "botan/mlock.cpp" # from [d357780c56771b5779d6c0f95ff7a20ef3f81898] # to [4755235e70fac894c364c327397ee9fef15658e3] # # patch "botan/mode_pad.cpp" # from [6e13929f903c51c67f4f9cae3f1636d15a6e94b1] # to [f43891fdce0ba6fc32bfdee10553bb44f7d34937] # # patch "botan/mode_pad.h" # from [0ec59170055c96be7b3e7a70aa3a4e25baefbfcd] # to [9798f98d1e290349efa42220ed0690bdcb45189d] # # patch "botan/modebase.cpp" # from [f55df855ab15cd85c53f74fcd09019136969253c] # to [cfe177154a0a7dd9006f87f55f17956c3d5bd087] # # patch "botan/modebase.h" # from [9c6b1c98f71e261ecd853037c2a6f2a6abf4a09f] # to [11a987c1e68cb7b68203f307febd5c8ab7a54fdd] # # patch "botan/mp_comba.cpp" # from [fe79003f739437691f78090af30ff3c0d08c7000] # to [ea841c092b0697f5297fb978cff5d71eee142149] # # patch "botan/mp_core.h" # from [5f8d926528ccb7e579d3778bfa61c6fc2d388b43] # to [af2e3afc3189ae2734b60216033ff361edbfda6c] # # patch "botan/mp_misc.cpp" # from [14c95fd2efacea3ba45e7f29e71a676ef834433c] # to [403da43006f3563e3f7610b2ad6efff0034b5809] # # patch "botan/mp_mul.cpp" # from [1a89216eb5fb97faaa1b948ed019813cf4404d80] # to [c22efb440d348bddd92f117a37a3296f112a92e9] # # patch "botan/mp_shift.cpp" # from [b0d06068404ec8818092b23bfcbdbafe0f804be6] # to [325a72292b8477bba5aecfede199e01b6ada1992] # # patch "botan/mp_types.h" # from [3d35d7b7414c08f0516573f15d99ef5db3b977d2] # to [e9a7d9daa17a17667fc62e90f97ce660092de0ad] # # patch "botan/mutex.cpp" # from [5178b950cb9ac2c1e726d470bd9edf1e2afb4afb] # to [879ae577f26b33ad7039c8c63e3a5e1dfd8e3866] # # patch "botan/mutex.h" # from [28413d972111f69c83901ddd9909b532008ba6f2] # to [8a7e3579fcb04cc12d232b5312044486a44508a4] # # patch "botan/numthry.cpp" # from [1a9aad79b7e3041179f8f107778421257d2c7bbf] # to [6a5d1c3ce4a22e0008ef01684c5b9d129dcd23ad] # # patch "botan/numthry.h" # from [7cd9a6b6f82dfbcb7ae04d7ecbca6a97fba83d67] # to [e7a209c8c3b650b8627798c12d01a57a009dfe89] # # patch "botan/ofb.cpp" # from [c9f5e8a40fda1f792eb91972cb72beccfb14e1d1] # to [ce7e2a5f1d9f76971ad66c6b79015a7e894fb506] # # patch "botan/ofb.h" # from [b829ab377c4d4ffd01d08317ab44af8e94b52ed4] # to [88c86eb33b448ac17ad5d533224ecfc902941d3a] # # patch "botan/oids.cpp" # from [2c16a47ec99aa367578e36a96ddb52e4c1315de8] # to [10fd1940bfb9469d8cc4c8833fa0a28bd5ca4674] # # patch "botan/oids.h" # from [ff39689a4be354d6e3f7572d8685a35d129f9f44] # to [3005c408ccd28f21be6d7e1aa621873059e4c552] # # patch "botan/out_buf.cpp" # from [0389fab8523d683166eec1bb43707c2c68e89dd1] # to [2489a9bec82d69346621189012595616f879bf93] # # patch "botan/out_buf.h" # from [1a0f690209f84f17abbee097aabbb8822dbe0f1e] # to [41a263e3362e4387260349e069f3f60b80798ff1] # # patch "botan/par_hash.h" # from [db8899df56e0764c6d1c01cbecf5e8c665fad98b] # to [71d7dccfc77480d0978ed5aa945b8feab9a5e945] # # patch "botan/parsing.cpp" # from [18bc352e3dcbf702bbd5aa3d4e6958ce9e76ff85] # to [0ec54baf44d58e0db2cdc5e6a188aa1ed7bf5200] # # patch "botan/parsing.h" # from [cc614612daa8f7957ead652e9d7b6155d60e06e4] # to [f75201b87b93e3c759253685c584e989ce529711] # # patch "botan/pbe.h" # from [06e59820482660316ca05b7039f35b3705c5acf5] # to [f70f01ec9efa2119a6a28519697bc0d5da8167f0] # # patch "botan/pbe_pkcs.h" # from [3c1f0cfeb63a5ef197b4d25078183f124fec7fad] # to [13c9b42c84107045259fe22f8723b2a7ec81da85] # # patch "botan/pbes1.cpp" # from [649e6fcfe4fde90cb7423caaaa7303df9e8b169b] # to [1d5afb55ee77c3cecac5c76f763c82315f82bf6a] # # patch "botan/pbes2.cpp" # from [402a6ec148314cb96273dd54f43360b47a0b0d45] # to [6aa65fd5356d5f5bbb3f5d645d9e0cce53b1484f] # # patch "botan/pem.cpp" # from [fe377ccf9051816213ded97776eab82c4f7ebe15] # to [eef9e1120e7547f53786198636a799358f419260] # # patch "botan/pem.h" # from [be2e43f828cff05d5f0ae7b02ee81adf0f1cda8d] # to [fb888d3bc2fed16ec4745cd5179bef5cc1f13b23] # # patch "botan/pipe.cpp" # from [774a4992b6b17495388d6087ada4cae49e2dc9b7] # to [7c3a10cad87f8009fa0b163890566b82220bbfd9] # # patch "botan/pipe.h" # from [2504d23b4aab823fa55180a13725a6d9f56e893b] # to [22989c7933461dfe48987a1ed8c7c482e4c7771c] # # patch "botan/pipe_io.cpp" # from [b91a0b4c82f460a14549cbc89580dcaab1aadd47] # to [b834ab95d290b21877ea8a562403b8ca76c10a6f] # # patch "botan/pipe_rw.cpp" # from [b8b1c777dbee7ebf724531dc9195a7636e23b0e0] # to [98ddc7cd79353b886929f6706a8404bee55aa953] # # patch "botan/pk_algs.cpp" # from [4db1878384c2944381591a79e7d615f5d638d229] # to [4eaf5dca76443211e7486ca651ae5521d7cb7181] # # patch "botan/pk_algs.h" # from [fb2336a4e5ecb6c99ff27495ac9a2a2bda8dd965] # to [a74b349952353849520a8ccd1547b22f4158917d] # # patch "botan/pk_core.cpp" # from [d0e5257141362be13da44c2e83b5d5d90c8925cc] # to [0389b1a4f1cd6c7c40ffb64d730529968ee58307] # # patch "botan/pk_core.h" # from [10477efff2a9f24a8bf0119ca6d341a190563df3] # to [bcdfc58a47396cdd6023fe343683ed34d6cbc42a] # # patch "botan/pk_filts.cpp" # from [a854cd0ea434d4376b575936345ef2a049d5b047] # to [f0b3034376d079b3c0e142fdf137b747eb59c493] # # patch "botan/pk_filts.h" # from [0d1647a1bdf4cad2f490ddd0e4ebce0784955bcc] # to [af8f30ddc7323c166cd55b0440ed913fd7ecb014] # # patch "botan/pk_keys.cpp" # from [10fcbc235a7fd98607ef6e931b97be3931fb64c9] # to [e96e015886270680f7e9fe6e72dec0f3b45eb717] # # patch "botan/pk_keys.h" # from [708654f66730aef50e3ebbeadeed4f51befec530] # to [4c027055ee9f940af7a6a19bd622f8ebb7f49db1] # # patch "botan/pk_ops.h" # from [3528538ab9d79c80e3f1ca31883cbb0a470451a2] # to [70200faf214f2f97b8b9c119ac37938532dd2905] # # patch "botan/pk_util.cpp" # from [07159fe81e167b59fcffd638f755d4672c8c42fa] # to [63673b6371f30e1bc06a7ff8e06ab6b9d998bf8b] # # patch "botan/pk_util.h" # from [f6402de5949c76a9788e261361c7317fd3b18f5b] # to [e770acbba30020bcf8b39caaa1c0d42f49710023] # # patch "botan/pkcs10.cpp" # from [377921951d6c212d506ffd85875229b831ae6769] # to [ad6427f721304d7504519f0aa9f7c7e1faf684b2] # # patch "botan/pkcs10.h" # from [7fdfce431e83e7cf380f877e3b7c726f3d698c1f] # to [d1509c9fa08d51959265aeb029078e937857d6fe] # # patch "botan/pkcs5.cpp" # from [cf89d6b74fd2e397176e49e4aa0de7b644ca642b] # to [191a70d25a288701ed5be7d8898129dfe484e348] # # patch "botan/pkcs5.h" # from [660436fb11b2f632b3dba051539cf93d023ffaa6] # to [8f8553ead419624b1aeb3041c2d84e2ec9cc4a96] # # patch "botan/policy.cpp" # from [f695e97b7eef3d49c960d3044b65b53a049e2364] # to [6d7bcb9a5926060492333a307fcc21a0294821bb] # # patch "botan/pow_mod.cpp" # from [d329aa0377ba3cb1b4249c155cacadb76cc0a43f] # to [622ad0b2f9cc40a01000c02e1e486e4bd40140b6] # # patch "botan/prf_x942.cpp" # from [6510c500215a92d3031d2f143432e45ed95c314c] # to [8878753f4bcf9a5a1f71ac387b1a02c7f0acd23f] # # patch "botan/primes.cpp" # from [6ece0b544fbb2d23c817999b4211dbd5c22cc092] # to [b6bc7dbb320ff24cdf16689cb57361551d6bc693] # # patch "botan/pubkey.cpp" # from [3fbc4d1720dbaa6d720465ae742d8862e02c1196] # to [82d0927ec5f390da00feeca1e23933c997c18df4] # # patch "botan/pubkey.h" # from [f98be2d1a95ff8e0cee18613917206aa7e1c6108] # to [7ffbfc8f5ce3e9b1c06623dc3d6adceb4c582e17] # # patch "botan/randpool.cpp" # from [cd54358602f6d3d1be416d1175fbd586cf711be6] # to [3e6ae9338b29a4a63d97b189a4184b9e18413038] # # patch "botan/randpool.h" # from [ac16cee42189e9d81f1be3927e6ecfc76240fee9] # to [bb00fef73a9af0b71f44a5478a668c8aad1211b2] # # patch "botan/readme.txt" # from [2e95992aa746384a01dd6ce9c683f040a15539ae] # to [5a24d1c1f9a0ab20413df3e5517d6c7f179c4158] # # patch "botan/reducer.cpp" # from [af05c42c789bbcfcba6ee93371320052a37f7bd5] # to [c9bfcbf3595d7d6f59a1e04275a68eb89054b10e] # # patch "botan/reducer.h" # from [3f84481f5c8f523e7d2e2aee651aac211d88b16e] # to [5958c1b425b899e44d943db154b4707818789d2b] # # patch "botan/rng.cpp" # from [7c1cdf73c8815e9bc2dbe381e910c999dca9154c] # to [8139450d8cf07f579a396a137018a6a0d34d488e] # # patch "botan/rng.h" # from [23a42a4209ff8c1050f7d12d8b6e75696f549067] # to [b7323e6afbef620294a9ade850838a996bfc588f] # # patch "botan/rsa.cpp" # from [fd012f7422edfebb9f6cc0c979d0e03d5ef36c22] # to [e5fb31ae1075baa340d89177d4757f574cf2bda1] # # patch "botan/rsa.h" # from [f30ab1f3965b3f7f93c32a1acee311079c780d1a] # to [f6b55678f033bcdc11bbcd04348058880391327f] # # patch "botan/s2k.cpp" # from [ccfb48a2afc91995ebef9d2ddd413ee635db7327] # to [edc80c7f6a50d8cc113d9e0ab44b2f49a05e54f2] # # patch "botan/s2k.h" # from [d7098ee5352337e1cad8416f9f36d07a8ac81d17] # to [f0d79e35304bc813713fa30c5f956fb5749ce288] # # patch "botan/secmem.h" # from [dd47f6b950495e2337fcf95bc44d4138d1f993f1] # to [7e435e885f9a0f44a51989c8f70615d0f88aabb3] # # patch "botan/secqueue.cpp" # from [930ab85903a98bb87794e938282860e57ea06a32] # to [980277872ed4f33cb3164ba90aa6f42e43bbd959] # # patch "botan/secqueue.h" # from [c5ce3de0ceda46423443b1abf297341eb6a702ea] # to [76d4ccc109fe988f6fa871fcccc8a044fa35f819] # # patch "botan/sha160.cpp" # from [7aa930cdbc87357c36b8df16fb74338df660ce6a] # to [f5218e5185ae523f2361838286ea0715b3043274] # # patch "botan/sha160.h" # from [ed9b5ecfb4120f6b0c8f5c930705c56959944ef9] # to [40a4e88a85e02cb8ef53d09e5698ba1f2be4d2f4] # # patch "botan/sha256.cpp" # from [6f8f29549c04f271120115f9c14113dd3b47c502] # to [5311156645190069e0d83433994737454ed7e748] # # patch "botan/sha256.h" # from [ad8001298ac6bfcef4891124d3f8ebd9c2011366] # to [f3fb2c1515d6e4275bfca19cf10c24bd217f9539] # # patch "botan/symkey.cpp" # from [2769475d3a051cfa8cdaec178c3e23517b5e9d73] # to [bf0815d2471b664035f262f40563c4eab7df9164] # # patch "botan/symkey.h" # from [4851cea7540a270a7ac4082c3e1a052664453287] # to [4ae3b55ea13aa03145bea1434c8ed08919c22526] # # patch "botan/timers.cpp" # from [0f75eecff82397be0b76891f68c73817e58a8136] # to [02e9174ce65403c561b579be46ec6dba3dda732e] # # patch "botan/timers.h" # from [7faf9a0353f4d8fe1c11b15bcf76a6db4e34860b] # to [54ddc626b8eb21354b91f17da4ce23f04553abae] # # patch "botan/types.h" # from [6747e38dbc6a39c04386ef1c2b60298a98d6c865] # to [f750f598866f1e3f6def3c798b7e92592e5bc4e1] # # patch "botan/ui.cpp" # from [d5b192eb455808424d41a1e7112d7cb11c5cbe7f] # to [32d9c59fa34f0fd2f122a5cc3b2ff021b3a8898c] # # patch "botan/ui.h" # from [a749e0f49028256cd9a159c54c56db95a8a6e66e] # to [b2113a0666a19f2ab5a86669b4aba1b7fb031b1a] # # patch "botan/util.cpp" # from [ad16ee05002deb5f13a4b9e5e21d2ffa66ae4308] # to [e993a6c91b6f3455787fc05d10230307b408c193] # # patch "botan/util.h" # from [7859becfb3fbbac552c6a78de5b265475fa4a767] # to [02cce31e55c9e0cf5a237bef31323b20a28d616e] # # patch "botan/version.h" # from [f834edcd6981ebe2560d045a4cf24a4fb3946969] # to [53fa3f9bc084e373ef685a521a5d185125b0ec27] # # patch "botan/x509_ca.cpp" # from [a6ca91a885bd8be1508fe8348af1282563742659] # to [a94a371ac8b99d786f17441ffd6995ff5e1a6f49] # # patch "botan/x509_ca.h" # from [8078cf9f2328251a13a938c506447d103a4df5c4] # to [06b345d0eea26ad6720442e1972a08604a668eee] # # patch "botan/x509_crl.cpp" # from [e3bdb21e5c44ca51be84f8793316df1f66552737] # to [3a01fdbeaa239a0ab8a4353824707f29ed4f5e4b] # # patch "botan/x509_crl.h" # from [3976dc632eea02244c6cc1e98b6f50b04c0aaf62] # to [971ccf0aa5adeea5f68fe008fbb94ef6400fc891] # # patch "botan/x509_key.cpp" # from [17699009477db1124b409f6e5e393a1cd709c2e4] # to [f70c5fd0cc4caf0c0a467abffe3327e594646ae7] # # patch "botan/x509_key.h" # from [1bc439ee441be814c600aa25263bc3a1e9a0f519] # to [7467cbbbcf62432e7bcb41fb6a3c189924ca94a9] # # patch "botan/x509_obj.cpp" # from [78e2d735c2a3cf3bb74b5ef36e4a7c132661c4ab] # to [cc7e829b3d3013e84ed72e06fdb17e9264f766a2] # # patch "botan/x509_obj.h" # from [2fa126c9ed1f9229d5a704c55757c48edb7d0d07] # to [2188d419f1e56a96277d2936295c65301309d7a2] # # patch "botan/x509cert.cpp" # from [9eea501682d3e1f6cd0c35caf8dcc0c1acc6349d] # to [c72dbb61b0aba0c216ae0affca5de53fb130d086] # # patch "botan/x509cert.h" # from [373ec84916c1d04b14060e7591d35c8a0c95b7ca] # to [eccae9cdf0fba3b4993dc1e1003bb971b2348548] # # patch "botan/x509find.cpp" # from [3540674cc40657424e46fa805404cb2c782064af] # to [30b125452b7d1d505e44a439fde5ef23016ced80] # # patch "botan/x509opt.cpp" # from [dd7040911c23c5a13f5682f5fe4e9d475db2b0f8] # to [b696ef340bef50a59ae0a05b31b4eb34f2752d8c] # # patch "botan/x509self.cpp" # from [094994e2e470e89abf1975f722f6bfa539063e96] # to [11382c4f93c3055cc2564138c9cdef0b5463caf9] # # patch "botan/x509self.h" # from [9e92e9d4c47782f41374b1e4829f65cb51b4dd8e] # to [8b65f919952b4445af08142e3a11028c32f14ba8] # # patch "botan/x509stor.cpp" # from [5d4584af2b3b825022727421f15a65ef72a2ce58] # to [de4a25ae8caad23ac23c10299b2a3805f2c0254d] # # patch "botan/x509stor.h" # from [a78774e7bde040bb909220fef6c9e5536540788d] # to [650719caca25ed77dd3308537b453801d12e85a6] # # patch "botan/x919_mac.h" # from [7687240f8465f0ad5f51fb74fc246c4851f9fad6] # to [e60f8158e591a605b501aae9e08e49223f3811d1] # # patch "botan/x931_rng.cpp" # from [48f15e5b870a4e1ced8dc06df188e7952feef520] # to [ee85f1d9ebc7be0d7f600386a1070641554a986c] # # patch "botan/x931_rng.h" # from [7379e614f20e55ff4bd65c3f9d40ed90d990c80e] # to [aed7d488fbbe36d35fe8245abe44bb7d6b98ab98] # # patch "mkstemp.cc" # from [03865df03f56044431e1ce1e2eebb27e73e5c248] # to [40607639286f4ffa5428bb9b6a05e7262d19ba30] # # patch "monotone.cc" # from [230bf4a63ae962252dd05590b0b6263b9035ff0d] # to [36b0c9c0582187a7d11a9efcccfaecc9791e7596] # ============================================================ --- botan/big_rand.cpp 2409e28c2f9eccf2f08383be22454bd462bb3584 +++ botan/big_rand.cpp 2409e28c2f9eccf2f08383be22454bd462bb3584 @@ -0,0 +1,84 @@ +/************************************************* +* BigInt Random Generation Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include +#include +#include +#include + +namespace Botan { + +/************************************************* +* Construct a BigInt of a specific form * +*************************************************/ +BigInt::BigInt(NumberType type, u32bit bits) + { + set_sign(Positive); + if(type == Random && bits) + randomize(bits); + else if(type == Power2) + set_bit(bits); + } + +/************************************************* +* Randomize this number * +*************************************************/ +void BigInt::randomize(u32bit bitsize) + { + set_sign(Positive); + + if(bitsize == 0) + clear(); + else + { + SecureVector array((bitsize + 7) / 8); + Global_RNG::randomize(array, array.size()); + if(bitsize % 8) + array[0] &= 0xFF >> (8 - (bitsize % 8)); + array[0] |= 0x80 >> ((bitsize % 8) ? (8 - bitsize % 8) : 0); + binary_decode(array, array.size()); + } + } + +/************************************************* +* Generate a random integer * +*************************************************/ +BigInt random_integer(u32bit bits) + { + BigInt x; + x.randomize(bits); + return x; + } + +/************************************************* +* Generate a random integer within given range * +*************************************************/ +BigInt random_integer(const BigInt& min, const BigInt& max) + { + BigInt range = max - min; + + if(range <= 0) + throw Invalid_Argument("random_integer: invalid min/max values"); + + return (min + (random_integer(range.bits() + 2) % range)); + } + +/************************************************* +* Generate a random safe prime * +*************************************************/ +BigInt random_safe_prime(u32bit bits) + { + if(bits <= 64) + throw Invalid_Argument("random_safe_prime: Can't make a prime of " + + to_string(bits) + " bits"); + + BigInt p; + do + p = (random_prime(bits - 1) << 1) + 1; + while(!is_prime(p)); + return p; + } + +} ============================================================ --- botan/def_powm.cpp 973942544f22958b8db2cf0fd91eb6e588b732de +++ botan/def_powm.cpp 973942544f22958b8db2cf0fd91eb6e588b732de @@ -0,0 +1,22 @@ +/************************************************* +* Modular Exponentiation Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include +#include + +namespace Botan { + +/************************************************* +* Choose a modular exponentation algorithm * +*************************************************/ +Modular_Exponentiator* +Default_Engine::mod_exp(const BigInt& n, Power_Mod::Usage_Hints hints) const + { + if(n.is_odd()) + return new Montgomery_Exponentiator(n, hints); + return new Fixed_Window_Exponentiator(n, hints); + } + +} ============================================================ --- botan/def_powm.h 5c47338822f1eec4e187c542df0529cb8b8ac173 +++ botan/def_powm.h 5c47338822f1eec4e187c542df0529cb8b8ac173 @@ -0,0 +1,59 @@ +/************************************************* +* Modular Exponentiation Header File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include +#include + +namespace Botan { + +/************************************************* +* Fixed Window Exponentiator * +*************************************************/ +class Fixed_Window_Exponentiator : public Modular_Exponentiator + { + public: + void set_exponent(const BigInt&); + void set_base(const BigInt&); + BigInt execute() const; + + Modular_Exponentiator* copy() const; + + Fixed_Window_Exponentiator(const BigInt&, Power_Mod::Usage_Hints); + ~Fixed_Window_Exponentiator(); + private: + class ModularReducer* reducer; + BigInt exp; + u32bit window_bits; + std::vector g; + Power_Mod::Usage_Hints hints; + }; + +/************************************************* +* Montgomery Exponentiator * +*************************************************/ +class Montgomery_Exponentiator : public Modular_Exponentiator + { + public: + void set_exponent(const BigInt&); + void set_base(const BigInt&); + BigInt execute() const; + + Modular_Exponentiator* copy() const; + + 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; + std::vector g; + word mod_prime; + u32bit exp_bits, window_bits; + Power_Mod::Usage_Hints hints; + }; +} ============================================================ --- botan/dl_group.h bf3839e75b8ec5d4d8b805f74c2098ee7b4f9140 +++ botan/dl_group.h bf3839e75b8ec5d4d8b805f74c2098ee7b4f9140 @@ -0,0 +1,51 @@ +/************************************************* +* Discrete Logarithm Group Header File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#ifndef BOTAN_DL_PARAM_H__ +#define BOTAN_DL_PARAM_H__ + +#include +#include + +namespace Botan { + +/************************************************* +* Discrete Logarithm Group * +*************************************************/ +class DL_Group + { + public: + const BigInt& get_p() const; + const BigInt& get_q() const; + const BigInt& get_g() const; + + enum Format { ANSI_X9_42, ANSI_X9_57, PKCS_3 }; + enum PrimeType { Strong, Prime_Subgroup, DSA_Kosherizer }; + + bool verify_group(bool) const; + + std::string PEM_encode(Format) const; + SecureVector DER_encode(Format) const; + void BER_decode(DataSource&, Format); + void PEM_decode(DataSource&); + + static BigInt make_dsa_generator(const BigInt&, const BigInt&); + + DL_Group(); + DL_Group(const std::string&); + DL_Group(u32bit, PrimeType = Strong); + DL_Group(const MemoryRegion&, u32bit = 1024, u32bit = 0); + DL_Group(const BigInt&, const BigInt&); + DL_Group(const BigInt&, const BigInt&, const BigInt&); + private: + void init_check() const; + void initialize(const BigInt&, const BigInt&, const BigInt&); + bool initialized; + BigInt p, q, g; + }; + +} + +#endif ============================================================ --- botan/libstate.cpp 0c010d07846f8903044e1d56b158314c00a93bc8 +++ botan/libstate.cpp 0c010d07846f8903044e1d56b158314c00a93bc8 @@ -0,0 +1,296 @@ +/************************************************* +* Library Internal/Global State Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include +#include +#include +#include +#include + +namespace Botan { + +namespace { + +/************************************************* +* Named Mutex Holder * +*************************************************/ +class Named_Mutex_Holder + { + public: + Named_Mutex_Holder(const std::map& mutexes, + const std::string& name) + { + mux = search_map(mutexes, name, 0); + + if(!mux) + throw Invalid_Argument("Named_Mutex_Holder: mutex not found"); + + mux->lock(); + } + + ~Named_Mutex_Holder() { mux->unlock(); } + private: + Mutex* mux; + }; + +} + +/************************************************* +* Increment the Engine iterator * +*************************************************/ +Engine* Library_State::Engine_Iterator::next() + { + return lib.get_engine_n(n++); + } + +/************************************************* +* Get a new mutex object * +*************************************************/ +Mutex* Library_State::get_mutex() + { + return mutex_factory->make(); + } + +/************************************************* +* Get an allocator by its name * +*************************************************/ +Allocator* Library_State::get_allocator(const std::string& type) const + { + Named_Mutex_Holder lock(locks, "allocator"); + + if(type != "") + return search_map(alloc_factory, type, 0); + + if(!cached_default_allocator) + { + const std::string key_name = "conf/base/default_allocator"; + + Named_Mutex_Holder lock(locks, "settings"); + std::string chosen = search_map(settings, key_name); + + if(chosen == "") + chosen = "malloc"; + + cached_default_allocator = + search_map(alloc_factory, chosen, 0); + } + + return cached_default_allocator; + } + +/************************************************* +* Create a new name to object mapping * +*************************************************/ +void Library_State::add_allocator(const std::string& type, + Allocator* allocator) + { + Named_Mutex_Holder lock(locks, "allocator"); + + allocator->init(); + if(alloc_factory[type]) + delete alloc_factory[type]; + alloc_factory[type] = allocator; + } + +/************************************************* +* Read a high resolution clock * +*************************************************/ +u64bit Library_State::system_clock() const + { + return timer->clock(); + } + +/************************************************* +* Set the global PRNG * +*************************************************/ +void Library_State::set_prng(RandomNumberGenerator* new_rng) + { + Named_Mutex_Holder lock(locks, "rng"); + + delete rng; + rng = new_rng; + } + +/************************************************* +* Get bytes from the global PRNG * +*************************************************/ +void Library_State::randomize(byte out[], u32bit length) + { + Named_Mutex_Holder lock(locks, "rng"); + + rng->randomize(out, length); + } + +/************************************************* +* Add a new entropy source to use * +*************************************************/ +void Library_State::add_entropy_source(EntropySource* src, bool last_in_list) + { + Named_Mutex_Holder lock(locks, "rng"); + + if(last_in_list) + entropy_sources.push_back(src); + else + entropy_sources.insert(entropy_sources.begin(), src); + } + +/************************************************* +* Add some bytes of entropy to the global PRNG * +*************************************************/ +void Library_State::add_entropy(const byte in[], u32bit length) + { + Named_Mutex_Holder lock(locks, "rng"); + + rng->add_entropy(in, length); + } + +/************************************************* +* Add some bytes of entropy to the global PRNG * +*************************************************/ +void Library_State::add_entropy(EntropySource& source, bool slow_poll) + { + Named_Mutex_Holder lock(locks, "rng"); + + rng->add_entropy(source, slow_poll); + } + +/************************************************* +* Gather entropy for our PRNG object * +*************************************************/ +u32bit Library_State::seed_prng(bool slow_poll, u32bit bits_to_get) + { + Named_Mutex_Holder lock(locks, "rng"); + + u32bit bits = 0; + for(u32bit j = 0; j != entropy_sources.size(); ++j) + { + bits += rng->add_entropy(*(entropy_sources[j]), slow_poll); + + if(bits_to_get && bits >= bits_to_get) + return bits; + } + + return bits; + } + +/************************************************* +* Set a named option * +*************************************************/ +void Library_State::set_option(const std::string& section, + const std::string& name, + const std::string& value, + bool overwrite) + { + Named_Mutex_Holder lock(locks, "settings"); + + std::map::const_iterator i = settings.find(name); + + if(overwrite || i == settings.end() || i->second == "") + { + const std::string full_name = section + "/" + name; + settings[full_name] = value; + + if(full_name == "base/default_allocator") + cached_default_allocator = 0; + } + } + +/************************************************* +* Get the value of the named option * +*************************************************/ +std::string Library_State::get_option(const std::string& section, + const std::string& name) const + { + Named_Mutex_Holder lock(locks, "settings"); + + return search_map(settings, + section + "/" + name, ""); + } + +/************************************************* +* See if a particular option has been set * +*************************************************/ +bool Library_State::option_set(const std::string& section, + const std::string& name) const + { + Named_Mutex_Holder lock(locks, "settings"); + + return search_map(settings, section + "/" + name, false, true); + } + +/************************************************* +* Get an engine out of the list * +*************************************************/ +Engine* Library_State::get_engine_n(u32bit n) const + { + Named_Mutex_Holder lock(locks, "engine"); + + if(n >= engines.size()) + return 0; + return engines[n]; + } + +/************************************************* +* Add a new engine to the list * +*************************************************/ +void Library_State::add_engine(Engine* engine) + { + Named_Mutex_Holder lock(locks, "engine"); + engines.push_back(engine); + } + +/************************************************* +* Library_State Constructor * +*************************************************/ +Library_State::Library_State(Mutex_Factory* mutex_factory, Timer* timer) + { + if(!mutex_factory) + mutex_factory = new Mutex_Factory; + if(!timer) + timer = new Timer; + + this->mutex_factory = mutex_factory; + this->timer = timer; + + locks["settings"] = get_mutex(); + locks["allocator"] = get_mutex(); + locks["rng"] = get_mutex(); + locks["engine"] = get_mutex(); + rng = 0; + cached_default_allocator = 0; + + set_default_policy(); + } + +/************************************************* +* Library_State Destructor * +*************************************************/ +Library_State::~Library_State() + { + cached_default_allocator = 0; + delete rng; + + for(u32bit j = 0; j != entropy_sources.size(); ++j) + delete entropy_sources[j]; + + for(u32bit j = 0; j != engines.size(); ++j) + delete engines[j]; + + for(std::map::iterator j = alloc_factory.begin(); + j != alloc_factory.end(); ++j) + { + j->second->destroy(); + delete j->second; + } + + delete mutex_factory; + delete timer; + + for(std::map::iterator j = locks.begin(); + j != locks.end(); ++j) + delete j->second; + } + +} ============================================================ --- botan/libstate.h 7fb554cb2261eecafd96ba55ab777c2ac452ae24 +++ botan/libstate.h 7fb554cb2261eecafd96ba55ab777c2ac452ae24 @@ -0,0 +1,84 @@ +/************************************************* +* Library Internal/Global State Header File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#ifndef BOTAN_LIB_STATE_H__ +#define BOTAN_LIB_STATE_H__ + +#include +#include +#include +#include + +namespace Botan { + +/************************************************* +* Global State Container Base * +*************************************************/ +class Library_State + { + public: + class Engine_Iterator + { + public: + class Engine* next(); + Engine_Iterator(const Library_State& l) : lib(l) { n = 0; } + private: + const Library_State& lib; + u32bit n; + }; + friend class Engine_Iterator; + + Allocator* get_allocator(const std::string& = "") const; + void add_allocator(const std::string&, Allocator*); + + void set_prng(RandomNumberGenerator*); + void randomize(byte[], u32bit); + void add_entropy_source(EntropySource*, bool = false); + void add_entropy(const byte[], u32bit); + void add_entropy(EntropySource&, bool); + u32bit seed_prng(bool, u32bit); + + u64bit system_clock() const; + + void set_option(const std::string&, const std::string&, + const std::string&, bool = true); + std::string get_option(const std::string&, const std::string&) const; + bool option_set(const std::string&, const std::string&) const; + + void add_engine(class Engine*); + + class Mutex* get_mutex(); + + Library_State(class Mutex_Factory*, class Timer*); + ~Library_State(); + private: + Library_State(const Library_State&) {} + Library_State& operator=(const Library_State&) { return (*this); } + + class Engine* get_engine_n(u32bit) const; + void set_default_policy(); + + std::map locks; + + class Mutex_Factory* mutex_factory; + class Timer* timer; + + std::map settings; + std::map alloc_factory; + mutable Allocator* cached_default_allocator; + + RandomNumberGenerator* rng; + std::vector entropy_sources; + std::vector engines; + }; + +/************************************************* +* Global State * +*************************************************/ +Library_State& global_state(); + +} + +#endif ============================================================ --- botan/map_util.h 4e6b06047d8fb0b0e35ae08b7983c57575814831 +++ botan/map_util.h 4e6b06047d8fb0b0e35ae08b7983c57575814831 @@ -0,0 +1,49 @@ +/************************************************* +* Map Utility Functions Header File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#ifndef BOTAN_MAP_UTIL_H__ +#define BOTAN_MAP_UTIL_H__ + +#include + +namespace Botan { + +/************************************************* +* Searching through a std::map * +*************************************************/ +template +inline V search_map(const std::map& mapping, + const K& key, + const V& null_result = V()) + { + typename std::map::const_iterator i = mapping.find(key); + if(i == mapping.end()) + return null_result; + return i->second; + } + +template +inline R search_map(const std::map& mapping, const K& key, + const R& null_result, const R& found_result) + { + typename std::map::const_iterator i = mapping.find(key); + if(i == mapping.end()) + return null_result; + return found_result; + } + +/************************************************* +* Insert a key/value pair into a multimap * +*************************************************/ +template +void multimap_insert(std::multimap& multimap, + const K& key, const V& value) + { + multimap.insert(std::make_pair(key, value)); + } + +} + +#endif ============================================================ --- botan/modules.cpp cd75a13013e5d6083d9425a9a753f4d92bf13af2 +++ botan/modules.cpp cd75a13013e5d6083d9425a9a753f4d92bf13af2 @@ -0,0 +1,187 @@ +/************************************************* +* Module Factory Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include +#include + +#if defined(BOTAN_EXT_MUTEX_PTHREAD) + #include +#elif defined(BOTAN_EXT_MUTEX_WIN32) + #include +#elif defined(BOTAN_EXT_MUTEX_QT) + #include +#endif + +#if defined(BOTAN_EXT_ALLOC_MMAP) + #include +#endif + +#if defined(BOTAN_EXT_TIMER_HARDWARE) + #include +#elif defined(BOTAN_EXT_TIMER_POSIX) + #include +#elif defined(BOTAN_EXT_TIMER_UNIX) + #include +#elif defined(BOTAN_EXT_TIMER_WIN32) + #include +#endif + +#if defined(BOTAN_EXT_ENGINE_AEP) + #include +#endif + +#if defined(BOTAN_EXT_ENGINE_GNU_MP) + #include +#endif + +#if defined(BOTAN_EXT_ENGINE_OPENSSL) + #include +#endif + +#if defined(BOTAN_EXT_ENTROPY_SRC_AEP) + #include +#endif + +#if defined(BOTAN_EXT_ENTROPY_SRC_EGD) + #include +#endif + +#if defined(BOTAN_EXT_ENTROPY_SRC_UNIX) + #include +#endif + +#if defined(BOTAN_EXT_ENTROPY_SRC_BEOS) + #include +#endif + +#if defined(BOTAN_EXT_ENTROPY_SRC_CAPI) + #include +#endif + +#if defined(BOTAN_EXT_ENTROPY_SRC_WIN32) + #include +#endif + +#if defined(BOTAN_EXT_ENTROPY_SRC_FTW) + #include +#endif + +namespace Botan { + +namespace Modules { + +/************************************************* +* Register a mutex type, if possible * +*************************************************/ +Mutex_Factory* get_mutex_factory() + { +#if defined(BOTAN_EXT_MUTEX_PTHREAD) + return new Pthread_Mutex_Factory; +#elif defined(BOTAN_EXT_MUTEX_WIN32) + return new Win32_Mutex_Factory; +#elif defined(BOTAN_EXT_MUTEX_QT) + return new Qt_Mutex_Factory; +#endif + + return 0; + } + +/************************************************* +* Find a high resolution timer, if possible * +*************************************************/ +Timer* get_timer() + { +#if defined(BOTAN_EXT_TIMER_HARDWARE) + return new Hardware_Timer; +#elif defined(BOTAN_EXT_TIMER_POSIX) + return new POSIX_Timer; +#elif defined(BOTAN_EXT_TIMER_UNIX) + return new Unix_Timer; +#elif defined(BOTAN_EXT_TIMER_WIN32) + return new Win32_Timer; +#endif + + return 0; + } + +/************************************************* +* Find any usable allocators * +*************************************************/ +std::map get_allocators() + { + std::map allocators; + +#if defined(BOTAN_EXT_ALLOC_MMAP) + allocators["mmap"] = new MemoryMapping_Allocator; +#endif + + return allocators; + } + +/************************************************* +* Register any usable entropy sources * +*************************************************/ +std::vector get_entropy_sources() + { + std::vector sources; + + sources.push_back(new File_EntropySource); + +#if defined(BOTAN_EXT_ENTROPY_SRC_AEP) + sources.push_back(new AEP_EntropySource); +#endif + +#if defined(BOTAN_EXT_ENTROPY_SRC_EGD) + sources.push_back(new EGD_EntropySource); +#endif + +#if defined(BOTAN_EXT_ENTROPY_SRC_CAPI) + sources.push_back(new Win32_CAPI_EntropySource); +#endif + +#if defined(BOTAN_EXT_ENTROPY_SRC_WIN32) + sources.push_back(new Win32_EntropySource); +#endif + +#if defined(BOTAN_EXT_ENTROPY_SRC_UNIX) + sources.push_back(new Unix_EntropySource); +#endif + +#if defined(BOTAN_EXT_ENTROPY_SRC_BEOS) + sources.push_back(new BeOS_EntropySource); +#endif + +#if defined(BOTAN_EXT_ENTROPY_SRC_FTW) + sources.push_back(new FTW_EntropySource); +#endif + + return sources; + } + +/************************************************* +* Find any usable engines * +*************************************************/ +std::vector get_engines() + { + std::vector engines; + +#if defined(BOTAN_EXT_ENGINE_AEP) + engines.push_back(new AEP_Engine); +#endif + +#if defined(BOTAN_EXT_ENGINE_GNU_MP) + engines.push_back(new GMP_Engine); +#endif + +#if defined(BOTAN_EXT_ENGINE_OPENSSL) + engines.push_back(new OpenSSL_Engine); +#endif + + return engines; + } + +} + +} ============================================================ --- botan/modules.h b28353b556b87a4f69147ee066bdbd12b2235038 +++ botan/modules.h b28353b556b87a4f69147ee066bdbd12b2235038 @@ -0,0 +1,39 @@ +/************************************************* +* Module Factory Header File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#ifndef BOTAN_MODULE_FACTORIES_H__ +#define BOTAN_MODULE_FACTORIES_H__ + +#include +#include +#include + +namespace Botan { + +/************************************************* +* Forward Declarations * +*************************************************/ +class Mutex_Factory; +class Timer; +class EntropySource; +class Engine; +class Allocator; + +namespace Modules { + +/************************************************* +* Get the module objects * +*************************************************/ +class Mutex_Factory* get_mutex_factory(); +class Timer* get_timer(); +std::vector get_entropy_sources(); +std::vector get_engines(); +std::map get_allocators(); + +} + +} + +#endif ============================================================ --- botan/mp_add.cpp cb49c8919e7eccd7f65de3bef85d2a143a1c726c +++ botan/mp_add.cpp cb49c8919e7eccd7f65de3bef85d2a143a1c726c @@ -0,0 +1,118 @@ +/************************************************* +* MPI Addition Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include +#include + +namespace Botan { + +extern "C" { + +namespace { + +/************************************************* +* 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; + } + +} + +/************************************************* +* 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) + { + x[j ] = word_add(x[j ], y[j ], &carry); + x[j+1] = word_add(x[j+1], y[j+1], &carry); + x[j+2] = word_add(x[j+2], y[j+2], &carry); + x[j+3] = word_add(x[j+3], y[j+3], &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) + { + x[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) + { + z[j ] = word_add(x[j ], y[j ], &carry); + z[j+1] = word_add(x[j+1], y[j+1], &carry); + z[j+2] = word_add(x[j+2], y[j+2], &carry); + z[j+3] = word_add(x[j+3], y[j+3], &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) + { + if(bigint_add2_nc(x, x_size, y, y_size)) + x[x_size]++; + } + +/************************************************* +* Three Operand Addition * +*************************************************/ +void bigint_add3(word z[], const word x[], u32bit x_size, + const word y[], u32bit y_size) + { + if(bigint_add3_nc(z, x, x_size, y, y_size)) + z[x_size > y_size ? x_size : y_size]++; + } + +} + +} ============================================================ --- botan/mp_asm.h a1f6a95c58b1a7036398fb843807d2016be2c438 +++ botan/mp_asm.h a1f6a95c58b1a7036398fb843807d2016be2c438 @@ -0,0 +1,48 @@ +/************************************************* +* Lowest Level MPI Algorithms Header File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#ifndef BOTAN_MP_ASM_H__ +#define BOTAN_MP_ASM_H__ + +#include + +#if (BOTAN_MP_WORD_BITS == 8) + typedef Botan::u16bit dword; +#elif (BOTAN_MP_WORD_BITS == 16) + typedef Botan::u32bit dword; +#elif (BOTAN_MP_WORD_BITS == 32) + typedef Botan::u64bit dword; +#elif (BOTAN_MP_WORD_BITS == 64) + #error BOTAN_MP_WORD_BITS can only be 64 with the mp_asm64 module +#else + #error BOTAN_MP_WORD_BITS must be 8, 16, 32, or 64 +#endif + +namespace Botan { + +/************************************************* +* Multiply-Carry Operation * +*************************************************/ +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); + } + +/************************************************* +* Multiply-Add Operation * +*************************************************/ +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); + } + +} + +#endif ============================================================ --- botan/mp_numth.cpp 4c55dcdaad744b0725dd5d7e489acdb6eb4039bd +++ botan/mp_numth.cpp 4c55dcdaad744b0725dd5d7e489acdb6eb4039bd @@ -0,0 +1,78 @@ +/************************************************* +* Fused and Important MP Algorithms Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include +#include + +namespace Botan { + +/************************************************* +* Square a BigInt * +*************************************************/ +BigInt square(const BigInt& x) + { + const u32bit x_sw = x.sig_words(); + + BigInt z(BigInt::Positive, 2*x_sw); + bigint_sqr(z.get_reg(), z.size(), x.data(), x.size(), x_sw); + return z; + } + +/************************************************* +* Multiply-Add Operation * +*************************************************/ +BigInt mul_add(const BigInt& a, const BigInt& b, const BigInt& c) + { + if(c.is_negative() || c.is_zero()) + throw Invalid_Argument("mul_add: Third argument must be > 0"); + + BigInt::Sign sign = BigInt::Positive; + if(a.sign() != b.sign()) + sign = BigInt::Negative; + + const u32bit a_sw = a.sig_words(); + const u32bit b_sw = b.sig_words(); + 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); + const u32bit r_size = std::max(r.sig_words(), c_sw); + bigint_add2(r.get_reg(), r_size, c.data(), c_sw); + return r; + } + +/************************************************* +* Subtract-Multiply Operation * +*************************************************/ +BigInt sub_mul(const BigInt& a, const BigInt& b, const BigInt& c) + { + if(a.is_negative() || b.is_negative()) + throw Invalid_Argument("sub_mul: First two arguments must be >= 0"); + + BigInt r = a; + r -= b; + r *= c; + return r; + } + +/************************************************* +* Multiply-Modulo Operation * +*************************************************/ +BigInt mul_mod(const BigInt& a, const BigInt& b, const BigInt& m) + { + if(a.is_negative() || b.is_negative()) + throw Invalid_Argument("mul_mod: First two arguments must be >= 0"); + if(m <= 0) + throw Invalid_Argument("mul_mod: Modulo must be positive"); + + BigInt r = a; + r *= b; + r %= m; + return r; + } + +} ============================================================ --- botan/mp_sqr.cpp 432313c19062bf16fd46c2f484b7ff2abde9e536 +++ botan/mp_sqr.cpp 432313c19062bf16fd46c2f484b7ff2abde9e536 @@ -0,0 +1,167 @@ +/************************************************* +* Karatsuba Squaring Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#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 { + +/************************************************* +* Karatsuba Squaring Operation * +*************************************************/ +void karatsuba_sqr(word z[], const word x[], u32bit N, word workspace[]) + { + const u32bit KARATSUBA_SQR_LOWER_SIZE = BOTAN_KARAT_SQR_THRESHOLD; + + if(N == 6) + bigint_comba_sqr6(z, x); + else if(N == 8) + bigint_comba_sqr8(z, x); + else if(N < KARATSUBA_SQR_LOWER_SIZE || N % 2) + bigint_simple_sqr(z, x, N); + else + { + const u32bit N2 = N / 2; + + const word* x0 = x; + const word* x1 = x + N2; + word* z0 = z; + word* z1 = z + N; + + const s32bit cmp = bigint_cmp(x0, N2, x1, N2); + + clear_mem(workspace, 2*N); + + if(cmp) + { + if(cmp > 0) + bigint_sub3(z0, x0, N2, x1, N2); + else + bigint_sub3(z0, x1, N2, x0, N2); + + karatsuba_sqr(workspace, z0, N2, workspace+N); + } + + karatsuba_sqr(z0, x0, N2, workspace+N); + karatsuba_sqr(z1, x1, N2, workspace+N); + + word carry = bigint_add3_nc(workspace+N, z0, N, z1, N); + carry += bigint_add2_nc(z + N2, N, workspace + N, N); + bigint_add2_nc(z + N + N2, N2, &carry, 1); + + if(cmp == 0) + bigint_add2(z + N2, 2*N-N2, workspace, N); + else + bigint_sub2(z + N2, 2*N-N2, workspace, N); + } + } + +/************************************************* +* Pick a good size for the Karatsuba squaring * +*************************************************/ +u32bit karatsuba_size(u32bit x_size, u32bit x_sw) + { + if(x_sw == x_size) + { + if(x_sw % 2) + return 0; + return x_sw; + } + + for(u32bit j = x_sw; j <= x_size; ++j) + if(j % 2 == 0 && x_sw <= j && j <= x_size) + { + if(j % 4 == 2 && (j+2) < x_size) + return (j+2); + return j; + } + return 0; + } + +/************************************************* +* Handle small operand squarings * +*************************************************/ +void handle_small_sqr(word z[], u32bit z_size, + const word x[], u32bit x_size, u32bit x_sw) + { + if(x_sw == 1) + bigint_linmul3(z, x, x_sw, x[0]); + else if(x_sw <= 4 && x_size >= 4 && z_size >= 8) + bigint_comba_sqr4(z, x); + else if(x_sw <= 6 && x_size >= 6 && z_size >= 12) + bigint_comba_sqr6(z, x); + else if(x_sw <= 8 && x_size >= 8 && z_size >= 16) + bigint_comba_sqr8(z, x); + else + bigint_simple_sqr(z, x, x_sw); + } + +} + +/************************************************* +* Squaring Algorithm Dispatcher * +*************************************************/ +void bigint_sqr(word z[], u32bit z_size, + const word x[], u32bit x_size, u32bit x_sw) + { + if(x_size <= 8 || x_size <= 8) + { + handle_small_sqr(z, z_size, x, x_size, x_sw); + return; + } + + const u32bit N = karatsuba_size(x_size, x_sw); + + if(N) + { + word* workspace = new word[2*N]; + clear_mem(workspace, 2*N); + + karatsuba_sqr(z, x, N, workspace); + + clear_mem(workspace, 2*N); + delete[] workspace; + } + else + bigint_simple_sqr(z, x, x_sw); + } + +} ============================================================ --- botan/mp_sub.cpp ad4d6e96032c60c4e8a5237dd3642263516b0978 +++ botan/mp_sub.cpp ad4d6e96032c60c4e8a5237dd3642263516b0978 @@ -0,0 +1,81 @@ +/************************************************* +* MPI Subtraction Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include +#include + +namespace Botan { + +extern "C" { + +namespace { + +/************************************************* +* 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; + } + +} + +/************************************************* +* Two Operand Subtraction * +*************************************************/ +void bigint_sub2(word x[], u32bit x_size, const word y[], u32bit y_size) + { + word carry = 0; + for(u32bit j = 0; 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; + for(u32bit j = 0; j != y_size; ++j) + { + const word x_j = x[j], y_j = y[j]; + + word c1 = 0, c2 = 0, z_j = 0, t0 = 0; + + t0 = x_j - y_j; + c1 = (t0 > x_j); + + z_j = t0 - carry; + c2 = (z_j > t0); + + carry = c1 | c2; + z[j] = z_j; + } + + 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; + } + } + +} + +} ============================================================ --- botan/pow_mod.h d01bdba0bdab4579b8c0ac0df3d05b4054bb409c +++ botan/pow_mod.h d01bdba0bdab4579b8c0ac0df3d05b4054bb409c @@ -0,0 +1,91 @@ +/************************************************* +* Modular Exponentiator Header File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#ifndef BOTAN_POWER_MOD_H__ +#define BOTAN_POWER_MOD_H__ + +#include + +namespace Botan { + +/************************************************* +* Modular Exponentiator Interface * +*************************************************/ +class Modular_Exponentiator + { + public: + virtual void set_base(const BigInt&) = 0; + virtual void set_exponent(const BigInt&) = 0; + virtual BigInt execute() const = 0; + virtual Modular_Exponentiator* copy() const = 0; + virtual ~Modular_Exponentiator() {} + }; + +/************************************************* +* Modular Exponentiator Proxy * +*************************************************/ +class Power_Mod + { + public: + enum Usage_Hints { + NO_HINTS = 0x0000, + + BASE_IS_FIXED = 0x0001, + BASE_IS_SMALL = 0x0002, + BASE_IS_LARGE = 0x0004, + BASE_IS_2 = 0x0008, + + EXP_IS_FIXED = 0x0100, + EXP_IS_SMALL = 0x0200, + EXP_IS_LARGE = 0x0400 + }; + + void set_modulus(const BigInt&, Usage_Hints = NO_HINTS) const; + void set_base(const BigInt&) const; + void set_exponent(const BigInt&) const; + + BigInt execute() const; + + Power_Mod& operator=(const Power_Mod&); + + Power_Mod(const BigInt& = 0, Usage_Hints = NO_HINTS); + Power_Mod(const Power_Mod&); + ~Power_Mod(); + private: + mutable Modular_Exponentiator* core; + Usage_Hints hints; + }; + +/************************************************* +* Fixed Exponent Modular Exponentiator Proxy * +*************************************************/ +class Fixed_Exponent_Power_Mod : public Power_Mod + { + public: + BigInt operator()(const BigInt& b) const + { set_base(b); return execute(); } + + Fixed_Exponent_Power_Mod() {} + Fixed_Exponent_Power_Mod(const BigInt&, const BigInt&, + Usage_Hints = NO_HINTS); + }; + +/************************************************* +* Fixed Base Modular Exponentiator Proxy * +*************************************************/ +class Fixed_Base_Power_Mod : public Power_Mod + { + public: + BigInt operator()(const BigInt& e) const + { set_exponent(e); return execute(); } + + Fixed_Base_Power_Mod() {} + Fixed_Base_Power_Mod(const BigInt&, const BigInt&, + Usage_Hints = NO_HINTS); + }; + +} + +#endif ============================================================ --- botan/powm_fw.cpp 47a558712cef903c7205aa7d19dfc9f3ce1f8488 +++ botan/powm_fw.cpp 47a558712cef903c7205aa7d19dfc9f3ce1f8488 @@ -0,0 +1,127 @@ +/************************************************* +* Fixed Window Exponentiation Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include +#include +#include +#include +#include + +namespace Botan { + +namespace { + +/************************************************* +* Try to choose a good window size * +*************************************************/ +u32bit choose_window_bits(u32bit exp_bits, u32bit base_bits, + Power_Mod::Usage_Hints hints) + { + static const u32bit wsize[][2] = { + { 2048, 7 }, { 1024, 6 }, { 256, 5 }, { 128, 4 }, { 64, 3 }, { 0, 0 } + }; + + u32bit window_bits = 3; + + if(exp_bits) + { + for(u32bit j = 0; wsize[j][0]; ++j) + { + if(exp_bits >= wsize[j][0]) + { + window_bits += wsize[j][1]; + break; + } + } + } + + if(hints & Power_Mod::EXP_IS_FIXED) + window_bits += 2; + if(hints & Power_Mod::EXP_IS_LARGE) + window_bits += 2; + if(hints & Power_Mod::BASE_IS_FIXED) + window_bits++; + + return window_bits; + } + +} + +/************************************************* +* Set the exponent * +*************************************************/ +void Fixed_Window_Exponentiator::set_exponent(const BigInt& e) + { + exp = e; + } + +/************************************************* +* Set the base * +*************************************************/ +void Fixed_Window_Exponentiator::set_base(const BigInt& base) + { + window_bits = choose_window_bits(exp.bits(), base.bits(), hints); + + g.resize((1 << window_bits) - 1); + g[0] = base; + for(u32bit j = 1; j != g.size(); ++j) + g[j] = reducer->multiply(g[j-1], g[0]); + } + +/************************************************* +* Compute the result * +*************************************************/ +BigInt Fixed_Window_Exponentiator::execute() const + { + const u32bit exp_nibbles = (exp.bits() + window_bits - 1) / window_bits; + + BigInt x = 1; + for(u32bit j = exp_nibbles; j > 0; j--) + { + for(u32bit k = 0; k != window_bits; ++k) + x = reducer->square(x); + + u32bit nibble = exp.get_substring(window_bits*(j-1), window_bits); + if(nibble) + x = reducer->multiply(x, g.at(nibble-1)); + } + return x; + } + +/************************************************* +* Make a copy of this exponentiator * +*************************************************/ +Modular_Exponentiator* Fixed_Window_Exponentiator::copy() const + { + Fixed_Window_Exponentiator* out = + new Fixed_Window_Exponentiator(reducer->get_modulus(), hints); + + out->g = g; + out->exp = exp; + out->window_bits = window_bits; + + return out; + } + +/************************************************* +* Fixed_Window_Exponentiator Constructor * +*************************************************/ +Fixed_Window_Exponentiator::Fixed_Window_Exponentiator(const BigInt& n, + Power_Mod::Usage_Hints hints) + { + reducer = get_reducer(n); + this->hints = hints; + window_bits = 0; + } + +/************************************************* +* Fixed_Window_Exponentiator Destructor * +*************************************************/ +Fixed_Window_Exponentiator::~Fixed_Window_Exponentiator() + { + delete reducer; + } + +} ============================================================ --- botan/powm_mnt.cpp fb243f2b18a781bc9327a79a7e0cec0bd60b4d21 +++ botan/powm_mnt.cpp fb243f2b18a781bc9327a79a7e0cec0bd60b4d21 @@ -0,0 +1,226 @@ +/************************************************* +* Montgomery Exponentiation Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include +#include +#include + +#include // remove + +namespace Botan { + +namespace { + +/************************************************* +* Try to choose a good window size * +*************************************************/ +u32bit choose_window_bits(u32bit exp_bits, u32bit base_bits, + Power_Mod::Usage_Hints hints) + { + static const u32bit wsize[][2] = { + { 2048, 4 }, { 1024, 3 }, { 256, 2 }, { 128, 1 }, { 0, 0 } + }; + + u32bit window_bits = 1; + + if(exp_bits) + { + for(u32bit j = 0; wsize[j][0]; ++j) + { + if(exp_bits >= wsize[j][0] || base_bits >= wsize[j][0]) + { + window_bits += wsize[j][1]; + break; + } + } + } + + if(hints & Power_Mod::BASE_IS_FIXED) + window_bits += 2; + if(hints & Power_Mod::EXP_IS_LARGE) + window_bits++; + + return window_bits; + } + +} + +/************************************************* +* Set the exponent * +*************************************************/ +void Montgomery_Exponentiator::set_exponent(const BigInt& exp) + { + this->exp = exp; + exp_bits = exp.bits(); + } + +/************************************************* +* Set the base * +*************************************************/ +void Montgomery_Exponentiator::set_base(const BigInt& base) + { + window_bits = choose_window_bits(exp.bits(), base.bits(), hints); + + g.resize((1 << window_bits) - 1); + + g[0] = reduce(((base >= modulus) ? (base % modulus) : base) * R2); + for(u32bit j = 1; j != g.size(); ++j) + g[j] = reduce(g[j-1] * g[0]); + } + +/************************************************* +* Compute the result * +*************************************************/ +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_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) + { + 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); + } + + 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); + + 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); + } + + 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); + + x.get_reg().set(z, mod_size + 1); + } + +/************************************************* +* Montgomery Reduction * +*************************************************/ +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); + + for(u32bit j = 0; j != mod_size; ++j) + { + 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); + } + + 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; + } + +/************************************************* +* Make a copy of this exponentiator * +*************************************************/ +Modular_Exponentiator* Montgomery_Exponentiator::copy() const + { + return new Montgomery_Exponentiator(*this); + } + +/************************************************* +* Montgomery_Exponentiator Constructor * +*************************************************/ +Montgomery_Exponentiator::Montgomery_Exponentiator(const BigInt& mod, + Power_Mod::Usage_Hints hints) + { + if(!mod.is_positive()) + throw Exception("Montgomery_Exponentiator: modulus must be positive"); + if(mod.is_even()) + throw Exception("Montgomery_Exponentiator: modulus must be odd"); + + window_bits = 0; + this->hints = hints; + modulus = mod; + + BigInt mod_prime_bn(BigInt::Power2, MP_WORD_BITS); + mod_prime = (mod_prime_bn - inverse_mod(modulus, mod_prime_bn)).word_at(0); + + R_mod = BigInt(BigInt::Power2, MP_WORD_BITS * modulus.sig_words()); + R_mod %= modulus; + + R2 = BigInt(BigInt::Power2, 2 * MP_WORD_BITS * modulus.sig_words()); + R2 %= modulus; + } + +} ============================================================ --- ChangeLog c151668264b7969dafddfd7e2d3d363aa40a614c +++ ChangeLog beb22f4654fb059a63b906c468b9c8fed15af7cb @@ -1,3 +1,7 @@ +2006-01-22 Matt Johnston + + * merged in Botan 1.5.2 experimental release + 2006-01-21 Nathaniel Smith * netcmd.cc (read): Expand the error message we issue on protocol ============================================================ --- Makefile.am 1086b6f0ea35d96bdd46455c7d97c5934fb77e5a +++ Makefile.am 23f1c46e322bd2e9d8fc7660c7ac0c935c3acb76 @@ -73,91 +73,96 @@ netxx/streamserver.h netxx/timeout.h netxx/types.h BOTAN_SOURCES = \ - botan/aes.cpp botan/aes_tab.cpp botan/algolist.cpp \ - botan/allocate.cpp botan/arc4.cpp botan/asn1_alg.cpp \ - botan/asn1_alt.cpp botan/asn1_att.cpp botan/asn1_dn.cpp \ - botan/asn1_ext.cpp botan/asn1_ku.cpp botan/asn1_oid.cpp \ - botan/asn1_str.cpp botan/asn1_tm.cpp botan/barrett.cpp \ - botan/base.cpp botan/base64.cpp botan/basefilt.cpp \ - botan/ber_code.cpp botan/ber_dec.cpp botan/big_base.cpp \ - botan/big_code.cpp botan/big_io.cpp botan/big_ops2.cpp \ - botan/big_ops3.cpp botan/blinding.cpp botan/buf_es.cpp \ - botan/buf_filt.cpp botan/cbc.cpp botan/certstore.cpp \ - botan/cfb.cpp botan/charset.cpp botan/conf.cpp botan/crc32.cpp \ - botan/crl_ent.cpp botan/ctr.cpp botan/cts.cpp \ + botan/aes.cpp botan/aes_tab.cpp \ + botan/allocate.cpp botan/arc4.cpp botan/asn1_alg.cpp \ + botan/asn1_alt.cpp botan/asn1_att.cpp botan/asn1_dn.cpp \ + botan/asn1_ext.cpp botan/asn1_ku.cpp botan/asn1_oid.cpp \ + botan/asn1_str.cpp botan/asn1_tm.cpp \ + botan/base.cpp botan/base64.cpp botan/basefilt.cpp \ + botan/ber_code.cpp botan/ber_dec.cpp botan/big_base.cpp \ + botan/big_code.cpp botan/big_io.cpp botan/big_ops2.cpp \ + botan/big_ops3.cpp botan/blinding.cpp botan/buf_es.cpp \ + botan/buf_filt.cpp botan/cbc.cpp botan/certstore.cpp \ + botan/cfb.cpp botan/charset.cpp botan/conf.cpp botan/crc32.cpp \ + botan/crl_ent.cpp botan/ctr.cpp botan/cts.cpp \ botan/data_snk.cpp botan/data_src.cpp \ - botan/def_ops.cpp botan/defalloc.cpp botan/der_code.cpp \ - botan/der_enc.cpp botan/divide.cpp botan/dl_algo.cpp \ - botan/dl_group.cpp botan/dl_param.cpp \ - botan/dl_cache.cpp \ - botan/dlies.cpp botan/eax.cpp botan/ecb.cpp botan/eme1.cpp \ - botan/eme_pkcs.cpp botan/emsa1.cpp botan/emsa2.cpp \ - botan/emsa3.cpp botan/emsa4.cpp botan/emsa_raw.cpp \ - botan/eng_base.cpp botan/engine.cpp botan/es_file.cpp \ - botan/exceptn.cpp botan/filter.cpp botan/filters.cpp \ - botan/fips140.cpp botan/fused.cpp \ - botan/get_algo.cpp botan/get_enc.cpp botan/get_pbe.cpp \ - botan/gzip.cpp botan/hash_id.cpp botan/hex.cpp botan/hmac.cpp \ - botan/if_algo.cpp botan/inifile.cpp botan/init.cpp \ - botan/kdf.cpp botan/keypair.cpp botan/look_pk.cpp \ - botan/lookup.cpp botan/make_prm.cpp botan/mdx_hash.cpp \ - botan/mem_pool.cpp botan/mgf1.cpp botan/mlock.cpp \ - botan/mod_exp.cpp botan/mode_pad.cpp botan/modebase.cpp \ - botan/mp_comba.cpp botan/mp_core.cpp botan/mp_fkmul.cpp \ - botan/mp_misc.cpp botan/mp_mul.cpp botan/mp_shift.cpp \ - botan/mp_smul.cpp botan/mutex.cpp botan/numthry.cpp \ - botan/ofb.cpp botan/oids.cpp botan/parsing.cpp botan/pbes1.cpp \ - botan/pbes2.cpp botan/pem.cpp botan/pipe.cpp botan/pipe_io.cpp \ - botan/pipe_rw.cpp botan/pk_algs.cpp botan/pk_core.cpp \ - botan/pk_filts.cpp botan/pk_keys.cpp botan/pk_util.cpp \ - botan/pkcs10.cpp botan/pkcs8.cpp botan/policy.cpp \ + botan/def_ops.cpp botan/defalloc.cpp botan/der_code.cpp \ + botan/der_enc.cpp botan/divide.cpp botan/dl_algo.cpp \ + botan/dl_group.cpp \ + botan/dlies.cpp botan/eax.cpp botan/ecb.cpp botan/eme1.cpp \ + botan/eme_pkcs.cpp botan/emsa1.cpp botan/emsa2.cpp \ + botan/emsa3.cpp botan/emsa4.cpp botan/emsa_raw.cpp \ + botan/eng_base.cpp botan/engine.cpp botan/es_file.cpp \ + botan/exceptn.cpp botan/filter.cpp botan/filters.cpp \ + botan/fips140.cpp \ + botan/get_algo.cpp botan/get_enc.cpp botan/get_pbe.cpp \ + botan/gzip.cpp botan/hash_id.cpp botan/hex.cpp botan/hmac.cpp \ + botan/if_algo.cpp botan/inifile.cpp botan/init.cpp \ + botan/kdf.cpp botan/keypair.cpp botan/look_pk.cpp \ + botan/make_prm.cpp botan/mdx_hash.cpp \ + botan/mem_pool.cpp botan/mgf1.cpp botan/mlock.cpp \ + botan/mode_pad.cpp botan/modebase.cpp \ + botan/mp_comba.cpp \ + botan/mp_misc.cpp botan/mp_mul.cpp botan/mp_shift.cpp \ + botan/mutex.cpp botan/numthry.cpp \ + botan/ofb.cpp botan/oids.cpp botan/parsing.cpp botan/pbes1.cpp \ + botan/pbes2.cpp botan/pem.cpp botan/pipe.cpp botan/pipe_io.cpp \ + botan/pipe_rw.cpp botan/pk_algs.cpp botan/pk_core.cpp \ + botan/pk_filts.cpp botan/pk_keys.cpp botan/pk_util.cpp \ + botan/pkcs10.cpp botan/pkcs8.cpp botan/policy.cpp \ botan/pow_mod.cpp \ - botan/prf_x942.cpp botan/primes.cpp botan/pubkey.cpp \ - botan/randpool.cpp botan/reducer.cpp botan/rng.cpp \ - botan/rsa.cpp botan/s2k.cpp botan/secqueue.cpp \ - botan/sha160.cpp botan/symkey.cpp botan/timers.cpp \ - botan/ui.cpp botan/util.cpp botan/x509_ca.cpp \ - botan/x509_crl.cpp botan/x509_key.cpp botan/x509_obj.cpp \ - botan/x509cert.cpp botan/x509find.cpp botan/x509opt.cpp \ - botan/des.cpp botan/des_tab.cpp botan/pkcs5.cpp \ - botan/x509self.cpp botan/x509stor.cpp \ - botan/def_alg.cpp botan/def_mode.cpp botan/sha256.cpp \ + botan/prf_x942.cpp botan/primes.cpp botan/pubkey.cpp \ + botan/randpool.cpp botan/reducer.cpp botan/rng.cpp \ + botan/rsa.cpp botan/s2k.cpp botan/secqueue.cpp \ + botan/sha160.cpp botan/symkey.cpp botan/timers.cpp \ + botan/ui.cpp botan/util.cpp botan/x509_ca.cpp \ + botan/x509_crl.cpp botan/x509_key.cpp botan/x509_obj.cpp \ + botan/x509cert.cpp botan/x509find.cpp botan/x509opt.cpp \ + botan/des.cpp botan/des_tab.cpp botan/pkcs5.cpp \ + botan/x509self.cpp botan/x509stor.cpp \ + 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/aes.h botan/botan.h botan/def_eng.h botan/es_win32.h \ - botan/lookup.h botan/randpool.h botan/version.h \ - botan/algolist.h botan/buf_es.h botan/der_enc.h \ - botan/exceptn.h botan/mdx_hash.h botan/par_hash.h \ - botan/reducer.h botan/x509_ca.h botan/allocate.h \ - botan/buf_filt.h botan/dh.h botan/filter.h botan/mem_ops.h \ - botan/pbe.h botan/rng.h botan/x509cert.h botan/arc4.h \ - botan/cbc.h botan/dl_algo.h botan/filters.h botan/mem_pool.h \ - botan/pbe_pkcs.h botan/rsa.h botan/x509_crl.h botan/asn1.h \ - botan/certstor.h botan/dlies.h botan/fips140.h botan/mgf1.h \ - botan/pem.h botan/s2k.h botan/x509_key.h botan/asn1_obj.h \ - botan/cfb.h botan/dl_param.h botan/modebase.h \ - botan/pipe.h botan/x509_obj.h \ - botan/asn1_oid.h botan/conf.h botan/eax.h botan/gzip.h \ - botan/mode_pad.h botan/pk_algs.h botan/secmem.h \ - botan/x509self.h botan/barrett.h botan/config.h botan/ecb.h \ - botan/hex.h botan/mod_exp.h botan/pk_core.h botan/secqueue.h \ - botan/x509stor.h botan/base64.h botan/crc32.h botan/eme.h \ - botan/hmac.h botan/mp_core.h botan/pkcs10.h botan/sha160.h \ - botan/crl_ent.h botan/emsa.h \ - botan/if_algo.h botan/mp_madd.h botan/pkcs8.h \ - botan/x919_mac.h botan/basefilt.h botan/ctr.h botan/engine.h \ - botan/init.h botan/mp_types.h botan/pk_filts.h botan/symkey.h \ - botan/base.h botan/cts.h botan/enums.h botan/kdf.h \ - botan/mutex.h botan/pk_keys.h botan/timers.h botan/ber_dec.h \ - botan/data_snk.h botan/es_capi.h botan/keypair.h \ - botan/numthry.h botan/pk_ops.h botan/types.h botan/bigint.h \ - botan/data_src.h botan/es_egd.h botan/look_add.h botan/ofb.h \ - botan/pk_util.h botan/ui.h botan/blinding.h botan/defalloc.h \ - botan/es_file.h botan/look_pk.h botan/oids.h botan/pubkey.h \ - botan/util.h botan/charset.h botan/hash_id.h \ - botan/des.h botan/pkcs5.h \ + botan/aes.h botan/botan.h botan/def_eng.h botan/es_win32.h \ + botan/lookup.h botan/randpool.h botan/version.h \ + botan/algolist.h botan/buf_es.h botan/der_enc.h \ + botan/exceptn.h botan/mdx_hash.h botan/par_hash.h \ + botan/reducer.h botan/x509_ca.h botan/allocate.h \ + botan/buf_filt.h botan/dh.h botan/filter.h botan/mem_ops.h \ + botan/pbe.h botan/rng.h botan/x509cert.h botan/arc4.h \ + botan/cbc.h botan/dl_algo.h botan/filters.h botan/mem_pool.h \ + botan/pbe_pkcs.h botan/rsa.h botan/x509_crl.h botan/asn1.h \ + botan/certstor.h botan/dlies.h botan/fips140.h botan/mgf1.h \ + botan/pem.h botan/s2k.h botan/x509_key.h botan/asn1_obj.h \ + botan/cfb.h botan/modebase.h \ + botan/pipe.h botan/x509_obj.h \ + botan/asn1_oid.h botan/conf.h botan/eax.h botan/gzip.h \ + botan/mode_pad.h botan/pk_algs.h botan/secmem.h \ + botan/x509self.h botan/barrett.h botan/config.h botan/ecb.h \ + botan/hex.h botan/pk_core.h botan/secqueue.h \ + botan/x509stor.h botan/base64.h botan/crc32.h botan/eme.h \ + botan/hmac.h botan/mp_core.h botan/pkcs10.h botan/sha160.h \ + botan/crl_ent.h botan/emsa.h \ + botan/if_algo.h botan/pkcs8.h \ + botan/x919_mac.h botan/basefilt.h botan/ctr.h botan/engine.h \ + botan/init.h botan/mp_types.h botan/pk_filts.h botan/symkey.h \ + botan/base.h botan/cts.h botan/enums.h botan/kdf.h \ + botan/mutex.h botan/pk_keys.h botan/timers.h botan/ber_dec.h \ + botan/data_snk.h botan/es_capi.h botan/keypair.h \ + botan/numthry.h botan/pk_ops.h botan/types.h botan/bigint.h \ + botan/data_src.h botan/es_egd.h botan/look_add.h botan/ofb.h \ + botan/pk_util.h botan/ui.h botan/blinding.h botan/defalloc.h \ + botan/es_file.h botan/look_pk.h botan/oids.h botan/pubkey.h \ + botan/util.h botan/charset.h botan/hash_id.h \ + botan/des.h botan/pkcs5.h \ botan/x931_rng.h botan/sha256.h \ - botan/parsing.h botan/out_buf.h botan/bit_ops.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/aes.cpp ea31ea6f8b2b7dc8edebeceaf6cd76dcea951c43 +++ botan/aes.cpp 36910ce25c53f6e23f10415c653d2e7a54f58b83 @@ -1,6 +1,6 @@ /************************************************* * AES Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -124,12 +124,12 @@ SecureBuffer XEK, XDK; const u32bit X = length / 4; - for(u32bit j = 0; j != X; j++) + for(u32bit j = 0; j != X; ++j) XEK[j] = make_u32bit(key[4*j], key[4*j+1], key[4*j+2], key[4*j+3]); for(u32bit j = X; j < 4*(ROUNDS+1); j += X) { XEK[j] = XEK[j-X] ^ S(rotate_left(XEK[j-1], 8)) ^ RC[(j-X)/X]; - for(u32bit k = 1; k != X; k++) + for(u32bit k = 1; k != X; ++k) { if(X == 8 && k == 4) XEK[j+k] = XEK[j+k-X] ^ S(XEK[j+k-1]); @@ -145,12 +145,12 @@ XDK[j+2] = XEK[4*ROUNDS-j+2]; XDK[j+3] = XEK[4*ROUNDS-j+3]; } - for(u32bit j = 4; j != length + 24; j++) + for(u32bit j = 4; j != length + 24; ++j) XDK[j] = TD0[SE[get_byte(0, XDK[j])]] ^ TD1[SE[get_byte(1, XDK[j])]] ^ TD2[SE[get_byte(2, XDK[j])]] ^ TD3[SE[get_byte(3, XDK[j])]]; - for(u32bit j = 0; j != 4; j++) - for(u32bit k = 0; k != 4; k++) + for(u32bit j = 0; j != 4; ++j) + for(u32bit k = 0; k != 4; ++k) { ME[4*j+k ] = get_byte(k, XEK[j]); ME[4*j+k+16] = get_byte(k, XEK[j+4*ROUNDS]); ============================================================ --- botan/aes.h dacdc0de1fe5484610985ef059e9368f0d7244a0 +++ botan/aes.h d49ff5b7d6e4e8d9ccf868ddf5bcf73b6a1d2b40 @@ -1,6 +1,6 @@ /************************************************* * AES Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_AES_H__ ============================================================ --- botan/aes_tab.cpp 475c0caff88d72d21371d3f0435634a375f1fa4b +++ botan/aes_tab.cpp ef5e48c69d986f8fa73967194f5b4759c9e13882 @@ -1,6 +1,6 @@ /************************************************* * S-Box and Diffusion Tables for AES * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/allocate.cpp 00af600bc30ed8c6ecfdea3fe716cd169626b05f +++ botan/allocate.cpp 56a088b78ca5962099fd16a131a08de2e903fa31 @@ -1,178 +1,25 @@ /************************************************* * Allocator Factory Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include -#include +#include #include -#include -#include #include namespace Botan { -namespace { - /************************************************* -* A factory for creating Allocators * -*************************************************/ -class AllocatorFactory - { - public: - Allocator* get(const std::string&) const; - Allocator* get_default() const; - void add(const std::string&, Allocator*); - std::string set_default_allocator(const std::string&); - - AllocatorFactory() { factory_mutex = get_mutex(); } - ~AllocatorFactory(); - private: - std::map alloc_map; - std::string default_allocator; - Mutex* factory_mutex; - }; - -/************************************************* -* Get an allocator from the factory * -*************************************************/ -Allocator* AllocatorFactory::get(const std::string& type) const - { - Mutex_Holder lock(factory_mutex); - - std::map::const_iterator iter; - if(type == "default") iter = alloc_map.find(default_allocator); - else iter = alloc_map.find(type); - - if(iter == alloc_map.end()) - return 0; - return iter->second; - } - -/************************************************* -* Get the default allocator from the factory * -*************************************************/ -Allocator* AllocatorFactory::get_default() const - { - Mutex_Holder lock(factory_mutex); - - std::map::const_iterator iter; - iter = alloc_map.find(default_allocator); - - if(iter == alloc_map.end()) - return 0; - return iter->second; - } - -/************************************************* -* Make a new type available to the factory * -*************************************************/ -void AllocatorFactory::add(const std::string& type, Allocator* allocator) - { - Mutex_Holder lock(factory_mutex); - allocator->init(); - alloc_map[type] = allocator; - } - -/************************************************* -* Set the default allocator type * -*************************************************/ -std::string AllocatorFactory::set_default_allocator(const std::string& alloc) - { - Mutex_Holder lock(factory_mutex); - - std::string old_default = default_allocator; - default_allocator = alloc; - return old_default; - } - -/************************************************* -* Destroy an allocator factory * -*************************************************/ -AllocatorFactory::~AllocatorFactory() - { - std::map::iterator iter; - for(iter = alloc_map.begin(); iter != alloc_map.end(); iter++) - { - iter->second->destroy(); - delete iter->second; - } - delete factory_mutex; - } - -/************************************************* -* Global State * -*************************************************/ -AllocatorFactory* factory = 0; - -} - -/************************************************* * Get an allocator * *************************************************/ Allocator* get_allocator(const std::string& type) { - if(!factory) - throw Invalid_State("LibraryInitializer not created, or it failed"); + Allocator* alloc = global_state().get_allocator(type); + if(alloc) + return alloc; - Allocator* alloc = 0; - - if(!type.empty()) - { - alloc = factory->get(type); - if(alloc) return alloc; - } - - alloc = factory->get_default(); - if(alloc) return alloc; - - alloc = factory->get("locking"); - if(alloc) return alloc; - throw Exception("Couldn't find an allocator to use in get_allocator"); } -/************************************************* -* Set the default allocator type * -*************************************************/ -std::string set_default_allocator(const std::string& type) - { - return factory->set_default_allocator(type); - } - -/************************************************* -* Add new allocator type * -*************************************************/ -bool add_allocator_type(const std::string& type, Allocator* alloc) - { - if(type == "" || factory->get(type)) - return false; - factory->add(type, alloc); - return true; - } - -namespace Init { - -/************************************************* -* Initialize the memory subsystem * -*************************************************/ -void startup_memory_subsystem() - { - factory = new AllocatorFactory; - - add_allocator_type("malloc", new Malloc_Allocator); - add_allocator_type("locking", new Locking_Allocator); - } - -/************************************************* -* Shut down the memory subsystem * -*************************************************/ -void shutdown_memory_subsystem() - { - delete factory; - factory = 0; - } - } - -} ============================================================ --- botan/allocate.h 825e8e9e89e22aba9d30c55f4e142b98bbab5dfd +++ botan/allocate.h 9129902ea8a05219f75168eb9272188efad37f4c @@ -1,6 +1,6 @@ /************************************************* * Allocator Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_ALLOCATOR_H__ @@ -17,8 +17,8 @@ class Allocator { public: - virtual void* allocate(u32bit) const = 0; - virtual void deallocate(void*, u32bit) const = 0; + virtual void* allocate(u32bit) = 0; + virtual void deallocate(void*, u32bit) = 0; virtual void init() {} virtual void destroy() {} @@ -31,16 +31,6 @@ *************************************************/ Allocator* get_allocator(const std::string& = ""); -/************************************************* -* Set the default allocator type * -*************************************************/ -std::string set_default_allocator(const std::string&); - -/************************************************* -* Add new allocator type * -*************************************************/ -bool add_allocator_type(const std::string&, Allocator*); - } #endif ============================================================ --- botan/arc4.cpp 7e17884686141d3b361384b0368c41ec4538411e +++ botan/arc4.cpp f7ce3d818c61afd4802635c5c442c6d1e17e7384 @@ -1,6 +1,6 @@ /************************************************* * ARC4 Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -60,9 +60,9 @@ void ARC4::key(const byte key[], u32bit length) { clear(); - for(u32bit j = 0; j != 256; j++) + for(u32bit j = 0; j != 256; ++j) state[j] = j; - for(u32bit j = 0, state_index = 0; j != 256; j++) + for(u32bit j = 0, state_index = 0; j != 256; ++j) { state_index = (state_index + key[j % length] + state[j]) % 256; std::swap(state[j], state[state_index]); ============================================================ --- botan/arc4.h 86febd85b9edfbe8a1ca0719659171b65f67bcab +++ botan/arc4.h 7c4390562e4ef982824e249298873a59d25c266e @@ -1,6 +1,6 @@ /************************************************* * ARC4 Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_ARC4_H__ ============================================================ --- botan/asn1.h a15a8ffd094119897e5490f155ca642d31ef803e +++ botan/asn1.h 334088388bdaeaedb3be9e412eba21f1948af0e2 @@ -1,6 +1,6 @@ /************************************************* * ASN.1 Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_ASN1_H__ ============================================================ --- botan/asn1_alg.cpp ecf1238bbee1ff0c59910a3baa65581f90683678 +++ botan/asn1_alg.cpp 665b7aba742c9e8b143a634c45377e287511fe1b @@ -1,6 +1,6 @@ /************************************************* * Algorithm Identifier Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/asn1_alt.cpp 2fc51199398f1163aee5a7b4d67e43824c7d4031 +++ botan/asn1_alt.cpp 87e52c4c5cf8b39d0df5274453b0f6a8643c9ec8 @@ -1,9 +1,10 @@ /************************************************* * AlternativeName Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include +#include #include namespace Botan { @@ -31,7 +32,7 @@ typedef std::multimap::iterator iter; std::pair range = alt_info.equal_range(type); - for(iter j = range.first; j != range.second; j++) + for(iter j = range.first; j != range.second; ++j) if(j->second == str) return; @@ -85,7 +86,7 @@ typedef std::multimap::iterator iter; std::pair range = attr.equal_range(type); - for(iter j = range.first; j != range.second; j++) + for(iter j = range.first; j != range.second; ++j) { ASN1_String asn1_string(j->second, IA5_STRING); DER::encode(encoder, asn1_string, tagging, CONTEXT_SPECIFIC); @@ -106,7 +107,7 @@ std::multimap othernames = alt_name.get_othernames(); std::multimap::const_iterator i; - for(i = othernames.begin(); i != othernames.end(); i++) + for(i = othernames.begin(); i != othernames.end(); ++i) { encoder.start_explicit(ASN1_Tag(0)); DER::encode(encoder, i->first); ============================================================ --- botan/asn1_att.cpp 636c751ebe11b317a810f0fbd8b0a024f05c0e97 +++ botan/asn1_att.cpp 58c6fe82ac89ac485b0c61fb628d838813d549ff @@ -1,6 +1,6 @@ /************************************************* * Attribute Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/asn1_dn.cpp 348a2b7b12c6a85b3cbb9e063781ed2112629072 +++ botan/asn1_dn.cpp 51b2ba4326c52163456a03becbc2249168ca3691 @@ -1,10 +1,11 @@ /************************************************* * X509_DN Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include #include +#include #include namespace Botan { @@ -22,7 +23,7 @@ X509_DN::X509_DN(const std::multimap& args) { std::multimap::const_iterator j; - for(j = args.begin(); j != args.end(); j++) + for(j = args.begin(); j != args.end(); ++j) add_attribute(j->first, j->second); } @@ -32,7 +33,7 @@ X509_DN::X509_DN(const std::multimap& args) { std::multimap::const_iterator j; - for(j = args.begin(); j != args.end(); j++) + for(j = args.begin(); j != args.end(); ++j) add_attribute(OIDS::lookup(j->first), j->second); } @@ -54,10 +55,10 @@ if(str == "") return; - typedef std::multimap::iterator rdn_iter; + typedef std::multimap::const_iterator rdn_iter; std::pair range = dn_info.equal_range(oid); - for(rdn_iter j = range.first; j != range.second; j++) + for(rdn_iter j = range.first; j != range.second; ++j) if(j->second.value() == str) return; @@ -73,7 +74,7 @@ typedef std::multimap::const_iterator rdn_iter; std::multimap retval; - for(rdn_iter j = dn_info.begin(); j != dn_info.end(); j++) + for(rdn_iter j = dn_info.begin(); j != dn_info.end(); ++j) multimap_insert(retval, j->first, j->second.value()); return retval; } @@ -89,7 +90,7 @@ std::pair range = dn_info.equal_range(oid); std::vector values; - for(rdn_iter j = range.first; j != range.second; j++) + for(rdn_iter j = range.first; j != range.second; ++j) values.push_back(j->second.value()); return values; } @@ -169,8 +170,8 @@ if(p1->first != p2->first) return false; if(!x500_name_cmp(p1->second, p2->second)) return false; - p1++; - p2++; + ++p1; + ++p2; } return true; } @@ -218,7 +219,7 @@ ASN1_Tag string_type, const std::string& oid_str, bool must_exist = false) { - typedef std::multimap::iterator rdn_iter; + typedef std::multimap::const_iterator rdn_iter; const OID oid = OIDS::lookup(oid_str); const bool exists = (dn_info.find(oid) != dn_info.end()); @@ -229,7 +230,7 @@ std::pair range = dn_info.equal_range(oid); - for(rdn_iter j = range.first; j != range.second; j++) + for(rdn_iter j = range.first; j != range.second; ++j) { ASN1_String asn1_string(j->second, string_type); ============================================================ --- botan/asn1_ext.cpp a8cc362726b13e9e81757a214fd39b684253a0ef +++ botan/asn1_ext.cpp f3680a101a9166ae78cf8a0eda8a73c9fb62f629 @@ -1,6 +1,6 @@ /************************************************* * Extension Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/asn1_ku.cpp e6ef3eb1cd606ca2b6d063ffc7daa8dcb4f74fb6 +++ botan/asn1_ku.cpp fe99df71ef816d3da3e2bd849ee41686553883c6 @@ -1,6 +1,6 @@ /************************************************* * KeyUsage Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -54,7 +54,7 @@ obj.value[obj.value.size()-1] &= mask; u16bit usage = 0; - for(u32bit j = 1; j != obj.value.size(); j++) + for(u32bit j = 1; j != obj.value.size(); ++j) usage = (obj.value[j] << 8) | usage; key_usage = Key_Constraints(usage); ============================================================ --- botan/asn1_obj.h 16357c964a2e7ee51e5501db6ff05971fa737aa5 +++ botan/asn1_obj.h 3ad02bee70f5b366cf0ba4db02242239a2ad4871 @@ -1,6 +1,6 @@ /************************************************* * Common ASN.1 Objects Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_ASN1_OBJ_H__ @@ -198,16 +198,6 @@ } -/************************************************* -* Insert a key/value pair into a multimap * -*************************************************/ -template -void multimap_insert(std::multimap& multimap, - const K& key, const V& value) - { - multimap.insert(std::make_pair(key, value)); - } - } #endif ============================================================ --- botan/asn1_oid.cpp e52090928114f5d6012df44b91b02c0c353cd2a2 +++ botan/asn1_oid.cpp cc34e0af65d596314b5f0cda21a766b591d3298c @@ -1,6 +1,6 @@ /************************************************* * ASN.1 OID Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -38,7 +38,7 @@ std::string OID::as_string() const { std::string oid_str; - for(u32bit j = 0; j != id.size(); j++) + for(u32bit j = 0; j != id.size(); ++j) { oid_str += to_string(id[j]); if(j != id.size() - 1) @@ -54,7 +54,7 @@ { if(id.size() != oid.id.size()) return false; - for(u32bit j = 0; j != id.size(); j++) + for(u32bit j = 0; j != id.size(); ++j) if(id[j] != oid.id[j]) return false; return true; @@ -99,7 +99,7 @@ return true; if(oid1.size() > oid2.size()) return false; - for(u32bit j = 0; j != oid1.size(); j++) + for(u32bit j = 0; j != oid1.size(); ++j) { if(oid1[j] < oid2[j]) return true; @@ -124,7 +124,7 @@ MemoryVector encoding; encoding.append(40 * oid[0] + oid[1]); - for(u32bit j = 2; j != oid.size(); j++) + for(u32bit j = 2; j != oid.size(); ++j) { if(oid[j] == 0) encoding.append(0); @@ -133,7 +133,7 @@ u32bit blocks = high_bit(oid[j]) + 6; blocks = (blocks - (blocks % 7)) / 7; - for(u32bit k = 0; k != blocks - 1; k++) + for(u32bit k = 0; k != blocks - 1; ++k) encoding.append(0x80 | ((oid[j] >> 7*(blocks-k-1)) & 0x7F)); encoding.append(oid[j] & 0x7F); } @@ -167,7 +167,7 @@ u32bit component = 0; while(j != obj.value.size() - 1) { - j++; + ++j; component = (component << 7) + (obj.value[j] & 0x7F); if(!(obj.value[j] & 0x80)) break; ============================================================ --- botan/asn1_oid.h f9678be8147d4e32f1836282704fd63060171924 +++ botan/asn1_oid.h 4d25477139ae7c1cc8524d89f44f5238fd6887df @@ -1,6 +1,6 @@ /************************************************* * ASN.1 OID Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_ASN1_OID_H__ ============================================================ --- botan/asn1_str.cpp 91c1b106a979607e99985bf4cc0b1378cf0d441a +++ botan/asn1_str.cpp bfc6d126540833320f8929b6dabed7008d5c98d2 @@ -1,6 +1,6 @@ /************************************************* * Simple ASN.1 String Types Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -41,7 +41,7 @@ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - for(u32bit j = 0; j != str.size(); j++) + for(u32bit j = 0; j != str.size(); ++j) if(!IS_PRINTABLE[(byte)str[j]]) { const std::string type = Config::get_string("x509/ca/str_type"); ============================================================ --- botan/asn1_tm.cpp 1c88ddb515e255c648e05944abf4eed36d03b518 +++ botan/asn1_tm.cpp 61b38e0a5379a4fb1f6331ecd404c3f30fac26e0 @@ -1,6 +1,6 @@ /************************************************* * X.509 Time Types Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -47,7 +47,7 @@ std::vector params; std::string current; - for(u32bit j = 0; j != time_str.size(); j++) + for(u32bit j = 0; j != time_str.size(); ++j) { if(is_digit(time_str[j])) current += time_str[j]; @@ -119,12 +119,12 @@ std::vector params; std::string current; - for(u32bit j = 0; j != YEAR_SIZE; j++) + for(u32bit j = 0; j != YEAR_SIZE; ++j) current += t_spec[j]; params.push_back(current); current = ""; - for(u32bit j = YEAR_SIZE; j != t_spec.size() - 1; j++) + for(u32bit j = YEAR_SIZE; j != t_spec.size() - 1; ++j) { current += t_spec[j]; if(current.size() == 2) ============================================================ --- botan/base.cpp 6f45870998d3f60d680be03512d0ed1a40345316 +++ botan/base.cpp 296db55bc172f248ad5effe0001475b37a04b64f @@ -1,11 +1,12 @@ /************************************************* * Base Classes Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include #include #include +#include namespace Botan { @@ -104,7 +105,7 @@ SecureVector our_mac = final(); if(our_mac.size() != length) return false; - for(u32bit j = 0; j != length; j++) + for(u32bit j = 0; j != length; ++j) if(mac[j] != our_mac[j]) return false; return true; @@ -216,15 +217,20 @@ /************************************************* * Add entropy to internal state * *************************************************/ -void RandomNumberGenerator::add_entropy(EntropySource& source, bool slowpoll) +u32bit RandomNumberGenerator::add_entropy(EntropySource& source, + bool slow_poll) { - SecureVector buffer(slowpoll ? 192 : 64); - u32bit returned; + SecureVector buffer(slow_poll ? 192 : 64); + u32bit bytes_gathered; - if(slowpoll) returned = source.slow_poll(buffer, buffer.size()); - else returned = source.fast_poll(buffer, buffer.size()); + if(slow_poll) + bytes_gathered = source.slow_poll(buffer, buffer.size()); + else + bytes_gathered = source.fast_poll(buffer, buffer.size()); - add_entropy(buffer, returned); + add_entropy(buffer, bytes_gathered); + + return entropy_estimate(buffer, buffer.size()); } /************************************************* ============================================================ --- botan/base.h f15a3205c8851a4a7413154b940c1ba0cab9c66d +++ botan/base.h dc0a0fa5199199f4d79c37359fc2e72c9d6b1ab1 @@ -1,6 +1,6 @@ /************************************************* * Base Classes Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_BASE_H__ @@ -157,7 +157,7 @@ virtual void randomize(byte[], u32bit) throw(PRNG_Unseeded) = 0; virtual bool is_seeded() const { return true; } void add_entropy(const byte[], u32bit); - void add_entropy(EntropySource&, bool = true); + u32bit add_entropy(EntropySource&, bool = true); virtual ~RandomNumberGenerator() {} private: virtual void add_randomness(const byte[], u32bit) = 0; ============================================================ --- botan/base64.cpp 397126d19a42c0fb831b4201828be936e55fa2a5 +++ botan/base64.cpp 98965c9a7f80c7fb11bc863fdb60f27ade0a841a @@ -1,6 +1,6 @@ /************************************************* * Base64 Encoder/Decoder Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -179,7 +179,7 @@ *************************************************/ void Base64_Decoder::write(const byte input[], u32bit length) { - for(u32bit j = 0; j != length; j++) + for(u32bit j = 0; j != length; ++j) { if(is_valid(input[j])) in[position++] = input[j]; ============================================================ --- botan/base64.h a230286f7ddfefab2e317197aed37cfa407e4494 +++ botan/base64.h 7d3b17fd067410d4f45630b62f288d3b77c00c7e @@ -1,6 +1,6 @@ /************************************************* * Base64 Encoder/Decoder Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_BASE64_H__ @@ -20,6 +20,7 @@ void write(const byte[], u32bit); void end_msg(); + // monotone-specific Base64_Encoder(bool = true, u32bit = 72); private: void encode_and_send(const byte[], u32bit); ============================================================ --- botan/basefilt.cpp 18aab554ecbec7a50c1606b283c636e75f9bd1a9 +++ botan/basefilt.cpp 762c9f006ae634c2d935fbd34a86e8566f71077c @@ -1,6 +1,6 @@ /************************************************* * Basic Filters Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -23,7 +23,7 @@ *************************************************/ Chain::Chain(Filter* filters[], u32bit count) { - for(u32bit j = 0; j != count; j++) + for(u32bit j = 0; j != count; ++j) if(filters[j]) { attach(filters[j]); ============================================================ --- botan/basefilt.h ba3cd0d8a3f0dc1ddeab8a7641cac1eed8f8b2cd +++ botan/basefilt.h 1c2652eaa8d52203589e94003df6b89172530b1b @@ -1,6 +1,6 @@ /************************************************* * Basic Filters Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_BASEFILT_H__ ============================================================ --- botan/ber_code.cpp 5142a48f04a95643b2b6cbb273e3d72b9c66be5e +++ botan/ber_code.cpp fca2b4d8e8ef99e4da32e42c4d3366b161d5723f @@ -1,6 +1,6 @@ /************************************************* * BER Decoding Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -123,7 +123,7 @@ for(u32bit j = obj.value.size(); j > 0; j--) if(obj.value[j-1]--) break; - for(u32bit j = 0; j != obj.value.size(); j++) + for(u32bit j = 0; j != obj.value.size(); ++j) obj.value[j] = ~obj.value[j]; } ============================================================ --- botan/ber_dec.cpp c15980c2152172bdd3f82953e8f631799512ff23 +++ botan/ber_dec.cpp cece03873562a6e12275e03485f249afb4e25628 @@ -1,6 +1,6 @@ /************************************************* * BER Decoder Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -39,7 +39,7 @@ throw Decoding_Error("BER long-form tag truncated"); if(tag_buf & 0xFF000000) throw Decoding_Error("BER long-form tag overflow"); - tag_bytes++; + ++tag_bytes; tag_buf = (tag_buf << 7) | (b & 0x7F); if((b & 0x80) == 0) break; } @@ -71,7 +71,7 @@ u32bit length = 0; - for(u32bit j = 0; j != field_size - 1; j++) + for(u32bit j = 0; j != field_size - 1; ++j) { if(get_byte(0, length) != 0) throw BER_Decoding_Error("Field length overflow"); @@ -96,12 +96,10 @@ *************************************************/ u32bit find_eoc(DataSource* ber) { - SecureVector data; + SecureVector buffer(DEFAULT_BUFFERSIZE), data; while(true) { - SecureVector buffer(DEFAULT_BUFFERSIZE); - const u32bit got = ber->peek(buffer, buffer.size(), data.size()); if(got == 0) break; ============================================================ --- botan/ber_dec.h 380987e05bd500b7663f5954bdb4a7c8b0e84241 +++ botan/ber_dec.h 7455c840d03e605912f08c95535bb31ce18ecf3b @@ -1,6 +1,6 @@ /************************************************* * BER Decoder Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_BER_DECODER_H__ ============================================================ --- botan/big_base.cpp 457e25de9b908c143815af89388f873a9ed57d1c +++ botan/big_base.cpp 7b7a61902c43b9488128d60b950a1a9ec6f667b8 @@ -1,14 +1,13 @@ /************************************************* * BigInt Base Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include -#include #include #include #include -#include +#include namespace Botan { @@ -24,8 +23,8 @@ const u32bit limbs_needed = sizeof(u64bit) / sizeof(word); - reg.create(2*limbs_needed + 2); - for(u32bit j = 0; j != limbs_needed; j++) + reg.create(2*limbs_needed); + for(u32bit j = 0; j != limbs_needed; ++j) reg[j] = (word)((n >> (j*MP_WORD_BITS)) & MP_WORD_MASK); } @@ -34,7 +33,7 @@ *************************************************/ BigInt::BigInt(Sign s, u32bit size) { - reg.create(size); + reg.create(round_up(size, 16)); signedness = s; } @@ -43,9 +42,12 @@ *************************************************/ BigInt::BigInt(const BigInt& b) { - if(b.sig_words()) + const u32bit b_words = b.sig_words(); + + if(b_words) { - reg.set(b.data(), b.sig_words()); + reg.create(round_up(b_words, 16)); + reg.copy(b.data(), b_words); set_sign(b.sign()); } else @@ -88,18 +90,6 @@ } /************************************************* -* Construct a Random BigInt * -*************************************************/ -BigInt::BigInt(NumberType type, u32bit bits) - { - set_sign(Positive); - if(type == Random && bits) - randomize(bits); - else if(type == Power2) - set_bit(bits); - } - -/************************************************* * Swap this BigInt with another * *************************************************/ void BigInt::swap(BigInt& other) @@ -133,7 +123,7 @@ reg[0] += n; if(reg[0] > temp) return; - for(u32bit j = 1; j != size(); j++) + for(u32bit j = 1; j != size(); ++j) if(++reg[j]) return; grow_to(2*size()); reg[size() / 2] = 1; @@ -149,7 +139,7 @@ reg[0] -= n; if(reg[0] < temp) return; - for(u32bit j = 1; j != size(); j++) + for(u32bit j = 1; j != size(); ++j) if(reg[j]--) return; reg.create(2); flip_sign(); @@ -196,7 +186,7 @@ throw Encoding_Error("BigInt::to_u32bit: Number is too big to convert"); u32bit out = 0; - for(u32bit j = 0; j != 4; j++) + for(u32bit j = 0; j != 4; ++j) out = (out << 8) | byte_at(3-j); return out; } @@ -223,21 +213,21 @@ } /************************************************* -* Return nibble n of this number * +* Return bits {offset...offset+length} * *************************************************/ -u32bit BigInt::get_nibble(u32bit n, u32bit nibble_size) const +u32bit BigInt::get_substring(u32bit offset, u32bit length) const { - if(nibble_size > 32) - throw Invalid_Argument("BigInt::get_nibble: Nibble size too large"); + if(length > 32) + throw Invalid_Argument("BigInt::get_substring: Substring size too big"); - u32bit nibble = 0; - for(s32bit j = (s32bit)nibble_size-1; j >= 0; j--) - { - nibble <<= 1; - if(get_bit(n * nibble_size + j)) - nibble |= 1; - } - return nibble; + u64bit piece = 0; + for(u32bit j = 0; j != 8; ++j) + piece = (piece << 8) | byte_at((offset / 8) + (7-j)); + + u64bit mask = (1 << length) - 1; + u32bit shift = (offset % 8); + + return ((piece >> shift) & mask); } /************************************************* @@ -274,7 +264,7 @@ const word mask = ((word)1 << (n % MP_WORD_BITS)) - 1; if(top_word < size()) - for(u32bit j = top_word + 1; j != size(); j++) + for(u32bit j = top_word + 1; j != size(); ++j) reg[j] = 0; reg[top_word] &= mask; @@ -343,7 +333,7 @@ *************************************************/ bool BigInt::is_zero() const { - for(u32bit j = 0; j != size(); j++) + for(u32bit j = 0; j != size(); ++j) if(reg[j]) return false; return true; } @@ -398,32 +388,12 @@ } /************************************************* -* Randomize this number * -*************************************************/ -void BigInt::randomize(u32bit bitsize, RNG_Quality level) - { - set_sign(Positive); - - if(bitsize == 0) - clear(); - else - { - SecureVector array((bitsize + 7) / 8); - Global_RNG::randomize(array, array.size(), level); - if(bitsize % 8) - array[0] &= 0xFF >> (8 - (bitsize % 8)); - array[0] |= 0x80 >> ((bitsize % 8) ? (8 - bitsize % 8) : 0); - binary_decode(array, array.size()); - } - } - -/************************************************* * Encode this number into bytes * *************************************************/ void BigInt::binary_encode(byte output[]) const { const u32bit sig_bytes = bytes(); - for(u32bit j = 0; j != sig_bytes; j++) + for(u32bit j = 0; j != sig_bytes; ++j) output[sig_bytes-j-1] = byte_at(j); } @@ -433,55 +403,16 @@ void BigInt::binary_decode(const byte buf[], u32bit length) { const u32bit WORD_BYTES = sizeof(word); - reg.create(length / WORD_BYTES + 1); + reg.create(round_up(length / WORD_BYTES + 1, 4)); - for(u32bit j = 0; j != length / WORD_BYTES; j++) + for(u32bit j = 0; j != length / WORD_BYTES; ++j) { u32bit top = length - WORD_BYTES*j; 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++) + for(u32bit j = 0; j != length % WORD_BYTES; ++j) reg[length / WORD_BYTES] = (reg[length / WORD_BYTES] << 8) | buf[j]; } -/************************************************* -* Generate a random integer * -*************************************************/ -BigInt random_integer(u32bit bits, RNG_Quality level) - { - BigInt x; - x.randomize(bits, level); - return x; - } - -/************************************************* -* Generate a random integer within given range * -*************************************************/ -BigInt random_integer(const BigInt& min, const BigInt& max, RNG_Quality level) - { - BigInt range = max - min; - - if(range <= 0) - throw Invalid_Argument("random_integer: invalid min/max values"); - - return (min + (random_integer(range.bits() + 2, level) % range)); - } - -/************************************************* -* Generate a random safe prime * -*************************************************/ -BigInt random_safe_prime(u32bit bits, RNG_Quality level) - { - if(bits <= 64) - throw Invalid_Argument("random_safe_prime: Can't make a prime of " + - to_string(bits) + " bits"); - - BigInt p; - do - p = (random_prime(bits - 1, level) << 1) + 1; - while(!is_prime(p)); - return p; - } - } ============================================================ --- botan/big_code.cpp 9b6b6e6f233069e72f4b621d7e2a867bbed3d5b1 +++ botan/big_code.cpp 016dac5924166630ef4d213ce59811a7725247a7 @@ -1,6 +1,6 @@ /************************************************* * BigInt Encoding/Decoding Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -21,14 +21,14 @@ { SecureVector binary(n.encoded_size(Binary)); n.binary_encode(binary); - for(u32bit j = 0; j != binary.size(); j++) + for(u32bit j = 0; j != binary.size(); ++j) Hex_Encoder::encode(binary[j], output + 2*j); } else if(base == Octal) { BigInt copy = n; const u32bit output_size = n.encoded_size(Octal); - for(u32bit j = 0; j != output_size; j++) + for(u32bit j = 0; j != output_size; ++j) { output[output_size - 1 - j] = digit2char(copy % 8); copy /= 8; @@ -40,7 +40,7 @@ BigInt remainder; copy.set_sign(Positive); const u32bit output_size = n.encoded_size(Decimal); - for(u32bit j = 0; j != output_size; j++) + for(u32bit j = 0; j != output_size; ++j) { divide(copy, 10, copy, remainder); output[output_size - 1 - j] = digit2char(remainder.word_at(0)); @@ -60,7 +60,7 @@ SecureVector output(n.encoded_size(base)); encode(output, n, base); if(base != Binary) - for(u32bit j = 0; j != output.size(); j++) + for(u32bit j = 0; j != output.size(); ++j) if(output[j] == 0) output[j] = '0'; return output; @@ -101,7 +101,7 @@ else if(base == Hexadecimal) { SecureVector hex; - for(u32bit j = 0; j != length; j++) + for(u32bit j = 0; j != length; ++j) if(Hex_Decoder::is_valid(buf[j])) hex.append(buf[j]); @@ -114,14 +114,14 @@ binary[0] = Hex_Decoder::decode(temp); } - for(u32bit j = offset; j != binary.size(); j++) + for(u32bit j = offset; j != binary.size(); ++j) binary[j] = Hex_Decoder::decode(hex+2*j-offset); r.binary_decode(binary, binary.size()); } else if(base == Decimal || base == Octal) { const u32bit RADIX = ((base == Decimal) ? 10 : 8); - for(u32bit j = 0; j != length; j++) + for(u32bit j = 0; j != length; ++j) { byte x = char2digit(buf[j]); if(x >= RADIX) ============================================================ --- botan/big_io.cpp 17083ec29a3235fba2817a5117cc4c303434df3d +++ botan/big_io.cpp 69a6680403cf935f3cff67a9a0fd9709d7dc77dc @@ -1,6 +1,6 @@ /************************************************* * BigInt Input/Output Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -28,7 +28,7 @@ SecureVector buffer = BigInt::encode(n, base); u32bit skip = 0; while(buffer[skip] == '0' && skip < buffer.size()) - skip++; + ++skip; stream.write((const char*)buffer.begin() + skip, buffer.size() - skip); } if(!stream.good()) ============================================================ --- botan/big_ops2.cpp 7cb04ca6277c03495e7e1035f4f0c5d3ca652e60 +++ botan/big_ops2.cpp 600fa64bbc1306e4d48e6717baf28dccb97a4bd8 @@ -1,6 +1,6 @@ /************************************************* * BigInt Assignment Operators Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/big_ops3.cpp 033d775b361c8e20acd3d6b67faff41519e0a4d5 +++ botan/big_ops3.cpp ed35714c74e8a46cc83510b94aa88252759055ba @@ -1,6 +1,6 @@ /************************************************* * BigInt Binary Operators Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/bigint.h 0f4e2101aad1e358bfbba6a7e5b136c42566786c +++ botan/bigint.h 2f22d329675f1cdae7ab5c2824067e58a4467f30 @@ -1,6 +1,6 @@ /************************************************* * BigInt Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_BIGINT_H__ @@ -57,7 +57,7 @@ void mask_bits(u32bit); bool get_bit(u32bit) const; - u32bit get_nibble(u32bit, u32bit) const; + u32bit get_substring(u32bit, u32bit) const; byte byte_at(u32bit) const; word word_at(u32bit) const; @@ -84,7 +84,7 @@ word operator[](u32bit index) const { return reg[index]; } void clear() { reg.clear(); } - void randomize(u32bit = 0, RNG_Quality = SessionKey); + void randomize(u32bit = 0); void binary_encode(byte[]) const; void binary_decode(const byte[], u32bit); @@ -98,7 +98,8 @@ void swap(BigInt&); - BigInt(u64bit = 0); + BigInt() { signedness = Positive; } + BigInt(u64bit); BigInt(const BigInt&); BigInt(const std::string&); BigInt(const byte[], u32bit, Base = Binary); @@ -107,8 +108,8 @@ private: friend void modifying_divide(BigInt&, BigInt&, BigInt&); void grow_to(u32bit n) const { reg.grow_to(n); } + SecureVector reg; Sign signedness; - SecureVector reg; }; /************************************************* ============================================================ --- botan/bit_ops.cpp d07b224e9e1d15bb7ce59d0a374e236cd803e895 +++ botan/bit_ops.cpp 9548063db26062adee735f47a045a2e8b246edf6 @@ -1,6 +1,6 @@ /************************************************* * Bit/Word Operations Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -20,7 +20,7 @@ data[6] ^= mask[6]; data[7] ^= mask[7]; data += 8; mask += 8; length -= 8; } - for(u32bit j = 0; j != length; j++) + for(u32bit j = 0; j != length; ++j) data[j] ^= mask[j]; } @@ -34,7 +34,7 @@ out[6] = in[6] ^ mask[6]; out[7] = in[7] ^ mask[7]; in += 8; out += 8; mask += 8; length -= 8; } - for(u32bit j = 0; j != length; j++) + for(u32bit j = 0; j != length; ++j) out[j] = in[j] ^ mask[j]; } @@ -77,7 +77,7 @@ *************************************************/ u32bit significant_bytes(u64bit n) { - for(u32bit j = 0; j != 8; j++) + for(u32bit j = 0; j != 8; ++j) if(get_byte(j, n)) return 8-j; return 0; @@ -89,9 +89,9 @@ u32bit hamming_weight(u64bit n) { u32bit weight = 0; - for(u32bit j = 0; j != 64; j++) + for(u32bit j = 0; j != 64; ++j) if((n >> j) & 0x01) - weight++; + ++weight; return weight; } ============================================================ --- botan/bit_ops.h 15f92e1769a8715806856e0d5a64b571779f44bc +++ botan/bit_ops.h 322ee2eec0304c996d7816aba3d735a47db66b47 @@ -1,6 +1,6 @@ /************************************************* * Bit/Word Operations Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_BIT_OPS_H__ ============================================================ --- botan/blinding.cpp 409b0a4f351117490772f07a5328ce0ec88a420b +++ botan/blinding.cpp 4b2356d837f6957a9997bd35e2334a044e3ed5f6 @@ -1,9 +1,10 @@ /************************************************* * Blinder Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include +#include #include namespace Botan { ============================================================ --- botan/blinding.h 93d726432666ec51edd74003647882948261d9fd +++ botan/blinding.h ac3050bb8acdb4d1fa77680e7c4602ef30778021 @@ -1,13 +1,12 @@ /************************************************* * Blinder Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_BLINDER_H__ #define BOTAN_BLINDER_H__ #include -#include namespace Botan { @@ -29,7 +28,7 @@ private: mutable BigInt e, d; BigInt n; - ModularReducer* reducer; + class ModularReducer* reducer; }; } ============================================================ --- botan/botan.h b67160e0ce2e91677445439823e4e020963551d9 +++ botan/botan.h 76631677430121056a988cfa6e8c53112a813a5c @@ -1,6 +1,6 @@ /************************************************* * Botan Core Interface Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/buf_es.cpp 9d7a0ba8efe806a4088786015e31a41bcf73a433 +++ botan/buf_es.cpp 4ce4aba6edc36d7a36afe4c274d02134f641fed9 @@ -1,6 +1,6 @@ /************************************************* * Buffered EntropySource Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/buf_es.h 92c7fed684a29fa220d3320c0b3ca431874ddc8e +++ botan/buf_es.h b2d0dfcc87c0ef93a415b96460fb91650bab50ce @@ -1,6 +1,6 @@ /************************************************* * Buffered EntropySource Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_BUFFERED_ES_H__ ============================================================ --- botan/buf_filt.cpp 42c8a97f415ccacfe8b3ddaa29df18151b5dc6a7 +++ botan/buf_filt.cpp acf427f400125c1e9427da10f35d2a1f435adc4e @@ -1,6 +1,6 @@ /************************************************* * Buffering Filter Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/buf_filt.h 82b9c858e60af6bf816750888764e9330a6125c4 +++ botan/buf_filt.h 7282bd3d30c910df817e76a6c9946c129ebfce26 @@ -1,6 +1,6 @@ /************************************************* * Buffering Filter Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_BUFFERING_FILTER_H__ ============================================================ --- botan/cbc.cpp 482ead7cd979dedb9264dee265141f3f62cd8b24 +++ botan/cbc.cpp d2dba7243726bc71889bcfcf69aeae09bfae5f88 @@ -1,6 +1,6 @@ /************************************************* * CBC Mode Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/cbc.h 0ea0edd6d72aa5c8baec83cf46d075e326b05006 +++ botan/cbc.h 8d0a2b5c936d2be6750f3870cab6f4f262358751 @@ -1,6 +1,6 @@ /************************************************* * CBC Mode Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_CBC_H__ ============================================================ --- botan/certstor.h 0ac4c8644a5d17b7adb2868f37fe9fcc8adc310c +++ botan/certstor.h f76ddb23c18ad7da273da838831ce1b4f9e99e1f @@ -1,6 +1,6 @@ /************************************************* * Certificate Store Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_CERT_STORE_H__ ============================================================ --- botan/certstore.cpp d9840e20d737606905f1b846de1faa49870e4357 +++ botan/certstore.cpp 4decdbbea3ecee7c3db7a80ba2d58a2aed60a61f @@ -1,6 +1,6 @@ /************************************************* * Certificate Store Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/cfb.cpp fd5cc8fd41bf529237261b94a0c07749130aa71f +++ botan/cfb.cpp 16a90ba04269adf38b456ced5487f410d9a15511 @@ -1,6 +1,6 @@ /************************************************* * CFB Mode Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -74,7 +74,7 @@ *************************************************/ void CFB_Encryption::feedback() { - for(u32bit j = 0; j != BLOCK_SIZE - FEEDBACK_SIZE; j++) + for(u32bit j = 0; j != BLOCK_SIZE - FEEDBACK_SIZE; ++j) state[j] = state[j + FEEDBACK_SIZE]; state.copy(BLOCK_SIZE - FEEDBACK_SIZE, buffer, FEEDBACK_SIZE); cipher->encrypt(state, buffer); @@ -131,7 +131,7 @@ *************************************************/ void CFB_Decryption::feedback() { - for(u32bit j = 0; j != BLOCK_SIZE - FEEDBACK_SIZE; j++) + for(u32bit j = 0; j != BLOCK_SIZE - FEEDBACK_SIZE; ++j) state[j] = state[j + FEEDBACK_SIZE]; state.copy(BLOCK_SIZE - FEEDBACK_SIZE, buffer, FEEDBACK_SIZE); cipher->encrypt(state, buffer); ============================================================ --- botan/cfb.h 283d95f7f0336c5c97242104439f666b5d190e13 +++ botan/cfb.h bb45d558c81fc04ab816789c2c8c83eab422e979 @@ -1,6 +1,6 @@ /************************************************* * CFB Mode Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_CFB_H__ ============================================================ --- botan/charset.cpp 4eefedeea00d833c01b8968cf09a391821389bfe +++ botan/charset.cpp f095fd1d76e6ae1d4458edb8eaa602b0fdf4f3b9 @@ -1,6 +1,6 @@ /************************************************* * Character Set Handling Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -46,7 +46,8 @@ if(c == '7') return 7; if(c == '8') return 8; if(c == '9') return 9; - throw Invalid_Argument("char2digit: Invalid decimal char " + c); + + throw Invalid_Argument("char2digit: Input is not a digit character"); } /************************************************* @@ -64,6 +65,7 @@ if(b == 7) return '7'; if(b == 8) return '8'; if(b == 9) return '9'; + throw Invalid_Argument("digit2char: Input is not a digit"); } ============================================================ --- botan/charset.h 0a2fc0cf36512cdfbe8725d7a08cf7c239638cc5 +++ botan/charset.h 3fa5c0845715e76ec0b071b5b550fea6d533ad43 @@ -1,6 +1,6 @@ /************************************************* * Character Set Handling Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_CHARSET_H__ ============================================================ --- botan/conf.cpp 5f2a4cb8d45511ae6ee082231974fc5da0150ef4 +++ botan/conf.cpp c5eecb1961bdb03dae462c2fc13958a225e269ce @@ -1,90 +1,17 @@ /************************************************* * Configuration Handling Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include +#include #include -#include #include #include #include -#include namespace Botan { -namespace { - -/************************************************* -* Holder for name-value option pairs * -*************************************************/ -class Options - { - public: - std::string get(const std::string&); - void set(const std::string&, const std::string&, bool); - - Options() { options_mutex = get_mutex(); } - ~Options() { delete options_mutex; } - private: - std::map options; - Mutex* options_mutex; - }; - -/************************************************* -* Get an option by name * -*************************************************/ -std::string Options::get(const std::string& name) - { - Mutex_Holder lock(options_mutex); - - std::map::const_iterator i = options.find(name); - if(i != options.end()) - return i->second; - return ""; - } - -/************************************************* -* Set an option by name * -*************************************************/ -void Options::set(const std::string& name, const std::string& value, - bool overwrite) - { - const bool have_it = ((get(name) == "") ? false : true); - - Mutex_Holder lock(options_mutex); - if(overwrite || !have_it) - options[name] = value; - } - -/************************************************* -* Global state * -*************************************************/ -Options* options = 0; - -} - -namespace Init { - -/************************************************* -* Startup the configuration system * -*************************************************/ -void startup_conf() - { - options = new Options; - } - -/************************************************* -* Shutdown the configuration system * -*************************************************/ -void shutdown_conf() - { - delete options; - options = 0; - } - -} - namespace Config { /************************************************* @@ -92,10 +19,7 @@ *************************************************/ void set(const std::string& name, const std::string& value, bool overwrite) { - if(!options) - throw Internal_Error("Config::set: Conf system never started"); - - options->set(name, value, overwrite); + global_state().set_option("conf", name, value, overwrite); } /************************************************* @@ -103,10 +27,7 @@ *************************************************/ std::string get_string(const std::string& name) { - if(!options) - throw Internal_Error("Config::get: Conf system never started"); - - return options->get(name); + return global_state().get_option("conf", name); } /************************************************* @@ -207,4 +128,26 @@ } +/************************************************* +* Add an alias for an algorithm * +*************************************************/ +void add_alias(const std::string& alias, const std::string& official_name) + { + if(alias == "" || official_name == "") + return; + + global_state().set_option("alias", alias, official_name); + } + +/************************************************* +* Dereference an alias * +*************************************************/ +std::string deref_alias(const std::string& name) + { + std::string result = name; + while(global_state().option_set("alias", result)) + result = global_state().get_option("alias", result); + return result; + } + } ============================================================ --- botan/conf.h 5d5aea8872719a387a22c036edf441fe140d0a60 +++ botan/conf.h 7b0d0cce1b5ead63091611fad7a2e9cdb840ee94 @@ -1,6 +1,6 @@ /************************************************* * Configuration Handling Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_POLICY_CONF_H__ @@ -13,9 +13,17 @@ namespace Botan { +class Library_State; + namespace Config { /************************************************* +* Load a configuration file * +*************************************************/ +void load(const std::string&); +void load(const std::string&, Library_State&); + +/************************************************* * Set an option * *************************************************/ void set(const std::string&, const std::string&, bool = true); @@ -36,11 +44,6 @@ void choose_sig_format(const std::string&, std::string&, std::string&, Signature_Format&); -/************************************************* -* Load a configuration file * -*************************************************/ -void load(const std::string&); - } } ============================================================ --- botan/config.h 985b707216c13e7cb2684c869166c4dc4e007a45 +++ botan/config.h 8ba878178154ac468e2db83883314b2a9a3a223e @@ -9,6 +9,10 @@ #define BOTAN_MP_WORD_BITS 32 #define BOTAN_DEFAULT_BUFFER_SIZE 4096 #define BOTAN_VECTOR_OVER_ALLOCATE 4 + +#define BOTAN_KARAT_MUL_THRESHOLD 12 +#define BOTAN_KARAT_SQR_THRESHOLD 12 + #define BOTAN_GZIP_OS_CODE 255 #if defined(_MSC_VER) @@ -16,8 +20,8 @@ #endif #define BOTAN_VERSION_MAJOR 1 -#define BOTAN_VERSION_MINOR 4 -#define BOTAN_VERSION_PATCH 3 +#define BOTAN_VERSION_MINOR 5 +#define BOTAN_VERSION_PATCH 2 #define BOTAN_EXT_COMPRESSOR_GZIP #define BOTAN_EXT_COMPRESSOR_ZLIB ============================================================ --- botan/crc32.cpp dcbaf9e6729d96e7218e16761f4fdbd1e86a8348 +++ botan/crc32.cpp 37a171205e892360539205e21f099fcf788cd33f @@ -1,6 +1,6 @@ /************************************************* * CRC32 Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -81,7 +81,7 @@ length -= 16; } - for(u32bit j = 0; j != length; j++) + for(u32bit j = 0; j != length; ++j) tmp = TABLE[(tmp ^ input[j]) & 0xFF] ^ (tmp >> 8); crc = tmp; @@ -93,7 +93,7 @@ void CRC32::final_result(byte output[]) { crc ^= 0xFFFFFFFF; - for(u32bit j = 0; j != 4; j++) + for(u32bit j = 0; j != 4; ++j) output[j] = get_byte(j, crc); clear(); } ============================================================ --- botan/crc32.h 14797da7c705de3d822da4419a90d8eced1dbd1f +++ botan/crc32.h f0b4e516463a6bb833eaa5cbfe6717b831860e14 @@ -1,6 +1,6 @@ /************************************************* * CRC32 Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_CRC32_H__ ============================================================ --- botan/crl_ent.cpp 4198f9e3689fab5978bded5b64f8f71a8f1a1ea0 +++ botan/crl_ent.cpp 7bd2c10f75bc3aeeeb35b9c70c63d5e1fb8bac87 @@ -1,6 +1,6 @@ /************************************************* * CRL Entry Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/crl_ent.h cec8c4510b2505708ff6dd2bb2a6d8e60ec792eb +++ botan/crl_ent.h 6da618c04c39d66ac775a4c7483410ba0b8619cd @@ -1,6 +1,6 @@ /************************************************* * CRL Entry Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_CRL_ENTRY_H__ ============================================================ --- botan/ctr.cpp e76cf9a87a8daa959b65e3ddc66014b6bef46427 +++ botan/ctr.cpp 68b39a43c1e77abc1e97b2c89fa3c5e4fa21b4ef @@ -1,6 +1,6 @@ /************************************************* * CTR Mode Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/ctr.h 60b1b31f804d1f2808420b3869f6c1141ae5ba19 +++ botan/ctr.h de9842ca4641c8e4c759178799af038053da3516 @@ -1,6 +1,6 @@ /************************************************* * CTR Mode Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_CTR_H__ ============================================================ --- botan/cts.cpp 76480a05851111771df7fb35dbe1f01a0caa3d3f +++ botan/cts.cpp 48dc412226b16f2be5f7502b3fe7888816724866 @@ -1,6 +1,6 @@ /************************************************* * CTS Mode Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/cts.h c458d765007da986f16e0775a69a8635b8f69742 +++ botan/cts.h b3629ba48d49a2501e447a48eda76850f34130f9 @@ -1,6 +1,6 @@ /************************************************* * CTS Mode Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_CTS_H__ ============================================================ --- botan/data_snk.cpp 9b5fa3d71ac32b238fcdc22f8ae1af48ebf141e2 +++ botan/data_snk.cpp 72e9615bb9e131d1ffa6f97e19f280a26d407617 @@ -1,6 +1,6 @@ /************************************************* * DataSink Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/data_snk.h 5ff5db19807ce5b4bec7589a89e670b8801c01a2 +++ botan/data_snk.h 2f0b3b675f98fb0e5133a998790fc0dd55b4c30d @@ -1,6 +1,6 @@ /************************************************* * DataSink Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_DATA_SINK_H__ ============================================================ --- botan/data_src.cpp 3d9619006e9ea1a111e099ba7d4738887485a36c +++ botan/data_src.cpp 43ac60765c3ffa36be55d080827411575510bc3e @@ -1,6 +1,6 @@ /************************************************* * DataSource Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -31,7 +31,7 @@ { u32bit discarded = 0; byte dummy; - for(u32bit j = 0; j != n; j++) + for(u32bit j = 0; j != n; ++j) discarded = read_byte(dummy); return discarded; } @@ -88,6 +88,15 @@ } /************************************************* +* DataSource_Memory Constructor * +*************************************************/ +DataSource_Memory::DataSource_Memory(const std::string& in) + { + source.set((const byte*)in.c_str(), in.length()); + offset = 0; + } + +/************************************************* * Read from a stream * *************************************************/ u32bit DataSource_Stream::read(byte out[], u32bit length) ============================================================ --- botan/data_src.h e60fe6c6f970926fbac49b25bdad2e1465dd11f9 +++ botan/data_src.h 3c1805ef300f5650a79f4ad6c1d0151f478cdf3b @@ -1,6 +1,6 @@ /************************************************* * DataSource Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_DATA_SRC_H__ @@ -43,6 +43,7 @@ u32bit peek(byte[], u32bit, u32bit) const; bool end_of_data() const; + DataSource_Memory(const std::string&); DataSource_Memory(const byte[], u32bit); DataSource_Memory(const MemoryRegion&); private: ============================================================ --- botan/def_alg.cpp 6149d258796a049d0bd371a8b537a35fccb4d09d +++ botan/def_alg.cpp b3f2228ad990d77ed9f3c44715153b2993cb5cf5 @@ -1,6 +1,6 @@ /************************************************* * Default Engine Algorithms Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -18,6 +18,9 @@ #include +#include +#include + namespace Botan { /************************************************* @@ -97,7 +100,6 @@ HANDLE_TYPE_ONE_U32BIT("ARC4", ARC4, 0); HANDLE_TYPE_ONE_U32BIT("RC4_drop", ARC4, 768); - return 0; } @@ -134,4 +136,41 @@ return 0; } +/************************************************* +* Look for an algorithm with this name * +*************************************************/ +S2K* Default_Engine::find_s2k(const std::string& algo_spec) const + { + std::vector name = parse_algorithm_name(algo_spec); + if(name.size() == 0) + return 0; + + const std::string algo_name = deref_alias(name[0]); + + HANDLE_TYPE_ONE_STRING("PBKDF1", PKCS5_PBKDF1); + HANDLE_TYPE_ONE_STRING("PBKDF2", PKCS5_PBKDF2); + + return 0; + } + +/************************************************* +* Look for an algorithm with this name * +*************************************************/ +BlockCipherModePaddingMethod* +Default_Engine::find_bc_pad(const std::string& algo_spec) const + { + std::vector name = parse_algorithm_name(algo_spec); + if(name.size() == 0) + return 0; + + const std::string algo_name = deref_alias(name[0]); + + HANDLE_TYPE_NO_ARGS("PKCS7", PKCS7_Padding); + HANDLE_TYPE_NO_ARGS("OneAndZeros", OneAndZeros_Padding); + HANDLE_TYPE_NO_ARGS("X9.23", ANSI_X923_Padding); + HANDLE_TYPE_NO_ARGS("NoPadding", Null_Padding); + + return 0; + } + } ============================================================ --- botan/def_eng.h cb6c6b9768a0e7c77e67e9eef6598904d85f3b0e +++ botan/def_eng.h 22f1fd366a3b8480b4101127aaca73ead0efda57 @@ -1,6 +1,6 @@ /************************************************* * Default Engine Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_DEFAULT_ENGINE_H__ @@ -25,14 +25,20 @@ ELG_Operation* elg_op(const DL_Group&, const BigInt&, const BigInt&) const; DH_Operation* dh_op(const DL_Group&, const BigInt&) const; - ModularReducer* reducer(const BigInt&, bool) const; + Modular_Exponentiator* mod_exp(const BigInt&, + Power_Mod::Usage_Hints) const; + Keyed_Filter* get_cipher(const std::string&, Cipher_Dir); private: BlockCipher* find_block_cipher(const std::string&) const; StreamCipher* find_stream_cipher(const std::string&) const; HashFunction* find_hash(const std::string&) const; MessageAuthenticationCode* find_mac(const std::string&) const; + + class S2K* find_s2k(const std::string&) const; + class BlockCipherModePaddingMethod* + find_bc_pad(const std::string&) const; }; } ============================================================ --- botan/def_mode.cpp 70796fa32f99c175755d464b29b9ebed8be84d79 +++ botan/def_mode.cpp a1267f1d3cc1c225d91dd630ff5231f6af48bae2 @@ -1,6 +1,6 @@ /************************************************* * Default Engine Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/def_ops.cpp 18c63eab3d6ada615f8988fd13f0a4d39d218ae3 +++ botan/def_ops.cpp 367e4d60c52f360117249e7b6c1d3804ca0db1f4 @@ -1,12 +1,12 @@ /************************************************* * Default Engine PK Operations Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include -#include +#include #include -#include +#include namespace Botan { @@ -18,32 +18,38 @@ class Default_IF_Op : public IF_Operation { public: - BigInt public_op(const BigInt& i) const { return powermod_e_n(i); } + BigInt public_op(const BigInt& i) const + { return powermod_e_n(i); } BigInt private_op(const BigInt&) const; - IF_Operation* clone() const { return new Default_IF_Op(*this); } + IF_Operation* clone() const; Default_IF_Op(const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&); + ~Default_IF_Op() { delete reduce_by_p; } private: - const BigInt q, c; - FixedExponent_Exp powermod_e_n, powermod_d1_p, powermod_d2_q; + const BigInt p, q, c; + Fixed_Exponent_Power_Mod powermod_e_n, powermod_d1_p, powermod_d2_q; + ModularReducer* reduce_by_p; }; /************************************************* * Default_IF_Op Constructor * *************************************************/ Default_IF_Op::Default_IF_Op(const BigInt& e, const BigInt& n, const BigInt&, - const BigInt& p, const BigInt& qx, + const BigInt& px, const BigInt& qx, const BigInt& d1, const BigInt& d2, - const BigInt& cx) : q(qx), c(cx) + const BigInt& cx) : p(px), q(qx), c(cx) { - powermod_e_n = FixedExponent_Exp(e, n); + powermod_e_n = Fixed_Exponent_Power_Mod(e, n); + reduce_by_p = 0; + if(d1 != 0 && d2 != 0 && p != 0 && q != 0) { - powermod_d1_p = FixedExponent_Exp(d1, p); - powermod_d2_q = FixedExponent_Exp(d2, q); + powermod_d1_p = Fixed_Exponent_Power_Mod(d1, p); + powermod_d2_q = Fixed_Exponent_Power_Mod(d2, q); + reduce_by_p = get_reducer(p); } } @@ -57,10 +63,26 @@ BigInt j1 = powermod_d1_p(i); BigInt j2 = powermod_d2_q(i); - return mul_add(powermod_d1_p.reduce(sub_mul(j1, j2, c)), q, j2); + j1 = reduce_by_p->reduce(sub_mul(j1, j2, c)); + return mul_add(j1, q, j2); } /************************************************* +* Make a copy of this Default_IF_Op * +*************************************************/ +IF_Operation* Default_IF_Op::clone() const + { + Default_IF_Op* copy = new Default_IF_Op(*this); + copy->reduce_by_p = 0; + + if(p != 0) + copy->reduce_by_p = get_reducer(p); + + return copy; + } + + +/************************************************* * Default DSA Operation * *************************************************/ class Default_DSA_Op : public DSA_Operation @@ -75,7 +97,7 @@ private: const BigInt x, y; const DL_Group group; - FixedBase_Exp powermod_g_p, powermod_y_p; + Fixed_Base_Power_Mod powermod_g_p, powermod_y_p; }; /************************************************* @@ -84,8 +106,8 @@ Default_DSA_Op::Default_DSA_Op(const DL_Group& grp, const BigInt& y1, const BigInt& x1) : x(x1), y(y1), group(grp) { - powermod_g_p = FixedBase_Exp(group.get_g(), group.get_p()); - powermod_y_p = FixedBase_Exp(y, group.get_p()); + powermod_g_p = Fixed_Base_Power_Mod(group.get_g(), group.get_p()); + powermod_y_p = Fixed_Base_Power_Mod(y, group.get_p()); } /************************************************* @@ -152,7 +174,7 @@ private: const BigInt x, y; const DL_Group group; - FixedBase_Exp powermod_g_p, powermod_y_p; + Fixed_Base_Power_Mod powermod_g_p, powermod_y_p; }; /************************************************* @@ -161,8 +183,8 @@ Default_NR_Op::Default_NR_Op(const DL_Group& grp, const BigInt& y1, const BigInt& x1) : x(x1), y(y1), group(grp) { - powermod_g_p = FixedBase_Exp(group.get_g(), group.get_p()); - powermod_y_p = FixedBase_Exp(y, group.get_p()); + powermod_g_p = Fixed_Base_Power_Mod(group.get_g(), group.get_p()); + powermod_y_p = Fixed_Base_Power_Mod(y, group.get_p()); } /************************************************* @@ -227,8 +249,8 @@ Default_ELG_Op(const DL_Group&, const BigInt&, const BigInt&); private: const BigInt p; - FixedBase_Exp powermod_g_p, powermod_y_p; - FixedExponent_Exp powermod_x_p; + Fixed_Base_Power_Mod powermod_g_p, powermod_y_p; + Fixed_Exponent_Power_Mod powermod_x_p; }; /************************************************* @@ -237,11 +259,11 @@ Default_ELG_Op::Default_ELG_Op(const DL_Group& group, const BigInt& y, const BigInt& x) : p(group.get_p()) { - powermod_g_p = FixedBase_Exp(group.get_g(), p); - powermod_y_p = FixedBase_Exp(y, p); + powermod_g_p = Fixed_Base_Power_Mod(group.get_g(), p); + powermod_y_p = Fixed_Base_Power_Mod(y, p); if(x != 0) - powermod_x_p = FixedExponent_Exp(x, p); + powermod_x_p = Fixed_Exponent_Power_Mod(x, p); } /************************************************* @@ -268,9 +290,6 @@ *************************************************/ BigInt Default_ELG_Op::decrypt(const BigInt& a, const BigInt& b) const { - if(!powermod_x_p.initialized()) - throw Internal_Error("Default_ELG_Op::decrypt: No private key"); - if(a >= p || b >= p) throw Invalid_Argument("Default_ELG_Op: Invalid message"); @@ -289,7 +308,7 @@ Default_DH_Op(const DL_Group& group, const BigInt& x) : powermod_x_p(x, group.get_p()) {} private: - const FixedExponent_Exp powermod_x_p; + const Fixed_Exponent_Power_Mod powermod_x_p; }; } @@ -341,12 +360,4 @@ return new Default_DH_Op(group, x); } -/************************************************* -* Acquire a ModularReducer * -*************************************************/ -ModularReducer* Default_Engine::reducer(const BigInt& n, bool) const - { - return new BarrettReducer(n); - } - } ============================================================ --- botan/defalloc.cpp 0a8c4ea4f0ff0831f906e30415ab78d3fe0678b9 +++ botan/defalloc.cpp d856af43a6ef36e704887ff86d7639d7d7de274a @@ -1,6 +1,6 @@ /************************************************* * Basic Allocators Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -49,7 +49,7 @@ /************************************************* * Malloc_Allocator's Allocation * *************************************************/ -void* Malloc_Allocator::alloc_block(u32bit n) const +void* Malloc_Allocator::alloc_block(u32bit n) { return do_malloc(n, false); } @@ -57,7 +57,7 @@ /************************************************* * Malloc_Allocator's Deallocation * *************************************************/ -void Malloc_Allocator::dealloc_block(void* ptr, u32bit n) const +void Malloc_Allocator::dealloc_block(void* ptr, u32bit n) { do_free(ptr, n, false); } @@ -65,7 +65,7 @@ /************************************************* * Locking_Allocator's Allocation * *************************************************/ -void* Locking_Allocator::alloc_block(u32bit n) const +void* Locking_Allocator::alloc_block(u32bit n) { return do_malloc(n, true); } @@ -73,7 +73,7 @@ /************************************************* * Locking_Allocator's Deallocation * *************************************************/ -void Locking_Allocator::dealloc_block(void* ptr, u32bit n) const +void Locking_Allocator::dealloc_block(void* ptr, u32bit n) { do_free(ptr, n, true); } ============================================================ --- botan/defalloc.h f3cbe94e43909da2f169b34e04217b2946fc429e +++ botan/defalloc.h f543c96588ec45e303a700a3014cafb3a66b6e56 @@ -1,6 +1,6 @@ /************************************************* * Basic Allocators Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_BASIC_ALLOC_H__ @@ -15,9 +15,11 @@ *************************************************/ class Malloc_Allocator : public Pooling_Allocator { + public: + Malloc_Allocator() : Pooling_Allocator(64*1024, false) {} private: - void* alloc_block(u32bit) const; - void dealloc_block(void*, u32bit) const; + void* alloc_block(u32bit); + void dealloc_block(void*, u32bit); }; /************************************************* @@ -25,11 +27,11 @@ *************************************************/ class Locking_Allocator : public Pooling_Allocator { + public: + Locking_Allocator() : Pooling_Allocator(64*1024, true) {} private: - void* alloc_block(u32bit) const; - void dealloc_block(void*, u32bit) const; - u32bit prealloc_bytes() const { return 256*1024; } - u32bit keep_free() const { return 256*1024; } + void* alloc_block(u32bit); + void dealloc_block(void*, u32bit); }; } ============================================================ --- botan/der_code.cpp 7d1a406cbfb6bef841797d6c44fe49d5dd730c03 +++ botan/der_code.cpp 2a13e0688e91eaf456bdf5db60c77fa371060849 @@ -1,6 +1,6 @@ /************************************************* * DER Coding Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -129,7 +129,7 @@ BigInt::encode(contents.begin() + extra_zero, n); if(n < 0) { - for(u32bit j = 0; j != contents.size(); j++) + for(u32bit j = 0; j != contents.size(); ++j) contents[j] = ~contents[j]; for(u32bit j = contents.size(); j > 0; j--) if(++contents[j-1]) ============================================================ --- botan/der_enc.cpp f5bb0bb31a85670d626e3c02c35850438a8fee4d +++ botan/der_enc.cpp e70973207fdf7ce3ad5a9c7c5c48f51a5de10ea1 @@ -1,6 +1,6 @@ /************************************************* * DER Encoder Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -30,7 +30,7 @@ blocks = (blocks - (blocks % 7)) / 7; encoded_tag.append(class_tag | 0x1F); - for(u32bit k = 0; k != blocks - 1; k++) + for(u32bit k = 0; k != blocks - 1; ++k) encoded_tag.append(0x80 | ((type_tag >> 7*(blocks-k-1)) & 0x7F)); encoded_tag.append(type_tag & 0x7F); } @@ -50,7 +50,7 @@ { const u32bit top_byte = significant_bytes(length); encoded_length.append((byte)(0x80 | top_byte)); - for(u32bit j = 4-top_byte; j != 4; j++) + for(u32bit j = 4-top_byte; j != 4; ++j) encoded_length.append(get_byte(j, length)); } return encoded_length; @@ -75,7 +75,7 @@ if(a.size() < b.size()) return true; if(a.size() > b.size()) return false; - for(u32bit j = 0; j != a.size(); j++) + for(u32bit j = 0; j != a.size(); ++j) { if(a[j] < b[j]) return true; if(a[j] > b[j]) return false; @@ -97,7 +97,7 @@ if(is_a_set) { std::sort(set_contents.begin(), set_contents.end(), DER_Cmp()); - for(u32bit j = 0; j != set_contents.size(); j++) + for(u32bit j = 0; j != set_contents.size(); ++j) contents.append(set_contents[j]); set_contents.clear(); } @@ -161,7 +161,7 @@ void DER_Encoder::start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag, bool is_a_set) { - sequence_level++; + ++sequence_level; subsequences.push_back(DER_Sequence(type_tag, class_tag, is_a_set)); } ============================================================ --- botan/der_enc.h 612aef07516329e81624156d1481208dd64a88f7 +++ botan/der_enc.h 93f8ef503b4a79e882c9ca9e6a4f3018b61d9821 @@ -1,6 +1,6 @@ /************************************************* * DER Encoder Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_DER_ENCODER_H__ ============================================================ --- botan/des.cpp 93600b024d9dbb9dea04535016120e4ae8f1aa3c +++ botan/des.cpp 789f5036773e7a823b36016967f0b351686f0e5a @@ -1,6 +1,6 @@ /************************************************* * DES Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -159,7 +159,7 @@ ((key[1] & 0x08) << 2) | ((key[0] & 0x08) << 1) | ((key[3] & 0x10) >> 1) | ((key[2] & 0x10) >> 2) | ((key[1] & 0x10) >> 3) | ((key[0] & 0x10) >> 4); - for(u32bit j = 0; j != 16; j++) + for(u32bit j = 0; j != 16; ++j) { C = ((C << ROT[j]) | (C >> (28-ROT[j]))) & 0x0FFFFFFF; D = ((D << ROT[j]) | (D >> (28-ROT[j]))) & 0x0FFFFFFF; ============================================================ --- botan/des.h 37d4e302b7efcd7abbdb1a5100350bddad8af1c9 +++ botan/des.h fa8ae2ada50a692c3eb15d3e6b21e4186ffaed3c @@ -1,6 +1,6 @@ /************************************************* * DES Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_DES_H__ ============================================================ --- botan/des_tab.cpp dcdc96f398b9788d6b10c5fc08e942a6cc65b87e +++ botan/des_tab.cpp a45c36b824fabc92baa7a6d2e4b2d1a99f5218b7 @@ -1,6 +1,6 @@ /************************************************* * Substitution/Permutation Tables for DES * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/dh.cpp 52df677e2549c49115b537a9bcb7d99073c4e7f1 +++ botan/dh.cpp 27a34a0adc82564aeaa30832cea48fa4bf2d7aee @@ -1,6 +1,6 @@ /************************************************* * Diffie-Hellman Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -43,7 +43,7 @@ group = grp; const BigInt& p = group_p(); - x = random_integer(2 * dl_work_factor(p.bits()), LongTermKey); + x = random_integer(2 * dl_work_factor(p.bits())); PKCS8_load_hook(); check_generated_private(); ============================================================ --- botan/dh.h 0eb696b0a935052659c8a3bd123d0e0f4f965a65 +++ botan/dh.h 4fc7d2c0deac3d48e36292dbd26e6a7d625d0882 @@ -1,6 +1,6 @@ /************************************************* * Diffie-Hellman Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_DIFFIE_HELLMAN_H__ ============================================================ --- botan/divide.cpp 71a6766759d8ea7a4f148fc7187b99c17168502c +++ botan/divide.cpp 40f8a31ed5731ea3bcabb611198c770e1f62774f @@ -1,6 +1,6 @@ /************************************************* * Division Algorithm Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -57,7 +57,7 @@ u32bit shifts = 0; while(y[y.sig_words()-1] < MP_WORD_TOP_BIT) - { x <<= 1; y <<= 1; shifts++; } + { x <<= 1; y <<= 1; ++shifts; } u32bit n = x.sig_words() - 1, t = y.sig_words() - 1; q.reg.create(n - t + 1); @@ -70,7 +70,7 @@ BigInt temp = y << (MP_WORD_BITS * (n-t)); - while(x >= temp) { x -= temp; q[n-t]++; } + while(x >= temp) { x -= temp; ++q[n-t]; } for(u32bit j = n; j != t; j--) { ============================================================ --- botan/dl_algo.cpp 407d1a5e155d69d0248bdf003b1d4ae1c59eb07e +++ botan/dl_algo.cpp d9f8c515eae2c8c6ebf98824b3207a55d7ad9068 @@ -1,6 +1,6 @@ /************************************************* * DL Scheme Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/dl_algo.h ba177f21543053329ffa01070970973d5db39a52 +++ botan/dl_algo.h 33a24d8853cd27257f062bdcdc0c0d638e727301 @@ -1,12 +1,12 @@ /************************************************* * DL Scheme Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_DL_ALGO_H__ #define BOTAN_DL_ALGO_H__ -#include +#include #include #include ============================================================ --- botan/dl_group.cpp c335b79e38e853a394fd76e734ea102480cf6042 +++ botan/dl_group.cpp df34a048f075aba4a2fb9d27c2e40e219d3cbd4a @@ -1,187 +1,308 @@ /************************************************* -* DL Groups Source File * -* (C) 1999-2005 The Botan Project * +* Discrete Logarithm Parameters Source File * +* (C) 1999-2006 The Botan Project * *************************************************/ -#include +#include +#include +#include +#include +#include +#include +#include +#include namespace Botan { -namespace { +/************************************************* +* DL_Group Constructor * +*************************************************/ +DL_Group::DL_Group() + { + initialized = false; + } /************************************************* -* IETF 768-bit DL modulus * +* DL_Group Constructor * *************************************************/ -const char* IETF_768_PRIME = - "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1" - "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD" - "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245" - "E485B576 625E7EC6 F44C42E9 A63A3620 FFFFFFFF FFFFFFFF"; +DL_Group::DL_Group(const std::string& type) + { + DataSource_Memory pem(global_state().get_option("dl", type)); + PEM_decode(pem); + } /************************************************* -* IETF 1024-bit DL modulus * +* DL_Group Constructor * *************************************************/ -const char* IETF_1024_PRIME = - "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1" - "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD" - "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245" - "E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED" - "EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE65381" - "FFFFFFFF FFFFFFFF"; +DL_Group::DL_Group(u32bit pbits, PrimeType type) + { + if(pbits < 512) + throw Invalid_Argument("DL_Group: prime size " + to_string(pbits) + + " is too small"); + if(type == Strong) + { + p = random_safe_prime(pbits); + q = (p - 1) / 2; + g = 2; + } + else if(type == Prime_Subgroup || type == DSA_Kosherizer) + { + if(type == Prime_Subgroup) + { + const u32bit qbits = 2 * dl_work_factor(pbits); + q = random_prime(qbits); + BigInt X; + while(p.bits() != pbits || !is_prime(p)) + { + X = random_integer(pbits); + p = X - (X % (2*q) - 1); + } + } + else + generate_dsa_primes(p, q, pbits); + + g = make_dsa_generator(p, q); + } + + initialized = true; + } + /************************************************* -* IETF 1536-bit DL modulus * +* DL_Group Constructor * *************************************************/ -const char* IETF_1536_PRIME = - "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1" - "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD" - "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245" - "E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED" - "EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D" - "C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F" - "83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D" - "670C354E 4ABC9804 F1746C08 CA237327 FFFFFFFF FFFFFFFF"; +DL_Group::DL_Group(const MemoryRegion& seed, u32bit pbits, u32bit start) + { + if(!generate_dsa_primes(p, q, seed.begin(), seed.size(), pbits, start)) + throw Invalid_Argument("DL_Group: The seed/counter given does not " + "generate a DSA group"); + g = make_dsa_generator(p, q); + + initialized = true; + } + /************************************************* -* IETF 2048-bit DL modulus * +* DL_Group Constructor * *************************************************/ -const char* IETF_2048_PRIME = - "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1" - "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD" - "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245" - "E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED" - "EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D" - "C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F" - "83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D" - "670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B" - "E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9" - "DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510" - "15728E5A 8AACAA68 FFFFFFFF FFFFFFFF"; +DL_Group::DL_Group(const BigInt& p1, const BigInt& g1) + { + initialize(p1, 0, g1); + } /************************************************* -* IETF 3072-bit DL modulus * +* DL_Group Constructor * *************************************************/ -const char* IETF_3072_PRIME = - "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1" - "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD" - "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245" - "E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED" - "EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D" - "C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F" - "83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D" - "670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B" - "E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9" - "DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510" - "15728E5A 8AAAC42D AD33170D 04507A33 A85521AB DF1CBA64" - "ECFB8504 58DBEF0A 8AEA7157 5D060C7D B3970F85 A6E1E4C7" - "ABF5AE8C DB0933D7 1E8C94E0 4A25619D CEE3D226 1AD2EE6B" - "F12FFA06 D98A0864 D8760273 3EC86A64 521F2B18 177B200C" - "BBE11757 7A615D6C 770988C0 BAD946E2 08E24FA0 74E5AB31" - "43DB5BFC E0FD108E 4B82D120 A93AD2CA FFFFFFFF FFFFFFFF"; +DL_Group::DL_Group(const BigInt& p1, const BigInt& q1, const BigInt& g1) + { + initialize(p1, q1, g1); + } /************************************************* -* IETF 4096-bit DL modulus * +* DL_Group Initializer * *************************************************/ -const char* IETF_4096_PRIME = - "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1" - "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD" - "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245" - "E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED" - "EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D" - "C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F" - "83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D" - "670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B" - "E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9" - "DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510" - "15728E5A 8AAAC42D AD33170D 04507A33 A85521AB DF1CBA64" - "ECFB8504 58DBEF0A 8AEA7157 5D060C7D B3970F85 A6E1E4C7" - "ABF5AE8C DB0933D7 1E8C94E0 4A25619D CEE3D226 1AD2EE6B" - "F12FFA06 D98A0864 D8760273 3EC86A64 521F2B18 177B200C" - "BBE11757 7A615D6C 770988C0 BAD946E2 08E24FA0 74E5AB31" - "43DB5BFC E0FD108E 4B82D120 A9210801 1A723C12 A787E6D7" - "88719A10 BDBA5B26 99C32718 6AF4E23C 1A946834 B6150BDA" - "2583E9CA 2AD44CE8 DBBBC2DB 04DE8EF9 2E8EFC14 1FBECAA6" - "287C5947 4E6BC05D 99B2964F A090C3A2 233BA186 515BE7ED" - "1F612970 CEE2D7AF B81BDD76 2170481C D0069127 D5B05AA9" - "93B4EA98 8D8FDDC1 86FFB7DC 90A6C08F 4DF435C9 34063199" - "FFFFFFFF FFFFFFFF"; +void DL_Group::initialize(const BigInt& p1, const BigInt& q1, const BigInt& g1) + { + if(p1 < 3) + throw Invalid_Argument("DL_Group: Prime invalid"); + if(g1 < 2 || g1 >= p1) + throw Invalid_Argument("DL_Group: Generator invalid"); + if(q1 < 0 || q1 >= p1) + throw Invalid_Argument("DL_Group: Subgroup invalid"); + p = p1; + g = g1; + q = q1; + + if(q == 0 && check_prime((p - 1) / 2)) + q = (p - 1) / 2; + + initialized = true; + } + /************************************************* -* JCE default 512-bit DSA group * +* Verify that the group has been set * *************************************************/ -const char* JCE_512_PRIME_P = - "FCA682CE 8E12CABA 26EFCCF7 110E526D B078B05E DECBCD1E" - "B4A208F3 AE1617AE 01F35B91 A47E6DF6 3413C5E1 2ED0899B" - "CD132ACD 50D99151 BDC43EE7 37592E17"; -const char* JCE_512_PRIME_Q = - "962EDDCC 369CBA8E BB260EE6 B6A126D9 346E38C5"; +void DL_Group::init_check() const + { + if(!initialized) + throw Invalid_State("DLP group cannot be used uninitialized"); + } /************************************************* -* JCE default 768-bit DSA group * +* Verify the parameters * *************************************************/ -const char* JCE_768_PRIME_P = - "E9E64259 9D355F37 C97FFD35 67120B8E 25C9CD43 E927B3A9" - "670FBEC5 D8901419 22D2C3B3 AD248009 3799869D 1E846AAB" - "49FAB0AD 26D2CE6A 22219D47 0BCE7D77 7D4A21FB E9C270B5" - "7F607002 F3CEF839 3694CF45 EE3688C1 1A8C56AB 127A3DAF"; -const char* JCE_768_PRIME_Q = - "9CDBD84C 9F1AC2F3 8D0F80F4 2AB952E7 338BF511"; +bool DL_Group::verify_group(bool strong) const + { + init_check(); + if(g < 2 || p < 3 || q < 0) + return false; + if((q != 0) && ((p - 1) % q != 0)) + return false; + + if(!strong) + return true; + + if(!check_prime(p)) + return false; + if((q > 0) && !check_prime(q)) + return false; + return true; + } + /************************************************* -* JCE default 1024-bit DSA group * +* Return the prime * *************************************************/ -const char* JCE_1024_PRIME_P = - "FD7F5381 1D751229 52DF4A9C 2EECE4E7 F611B752 3CEF4400" - "C31E3F80 B6512669 455D4022 51FB593D 8D58FABF C5F5BA30" - "F6CB9B55 6CD7813B 801D346F F26660B7 6B9950A5 A49F9FE8" - "047B1022 C24FBBA9 D7FEB7C6 1BF83B57 E7C6A8A6 150F04FB" - "83F6D3C5 1EC30235 54135A16 9132F675 F3AE2B61 D72AEFF2" - "2203199D D14801C7"; -const char* JCE_1024_PRIME_Q = - "9760508F 15230BCC B292B982 A2EB840B F0581CF5"; +const BigInt& DL_Group::get_p() const + { + init_check(); + return p; + } /************************************************* -* Decode the modulus string * +* Return the generator * *************************************************/ -BigInt decode(const char* prime) +const BigInt& DL_Group::get_g() const { - return BigInt::decode((const byte*)prime, std::strlen(prime), - BigInt::Hexadecimal); + init_check(); + return g; } -} +/************************************************* +* Return the subgroup * +*************************************************/ +const BigInt& DL_Group::get_q() const + { + init_check(); + if(q == 0) + throw Format_Error("DLP group has no q prime specified"); + return q; + } /************************************************* -* Try to obtain a particular DL group * +* DER encode the parameters * *************************************************/ -DL_Group try_to_get_dl_group(const std::string& name) +SecureVector DL_Group::DER_encode(Format format) const { - if(name == "DSA-512" || name == "DSA-768" || name == "DSA-1024") + init_check(); + + if((q == 0) && (format != PKCS_3)) + throw Encoding_Error("The ANSI DL parameter formats require a subgroup"); + + DER_Encoder encoder; + encoder.start_sequence(); + if(format == ANSI_X9_57) { - const char* P = 0; - const char* Q = 0; - if(name == "DSA-512") { P = JCE_512_PRIME_P; Q = JCE_512_PRIME_Q; } - if(name == "DSA-768") { P = JCE_768_PRIME_P; Q = JCE_768_PRIME_Q; } - if(name == "DSA-1024") { P = JCE_1024_PRIME_P; Q = JCE_1024_PRIME_Q; } + DER::encode(encoder, p); + DER::encode(encoder, q); + DER::encode(encoder, g); + } + else if(format == ANSI_X9_42) + { + DER::encode(encoder, p); + DER::encode(encoder, g); + DER::encode(encoder, q); + } + else if(format == PKCS_3) + { + DER::encode(encoder, p); + DER::encode(encoder, g); + } + else + throw Invalid_Argument("Unknown DL_Group encoding " + to_string(format)); + encoder.end_sequence(); - BigInt p = decode(P), q = decode(Q); - BigInt g = DL_Group::make_dsa_generator(p, q); - return DL_Group(p, q, g); + return encoder.get_contents(); + } + +/************************************************* +* PEM encode the parameters * +*************************************************/ +std::string DL_Group::PEM_encode(Format format) const + { + SecureVector encoding = DER_encode(format); + if(format == PKCS_3) + return PEM_Code::encode(encoding, "DH PARAMETERS"); + else if(format == ANSI_X9_57) + return PEM_Code::encode(encoding, "DSA PARAMETERS"); + else if(format == ANSI_X9_42) + return PEM_Code::encode(encoding, "X942 DH PARAMETERS"); + else + throw Invalid_Argument("Unknown DL_Group encoding " + to_string(format)); + } + +/************************************************* +* Decode BER encoded parameters * +*************************************************/ +void DL_Group::BER_decode(DataSource& source, Format format) + { + BigInt new_p, new_q, new_g; + + BER_Decoder decoder(source); + BER_Decoder sequence = BER::get_subsequence(decoder); + if(format == ANSI_X9_57) + { + BER::decode(sequence, new_p); + BER::decode(sequence, new_q); + BER::decode(sequence, new_g); } + else if(format == ANSI_X9_42) + { + BER::decode(sequence, new_p); + BER::decode(sequence, new_g); + BER::decode(sequence, new_q); + sequence.discard_remaining(); + } + else if(format == PKCS_3) + { + BER::decode(sequence, new_p); + BER::decode(sequence, new_g); + sequence.discard_remaining(); + } + else + throw Invalid_Argument("Unknown DL_Group encoding " + to_string(format)); + sequence.verify_end(); - BigInt p, g; + initialize(new_p, new_q, new_g); + } - if(name == "IETF-768") { g = 2; p = decode(IETF_768_PRIME); } - if(name == "IETF-1024") { g = 2; p = decode(IETF_1024_PRIME); } - if(name == "IETF-1536") { g = 2; p = decode(IETF_1536_PRIME); } - if(name == "IETF-2048") { g = 2; p = decode(IETF_2048_PRIME); } - if(name == "IETF-3072") { g = 2; p = decode(IETF_3072_PRIME); } - if(name == "IETF-4096") { g = 2; p = decode(IETF_4096_PRIME); } +/************************************************* +* Decode PEM encoded parameters * +*************************************************/ +void DL_Group::PEM_decode(DataSource& source) + { + std::string label; + DataSource_Memory ber(PEM_Code::decode(source, label)); - if(p > 0 && g > 0) - return DL_Group(p, g); + if(label == "DH PARAMETERS") + BER_decode(ber, PKCS_3); + else if(label == "DSA PARAMETERS") + BER_decode(ber, ANSI_X9_57); + else if(label == "X942 DH PARAMETERS") + BER_decode(ber, ANSI_X9_42); + else + throw Decoding_Error("DL_Group: Invalid PEM label " + label); + } - throw Lookup_Error("DL group \"" + name + "\" not found"); +/************************************************* +* Create a random DSA-style generator * +*************************************************/ +BigInt DL_Group::make_dsa_generator(const BigInt& p, const BigInt& q) + { + BigInt g, e = (p - 1) / q; + + for(u32bit j = 0; j != PRIME_TABLE_SIZE; ++j) + { + g = power_mod(PRIMES[j], e, p); + if(g != 1) + break; + } + + if(g == 1) + throw Exception("DL_Group: Couldn't create a suitable generator"); + + return g; } } ============================================================ --- botan/dlies.cpp b390b695f810705238efe69a61dd63b6ad945135 +++ botan/dlies.cpp 17ac2bfa1bf4c527c5b5ed886da76c9c8ea1df4c @@ -1,6 +1,6 @@ /************************************************* * DLIES Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -52,7 +52,7 @@ mac->set_key(K.begin(), MAC_KEYLEN); mac->update(C, length); - for(u32bit j = 0; j != 8; j++) + for(u32bit j = 0; j != 8; ++j) mac->update(0); mac->final(C + length); @@ -114,7 +114,7 @@ mac->set_key(K.begin(), MAC_KEYLEN); mac->update(C); - for(u32bit j = 0; j != 8; j++) + for(u32bit j = 0; j != 8; ++j) mac->update(0); SecureVector T2 = mac->final(); if(T != T2) ============================================================ --- botan/dlies.h 220cf9a63bc846e59dbe6c10b59207b25259131e +++ botan/dlies.h 0a3b5f38ec3c4216823fd8fbab906ff8697a8558 @@ -1,6 +1,6 @@ /************************************************* * DLIES Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_DLIES_H__ ============================================================ --- botan/eax.cpp 8dadb5fff8caa3da4342acb2206ba165873564cb +++ botan/eax.cpp e23c313cd6eaa3b5c0e3209f665d2bd5ef96085e @@ -1,6 +1,6 @@ /************************************************* * EAX Mode Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -19,7 +19,7 @@ MessageAuthenticationCode* mac, const byte in[], u32bit length) { - for(u32bit j = 0; j != BLOCK_SIZE - 1; j++) + for(u32bit j = 0; j != BLOCK_SIZE - 1; ++j) mac->update(0); mac->update(param); mac->update(in, length); @@ -76,7 +76,7 @@ *************************************************/ void EAX_Base::start_msg() { - for(u32bit j = 0; j != BLOCK_SIZE - 1; j++) + for(u32bit j = 0; j != BLOCK_SIZE - 1; ++j) mac->update(0); mac->update(2); } @@ -292,7 +292,7 @@ SecureVector data_mac = mac->final(); - for(u32bit j = 0; j != TAG_SIZE; j++) + for(u32bit j = 0; j != TAG_SIZE; ++j) if(queue[queue_start+j] != (data_mac[j] ^ nonce_mac[j] ^ header_mac[j])) throw Integrity_Failure(name() + ": Message authentication failure"); ============================================================ --- botan/eax.h 616ac13b534dbba4144a76bd601259cc59187bc7 +++ botan/eax.h 193bbdd18e398ac054a8e05ae553afbdec291c24 @@ -1,6 +1,6 @@ /************************************************* * EAX Mode Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_EAX_H__ ============================================================ --- botan/ecb.cpp 519758ea66834c37ce4da85b634e1f54fe1e67f1 +++ botan/ecb.cpp 281a354f3c97e99d8e808137d78c7dce5abff8ee @@ -1,6 +1,6 @@ /************************************************* * ECB Mode Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/ecb.h 43b8217ca2da247c5d3f5169e227ef0a2cd09ce5 +++ botan/ecb.h 37d5e3f25deeb99b34c17b492649c422e1aaae24 @@ -1,6 +1,6 @@ /************************************************* * ECB Mode Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_ECB_H__ ============================================================ --- botan/eme.h 4412c54e61d8e70e2d1f42e5bb48ffb1ab1fb92a +++ botan/eme.h b22fa5c9c91835dcc5f0915ef6f7ddad2ffb1c4d @@ -1,6 +1,6 @@ /************************************************* * EME Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_EME_H__ ============================================================ --- botan/eme1.cpp 096712e2e91e96d4684e5cc447bd44ade28e349c +++ botan/eme1.cpp e90e2aba0e7cc71829a641ee4f9077a5bede20b6 @@ -1,6 +1,6 @@ /************************************************* * EME1 Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -26,7 +26,7 @@ out.clear(); - Global_RNG::randomize(out, HASH_LENGTH, Nonce); + Global_RNG::randomize(out, HASH_LENGTH); out.copy(HASH_LENGTH, Phash, Phash.size()); out[out.size() - in_length - 1] = 0x01; @@ -53,11 +53,11 @@ mgf->mask(tmp + HASH_LENGTH, tmp.size() - HASH_LENGTH, tmp, HASH_LENGTH); mgf->mask(tmp, HASH_LENGTH, tmp + HASH_LENGTH, tmp.size() - HASH_LENGTH); - for(u32bit j = 0; j != Phash.size(); j++) + for(u32bit j = 0; j != Phash.size(); ++j) if(tmp[j+HASH_LENGTH] != Phash[j]) throw Decoding_Error("Invalid EME1 encoding"); - for(u32bit j = HASH_LENGTH + Phash.size(); j != tmp.size(); j++) + for(u32bit j = HASH_LENGTH + Phash.size(); j != tmp.size(); ++j) { if(tmp[j] && tmp[j] != 0x01) throw Decoding_Error("Invalid EME1 encoding"); ============================================================ --- botan/eme_pkcs.cpp 0300e9b5bff3abc77f2550e099f9079adcc27535 +++ botan/eme_pkcs.cpp b6d2dcbe4674c075e759ada4d4f8a3ff8759977e @@ -1,6 +1,6 @@ /************************************************* * PKCS1 EME Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -24,9 +24,9 @@ SecureVector out(olen); out[0] = 0x02; - for(u32bit j = 1; j != olen - inlen - 1; j++) + for(u32bit j = 1; j != olen - inlen - 1; ++j) while(out[j] == 0) - out[j] = Global_RNG::random(Nonce); + out[j] = Global_RNG::random(); out.copy(olen - inlen, in, inlen); return out; @@ -42,7 +42,7 @@ throw Decoding_Error("PKCS1::unpad"); u32bit seperator = 0; - for(u32bit j = 0; j != inlen; j++) + for(u32bit j = 0; j != inlen; ++j) if(in[j] == 0) { seperator = j; ============================================================ --- botan/emsa.h 8aed2c73d0d4b9b0e8dd48331d00d99475d62b17 +++ botan/emsa.h b2b17af13aba1286f993907e80aae49e4c3fb071 @@ -1,6 +1,6 @@ /************************************************* * EMSA Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_EMSA_H__ ============================================================ --- botan/emsa1.cpp 3256c2a0d2f330e83926775165e5727a69db8c89 +++ botan/emsa1.cpp c1f50b7abac1a37e8bf7dfcb06e36beda025dc85 @@ -1,6 +1,6 @@ /************************************************* * EMSA1 Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -32,21 +32,21 @@ { if(msg.size() != hash->OUTPUT_LENGTH) throw Invalid_Argument("EMSA1::encoding_of: Invalid size for input"); - if(msg.bits() <= output_bits) + if(8*msg.size() <= output_bits) return msg; - u32bit shift = msg.bits() - output_bits; + u32bit shift = 8*msg.size() - output_bits; u32bit byte_shift = shift / 8, bit_shift = shift % 8; SecureVector digest(msg.size() - byte_shift); - for(u32bit j = 0; j != msg.size() - byte_shift; j++) + for(u32bit j = 0; j != msg.size() - byte_shift; ++j) digest[j] = msg[j]; if(bit_shift) { byte carry = 0; - for(u32bit j = 0; j != digest.size(); j++) + for(u32bit j = 0; j != digest.size(); ++j) { byte temp = digest[j]; digest[j] = (temp >> bit_shift) | carry; @@ -75,7 +75,7 @@ if(our_coding.size() - offset != coded.size()) return false; - for(u32bit j = 0; j != coded.size(); j++) + for(u32bit j = 0; j != coded.size(); ++j) if(coded[j] != our_coding[j+offset]) return false; ============================================================ --- botan/emsa2.cpp cc579ea8d68707008de96718e57aa45744ba7d2f +++ botan/emsa2.cpp a4d8301f23805ba4bb2554591dfc20e373bce4ca @@ -1,6 +1,6 @@ /************************************************* * EMSA2 Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -39,7 +39,7 @@ throw Invalid_Argument("EMSA2::encoding_of: Output length is too small"); bool empty = true; - for(u32bit j = 0; j != hash->OUTPUT_LENGTH; j++) + for(u32bit j = 0; j != hash->OUTPUT_LENGTH; ++j) if(empty_hash[j] != msg[j]) empty = false; ============================================================ --- botan/emsa3.cpp 7ceb6622645006dbf646a9597260a04167bfd248 +++ botan/emsa3.cpp 367b509f38995bb4978b8f514239c97989fb63b3 @@ -1,6 +1,6 @@ /************************************************* * EMSA3 Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/emsa4.cpp e34dfab00b372e779b31be6b6d935d88177e144c +++ botan/emsa4.cpp a45dd0f15cdb2cb8f81d8493b44248f206bf44f2 @@ -1,6 +1,6 @@ /************************************************* * EMSA4 Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -43,9 +43,9 @@ const u32bit output_length = (output_bits + 7) / 8; SecureVector salt(SALT_SIZE); - Global_RNG::randomize(salt, SALT_SIZE, Nonce); + Global_RNG::randomize(salt, SALT_SIZE); - for(u32bit j = 0; j != 8; j++) + for(u32bit j = 0; j != 8; ++j) hash->update(0); hash->update(msg); hash->update(salt, SALT_SIZE); @@ -100,7 +100,7 @@ DB[0] &= 0xFF >> TOP_BITS; u32bit salt_offset = 0; - for(u32bit j = 0; j != DB.size(); j++) + for(u32bit j = 0; j != DB.size(); ++j) { if(DB[j] == 0x01) { salt_offset = j + 1; break; } @@ -112,7 +112,7 @@ SecureVector salt(DB + salt_offset, DB.size() - salt_offset); - for(u32bit j = 0; j != 8; j++) + for(u32bit j = 0; j != 8; ++j) hash->update(0); hash->update(raw); hash->update(salt); ============================================================ --- botan/emsa_raw.cpp 4f061b051bf6e32e48f4e56ee2f2b9a12054e076 +++ botan/emsa_raw.cpp 3b8914e43991c3700e12a01185d057491c08db11 @@ -1,6 +1,6 @@ /************************************************* * EMSA-Raw Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/eng_base.cpp 470b429437811de062b605a3eef110f890be77c4 +++ botan/eng_base.cpp 9eac0e75637f3f720e8557654829d8e5833646ff @@ -1,9 +1,11 @@ /************************************************* * Basic No-Op Engine Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include +#include +#include #include namespace Botan { @@ -56,29 +58,56 @@ /************************************************* * Basic No-Op Engine Implementation * *************************************************/ -ModularReducer* Engine::reducer(const BigInt&, bool) const +Modular_Exponentiator* Engine::mod_exp(const BigInt&, + Power_Mod::Usage_Hints) const { return 0; } /************************************************* +* Get an algorithm out of the table * +*************************************************/ +Algorithm* Engine::get_algo(const std::string& type, + const std::string& name) const + { + Mutex_Holder lock(mappings[type].first); + return search_map(mappings[type].second, name); + } + +/************************************************* +* Add an algorithm to the appropriate table * +*************************************************/ +void Engine::add_algo(const std::string& type, Algorithm* algo) const + { + if(!algo) + return; + + Mutex_Holder lock(mappings[type].first); + + std::map& map = mappings[type].second; + + const std::string algo_name = algo->name(); + + if(map.find(algo_name) != map.end()) + delete map[algo_name]; + map[algo_name] = algo; + } + +/************************************************* * Acquire a BlockCipher * *************************************************/ const BlockCipher* Engine::block_cipher(const std::string& name) const { - BlockCipher* retval = 0; - bc_map_lock->lock(); - std::map::const_iterator algo; - algo = bc_map.find(deref_alias(name)); - if(algo != bc_map.end()) - retval = algo->second; - bc_map_lock->unlock(); - if(!retval) - { - retval = find_block_cipher(deref_alias(name)); - add_algorithm(retval); - } - return retval; + const std::string real_name = deref_alias(name); + + Algorithm* got = get_algo("block_cipher", real_name); + + if(got) + return dynamic_cast(got); + + BlockCipher* to_return = find_block_cipher(real_name); + add_algorithm(to_return); + return to_return; } /************************************************* @@ -86,19 +115,16 @@ *************************************************/ const StreamCipher* Engine::stream_cipher(const std::string& name) const { - StreamCipher* retval = 0; - sc_map_lock->lock(); - std::map::const_iterator algo; - algo = sc_map.find(deref_alias(name)); - if(algo != sc_map.end()) - retval = algo->second; - sc_map_lock->unlock(); - if(!retval) - { - retval = find_stream_cipher(deref_alias(name)); - add_algorithm(retval); - } - return retval; + const std::string real_name = deref_alias(name); + + Algorithm* got = get_algo("stream_cipher", real_name); + + if(got) + return dynamic_cast(got); + + StreamCipher* to_return = find_stream_cipher(real_name); + add_algorithm(to_return); + return to_return; } /************************************************* @@ -106,19 +132,16 @@ *************************************************/ const HashFunction* Engine::hash(const std::string& name) const { - HashFunction* retval = 0; - hf_map_lock->lock(); - std::map::const_iterator algo; - algo = hf_map.find(deref_alias(name)); - if(algo != hf_map.end()) - retval = algo->second; - hf_map_lock->unlock(); - if(!retval) - { - retval = find_hash(deref_alias(name)); - add_algorithm(retval); - } - return retval; + const std::string real_name = deref_alias(name); + + Algorithm* got = get_algo("hash_func", real_name); + + if(got) + return dynamic_cast(got); + + HashFunction* to_return = find_hash(real_name); + add_algorithm(to_return); + return to_return; } /************************************************* @@ -126,32 +149,61 @@ *************************************************/ const MessageAuthenticationCode* Engine::mac(const std::string& name) const { - MessageAuthenticationCode* retval = 0; - mac_map_lock->lock(); - std::map::const_iterator algo; - algo = mac_map.find(deref_alias(name)); - if(algo != mac_map.end()) - retval = algo->second; - mac_map_lock->unlock(); - if(!retval) - { - retval = find_mac(deref_alias(name)); - add_algorithm(retval); - } - return retval; + const std::string real_name = deref_alias(name); + + Algorithm* got = get_algo("mac_func", real_name); + + if(got) + return dynamic_cast(got); + + MessageAuthenticationCode* to_return = find_mac(real_name); + add_algorithm(to_return); + return to_return; } /************************************************* +* Acquire a S2K object * +*************************************************/ +const S2K* Engine::s2k(const std::string& name) const + { + const std::string real_name = deref_alias(name); + + Algorithm* got = get_algo("s2k_func", real_name); + + if(got) + return dynamic_cast(got); + + S2K* to_return = find_s2k(real_name); + add_algorithm(to_return); + return to_return; + } + +/************************************************* +* Acquire a cipher padding object * +*************************************************/ +const BlockCipherModePaddingMethod* +Engine::bc_pad(const std::string& name) const + { + const std::string real_name = deref_alias(name); + + Algorithm* got = get_algo("bc_pad", real_name); + + if(got) + return dynamic_cast(got); + + BlockCipherModePaddingMethod* to_return = + find_bc_pad(real_name); + + add_algorithm(to_return); + return to_return; + } + +/************************************************* * Add a block cipher to the lookup table * *************************************************/ void Engine::add_algorithm(BlockCipher* algo) const { - if(!algo) return; - bc_map_lock->lock(); - if(bc_map.find(algo->name()) != bc_map.end()) - delete bc_map[algo->name()]; - bc_map[algo->name()] = algo; - bc_map_lock->unlock(); + add_algo("block_cipher", algo); } /************************************************* @@ -159,12 +211,7 @@ *************************************************/ void Engine::add_algorithm(StreamCipher* algo) const { - if(!algo) return; - sc_map_lock->lock(); - if(sc_map.find(algo->name()) != sc_map.end()) - delete sc_map[algo->name()]; - sc_map[algo->name()] = algo; - sc_map_lock->unlock(); + add_algo("stream_cipher", algo); } /************************************************* @@ -172,12 +219,7 @@ *************************************************/ void Engine::add_algorithm(HashFunction* algo) const { - if(!algo) return; - hf_map_lock->lock(); - if(hf_map.find(algo->name()) != hf_map.end()) - delete hf_map[algo->name()]; - hf_map[algo->name()] = algo; - hf_map_lock->unlock(); + add_algo("hash_func", algo); } /************************************************* @@ -185,23 +227,41 @@ *************************************************/ void Engine::add_algorithm(MessageAuthenticationCode* algo) const { - if(!algo) return; - mac_map_lock->lock(); - if(mac_map.find(algo->name()) != mac_map.end()) - delete mac_map[algo->name()]; - mac_map[algo->name()] = algo; - mac_map_lock->unlock(); + add_algo("mac_func", algo); } /************************************************* +* Add a S2K to the lookup table * +*************************************************/ +void Engine::add_algorithm(S2K* algo) const + { + add_algo("s2k_func", algo); + } + +/************************************************* +* Add a cipher pad method to the lookup table * +*************************************************/ +void Engine::add_algorithm(BlockCipherModePaddingMethod* algo) const + { + add_algo("bc_pad", algo); + } + +/************************************************* * Create an Engine * *************************************************/ Engine::Engine() { - bc_map_lock = get_mutex(); - sc_map_lock = get_mutex(); - hf_map_lock = get_mutex(); - mac_map_lock = get_mutex(); + const std::string TYPES[] = { + "block_cipher", "stream_cipher", "hash_func", "mac_func", + "s2k_func", "bc_pad", "" + }; + + for(u32bit j = 0; TYPES[j] != ""; ++j) + { + mappings[TYPES[j]] = + std::make_pair(global_state().get_mutex(), + std::map()); + } } /************************************************* @@ -209,26 +269,21 @@ *************************************************/ Engine::~Engine() { - std::map::iterator bc_iter; - for(bc_iter = bc_map.begin(); bc_iter != bc_map.end(); bc_iter++) - delete bc_iter->second; + std::map::iterator i = mappings.begin(); + while(i != mappings.end()) + { + delete i->second.first; - std::map::iterator sc_iter; - for(sc_iter = sc_map.begin(); sc_iter != sc_map.end(); sc_iter++) - delete sc_iter->second; + std::map::iterator j = + i->second.second.begin(); + while(j != i->second.second.end()) + { + delete j->second; + ++j; + } - std::map::iterator hf_iter; - for(hf_iter = hf_map.begin(); hf_iter != hf_map.end(); hf_iter++) - delete hf_iter->second; - - std::map::iterator mac_iter; - for(mac_iter = mac_map.begin(); mac_iter != mac_map.end(); mac_iter++) - delete mac_iter->second; - - delete bc_map_lock; - delete sc_map_lock; - delete hf_map_lock; - delete mac_map_lock; + ++i; + } } /************************************************* @@ -266,6 +321,22 @@ /************************************************* * Basic No-Op Engine Implementation * *************************************************/ +S2K* Engine::find_s2k(const std::string&) const + { + return 0; + } + +/************************************************* +* Basic No-Op Engine Implementation * +*************************************************/ +BlockCipherModePaddingMethod* Engine::find_bc_pad(const std::string&) const + { + return 0; + } + +/************************************************* +* Basic No-Op Engine Implementation * +*************************************************/ Keyed_Filter* Engine::get_cipher(const std::string&, Cipher_Dir) { return 0; ============================================================ --- botan/engine.cpp f9f3e140d9d596fba3bdee49d93f3348cc02c799 +++ botan/engine.cpp af6d1fb7827625d968315b490b84756861c17f7c @@ -1,65 +1,32 @@ /************************************************* * Engine Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include +#include #include -#include -#include namespace Botan { -namespace { - -std::vector engines; - -} - -namespace Init { - -/************************************************* -* Initialize the list of Engines * -*************************************************/ -void startup_engines() - { - engines.push_back(new Default_Engine); - } - -/************************************************* -* Delete the list of Engines * -*************************************************/ -void shutdown_engines() - { - for(u32bit j = 0; j != engines.size(); j++) - delete engines[j]; - engines.clear(); - } - -} - namespace Engine_Core { /************************************************* -* Add an Engine to the list * -*************************************************/ -void add_engine(Engine* engine) - { - engines.insert(engines.end() - 1, engine); - } - -/************************************************* * Acquire an IF op * *************************************************/ IF_Operation* if_op(const BigInt& e, const BigInt& n, const BigInt& d, const BigInt& p, const BigInt& q, const BigInt& d1, const BigInt& d2, const BigInt& c) { - for(u32bit j = 0; j != engines.size(); j++) + Library_State::Engine_Iterator i(global_state()); + + while(const Engine* engine = i.next()) { - IF_Operation* op = engines[j]->if_op(e, n, d, p, q, d1, d2, c); - if(op) return op; + IF_Operation* op = engine->if_op(e, n, d, p, q, d1, d2, c); + if(op) + return op; } + throw Lookup_Error("Engine_Core::if_op: Unable to find a working engine"); } @@ -68,11 +35,15 @@ *************************************************/ DSA_Operation* dsa_op(const DL_Group& group, const BigInt& y, const BigInt& x) { - for(u32bit j = 0; j != engines.size(); j++) + Library_State::Engine_Iterator i(global_state()); + + while(const Engine* engine = i.next()) { - DSA_Operation* op = engines[j]->dsa_op(group, y, x); - if(op) return op; + DSA_Operation* op = engine->dsa_op(group, y, x); + if(op) + return op; } + throw Lookup_Error("Engine_Core::dsa_op: Unable to find a working engine"); } @@ -81,11 +52,15 @@ *************************************************/ NR_Operation* nr_op(const DL_Group& group, const BigInt& y, const BigInt& x) { - for(u32bit j = 0; j != engines.size(); j++) + Library_State::Engine_Iterator i(global_state()); + + while(const Engine* engine = i.next()) { - NR_Operation* op = engines[j]->nr_op(group, y, x); - if(op) return op; + NR_Operation* op = engine->nr_op(group, y, x); + if(op) + return op; } + throw Lookup_Error("Engine_Core::nr_op: Unable to find a working engine"); } @@ -94,11 +69,15 @@ *************************************************/ ELG_Operation* elg_op(const DL_Group& group, const BigInt& y, const BigInt& x) { - for(u32bit j = 0; j != engines.size(); j++) + Library_State::Engine_Iterator i(global_state()); + + while(const Engine* engine = i.next()) { - ELG_Operation* op = engines[j]->elg_op(group, y, x); - if(op) return op; + ELG_Operation* op = engine->elg_op(group, y, x); + if(op) + return op; } + throw Lookup_Error("Engine_Core::elg_op: Unable to find a working engine"); } @@ -107,39 +86,52 @@ *************************************************/ DH_Operation* dh_op(const DL_Group& group, const BigInt& x) { - for(u32bit j = 0; j != engines.size(); j++) + Library_State::Engine_Iterator i(global_state()); + + while(const Engine* engine = i.next()) { - DH_Operation* op = engines[j]->dh_op(group, x); - if(op) return op; + DH_Operation* op = engine->dh_op(group, x); + if(op) + return op; } + throw Lookup_Error("Engine_Core::dh_op: Unable to find a working engine"); } -} - /************************************************* -* Acquire a modular reducer * +* Acquire a modular exponentiator * *************************************************/ -ModularReducer* get_reducer(const BigInt& n, bool convert_ok) +Modular_Exponentiator* mod_exp(const BigInt& n, Power_Mod::Usage_Hints hints) { - for(u32bit j = 0; j != engines.size(); j++) + Library_State::Engine_Iterator i(global_state()); + + while(const Engine* engine = i.next()) { - ModularReducer* op = engines[j]->reducer(n, convert_ok); - if(op) return op; + Modular_Exponentiator* op = engine->mod_exp(n, hints); + + if(op) + return op; } - throw Lookup_Error("get_reducer: Unable to find a working engine"); + + throw Lookup_Error("Engine_Core::mod_exp: Unable to find a working engine"); } +} + /************************************************* * Acquire a block cipher * *************************************************/ const BlockCipher* retrieve_block_cipher(const std::string& name) { - for(u32bit j = 0; j != engines.size(); j++) + Library_State::Engine_Iterator i(global_state()); + + while(const Engine* engine = i.next()) { - const BlockCipher* algo = engines[j]->block_cipher(name); - if(algo) return algo; + const BlockCipher* algo = engine->block_cipher(name); + if(algo) + return algo; } + return 0; } @@ -148,11 +140,15 @@ *************************************************/ const StreamCipher* retrieve_stream_cipher(const std::string& name) { - for(u32bit j = 0; j != engines.size(); j++) + Library_State::Engine_Iterator i(global_state()); + + while(const Engine* engine = i.next()) { - const StreamCipher* algo = engines[j]->stream_cipher(name); - if(algo) return algo; + const StreamCipher* algo = engine->stream_cipher(name); + if(algo) + return algo; } + return 0; } @@ -161,11 +157,15 @@ *************************************************/ const HashFunction* retrieve_hash(const std::string& name) { - for(u32bit j = 0; j != engines.size(); j++) + Library_State::Engine_Iterator i(global_state()); + + while(const Engine* engine = i.next()) { - const HashFunction* algo = engines[j]->hash(name); - if(algo) return algo; + const HashFunction* algo = engine->hash(name); + if(algo) + return algo; } + return 0; } @@ -174,28 +174,69 @@ *************************************************/ const MessageAuthenticationCode* retrieve_mac(const std::string& name) { - for(u32bit j = 0; j != engines.size(); j++) + Library_State::Engine_Iterator i(global_state()); + + while(const Engine* engine = i.next()) { - const MessageAuthenticationCode* algo = engines[j]->mac(name); - if(algo) return algo; + const MessageAuthenticationCode* algo = engine->mac(name); + if(algo) + return algo; } + return 0; } /************************************************* +* Acquire a string-to-key algorithm * +*************************************************/ +const S2K* retrieve_s2k(const std::string& name) + { + Library_State::Engine_Iterator i(global_state()); + + while(const Engine* engine = i.next()) + { + const S2K* algo = engine->s2k(name); + if(algo) + return algo; + } + + return 0; + } + +/************************************************* +* Retrieve a block cipher padding method * +*************************************************/ +const BlockCipherModePaddingMethod* retrieve_bc_pad(const std::string& name) + { + Library_State::Engine_Iterator i(global_state()); + + while(const Engine* engine = i.next()) + { + const BlockCipherModePaddingMethod* algo = engine->bc_pad(name); + if(algo) + return algo; + } + + return 0; + } + +/************************************************* * Add a new block cipher * *************************************************/ void add_algorithm(BlockCipher* algo) { - for(u32bit j = 0; j != engines.size(); j++) + Library_State::Engine_Iterator i(global_state()); + + while(Engine* engine_base = i.next()) { - Default_Engine* engine = dynamic_cast(engines[j]); + Default_Engine* engine = dynamic_cast(engine_base); if(engine) { engine->add_algorithm(algo); return; } } + throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); } @@ -204,15 +245,18 @@ *************************************************/ void add_algorithm(StreamCipher* algo) { - for(u32bit j = 0; j != engines.size(); j++) + Library_State::Engine_Iterator i(global_state()); + + while(Engine* engine_base = i.next()) { - Default_Engine* engine = dynamic_cast(engines[j]); + Default_Engine* engine = dynamic_cast(engine_base); if(engine) { engine->add_algorithm(algo); return; } } + throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); } @@ -221,15 +265,18 @@ *************************************************/ void add_algorithm(HashFunction* algo) { - for(u32bit j = 0; j != engines.size(); j++) + Library_State::Engine_Iterator i(global_state()); + + while(Engine* engine_base = i.next()) { - Default_Engine* engine = dynamic_cast(engines[j]); + Default_Engine* engine = dynamic_cast(engine_base); if(engine) { engine->add_algorithm(algo); return; } } + throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); } @@ -238,28 +285,55 @@ *************************************************/ void add_algorithm(MessageAuthenticationCode* algo) { - for(u32bit j = 0; j != engines.size(); j++) + Library_State::Engine_Iterator i(global_state()); + + while(Engine* engine_base = i.next()) { - Default_Engine* engine = dynamic_cast(engines[j]); + Default_Engine* engine = dynamic_cast(engine_base); if(engine) { engine->add_algorithm(algo); return; } } + throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); } /************************************************* +* Add a padding method to the lookup table * +*************************************************/ +void add_algorithm(BlockCipherModePaddingMethod* algo) + { + Library_State::Engine_Iterator i(global_state()); + + while(Engine* engine_base = i.next()) + { + Default_Engine* engine = dynamic_cast(engine_base); + if(engine) + { + engine->add_algorithm(algo); + return; + } + } + + throw Invalid_State("add_algorithm: Couldn't find the Default_Engine"); + } + +/************************************************* * Get a cipher object * *************************************************/ Keyed_Filter* get_cipher(const std::string& algo_spec, Cipher_Dir direction) { - for(u32bit j = 0; j != engines.size(); j++) + Library_State::Engine_Iterator i(global_state()); + + while(Engine* engine = i.next()) { - Keyed_Filter* algo = engines[j]->get_cipher(algo_spec, direction); - if(algo) return algo; + Keyed_Filter* algo = engine->get_cipher(algo_spec, direction); + if(algo) + return algo; } + throw Algorithm_Not_Found(algo_spec); } ============================================================ --- botan/engine.h bf1afaedad957edbc26e34b4a0490cc156e6789c +++ botan/engine.h f3677aebcf825ab278fc89ad154646b7133ae76a @@ -1,17 +1,17 @@ /************************************************* * Engine Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_ENGINE_H__ #define BOTAN_ENGINE_H__ #include +#include #include -#include -#include +#include #include -#include +#include #include namespace Botan { @@ -32,19 +32,26 @@ virtual ELG_Operation* elg_op(const DL_Group&, const BigInt&, const BigInt&) const; virtual DH_Operation* dh_op(const DL_Group&, const BigInt&) const; - virtual ModularReducer* reducer(const BigInt&, bool) const; + virtual Modular_Exponentiator* mod_exp(const BigInt&, + Power_Mod::Usage_Hints) const; + + virtual Keyed_Filter* get_cipher(const std::string&, Cipher_Dir); + const BlockCipher* block_cipher(const std::string&) const; const StreamCipher* stream_cipher(const std::string&) const; const HashFunction* hash(const std::string&) const; const MessageAuthenticationCode* mac(const std::string&) const; + const class S2K* s2k(const std::string&) const; + const class BlockCipherModePaddingMethod* + bc_pad(const std::string&) const; - virtual Keyed_Filter* get_cipher(const std::string&, Cipher_Dir); - void add_algorithm(BlockCipher*) const; void add_algorithm(StreamCipher*) const; void add_algorithm(HashFunction*) const; void add_algorithm(MessageAuthenticationCode*) const; + void add_algorithm(class S2K*) const; + void add_algorithm(class BlockCipherModePaddingMethod*) const; Engine(); virtual ~Engine(); @@ -53,28 +60,25 @@ virtual StreamCipher* find_stream_cipher(const std::string&) const; virtual HashFunction* find_hash(const std::string&) const; virtual MessageAuthenticationCode* find_mac(const std::string&) const; + virtual class S2K* find_s2k(const std::string&) const; + virtual class BlockCipherModePaddingMethod* + find_bc_pad(const std::string&) const; - mutable std::map bc_map; - mutable std::map sc_map; - mutable std::map hf_map; - mutable std::map mac_map; + Algorithm* get_algo(const std::string&, const std::string&) const; + void add_algo(const std::string&, Algorithm*) const; - Mutex* bc_map_lock; - Mutex* sc_map_lock; - Mutex* hf_map_lock; - Mutex* mac_map_lock; + typedef std::pair > + mutex_map_pair; + mutable std::map mappings; }; namespace Engine_Core { /************************************************* -* Engine Management * +* Get an operation from an Engine * *************************************************/ -void add_engine(Engine*); +Modular_Exponentiator* mod_exp(const BigInt&, Power_Mod::Usage_Hints); -/************************************************* -* Get an operation from an Engine * -*************************************************/ IF_Operation* if_op(const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&, const BigInt&); ============================================================ --- botan/enums.h d11810103ab6a83b78ec6248a12f8e40db56121d +++ botan/enums.h c04f2e670414dd7dfe11091e7f63e82bf4242fd4 @@ -1,6 +1,6 @@ /************************************************* * Enumerations Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_ENUMS_H__ @@ -112,8 +112,6 @@ /************************************************* * Various Other Enumerations * *************************************************/ -enum RNG_Quality { Nonce = 0, PublicValue = 0, SessionKey, LongTermKey }; - enum Decoder_Checking { NONE, IGNORE_WS, FULL_CHECK }; enum X509_Encoding { RAW_BER, PEM }; ============================================================ --- botan/es_capi.cpp 2d8b12afebb00cf798cb8d4c42defad1dcd8b181 +++ botan/es_capi.cpp 4ac7b3e52f1d7a16aed591cde28ae620df18e5c2 @@ -1,11 +1,11 @@ /************************************************* -* Win32 CAPI EntropySource Source File * -* (C) 1999-2005 The Botan Project * +* Win32 CryptoAPI EntropySource Source File * +* (C) 1999-2006 The Botan Project * *************************************************/ #include +#include #include -#include #include #include @@ -22,6 +22,7 @@ CSP_Handle(u64bit); ~CSP_Handle(); + void gen_random(byte[], u32bit) const; bool is_valid() const { return valid; } HCRYPTPROV get_handle() const { return handle; } @@ -31,6 +32,14 @@ }; /************************************************* +* Call CryptGenRandom * +*************************************************/ +void CSP_Handle::gen_random(byte out[], u32bit n) const + { + CryptGenRandom(handle, n, out); + } + +/************************************************* * Initialize a CSP Handle * *************************************************/ CSP_Handle::CSP_Handle(u64bit capi_provider) @@ -64,8 +73,11 @@ for(u32bit j = 0; j != prov_types.size(); j++) { CSP_Handle csp(prov_types[j]); - if(!csp.is_valid()) continue; - if(CryptGenRandom(csp.get_handle(), length, output)) break; + if(!csp.is_valid()) + continue; + + csp.gen_random(output, length); + break; } return length; } ============================================================ --- botan/es_capi.h addcb8c601219d5a95e9d8b5e8b93026269b6075 +++ botan/es_capi.h 72dab1a57f7e67a2eb34eeb6a43a35441a2a9b47 @@ -1,6 +1,6 @@ /************************************************* * Win32 CAPI EntropySource Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_EXT_ENTROPY_SRC_WIN32_CAPI_H__ ============================================================ --- botan/es_egd.cpp 16c13a4ab4865ebcb771d9ddd251e4a2838fb64c +++ botan/es_egd.cpp b5a2e16b8872dcd26f83064797a8398a8fe0a307 @@ -1,6 +1,6 @@ /************************************************* * EGD EntropySource Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/es_egd.h e5d389bab5e622f5438183f92778c314347f6565 +++ botan/es_egd.h b81212d62810f7b8758c76192e746ff403d4a9a1 @@ -1,6 +1,6 @@ /************************************************* * EGD EntropySource Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_EXT_ENTROPY_SRC_EGD_H__ ============================================================ --- botan/es_file.cpp 0ccbd0d7f16404e39f3a7a3c664a867801cf39ce +++ botan/es_file.cpp 8485aab5b2589450af2d7915919db7b03b2a7fa8 @@ -1,6 +1,6 @@ /************************************************* * File EntropySource Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -18,9 +18,9 @@ std::vector source_list = split_on(sources, ':'); std::vector defaults = Config::get_list("rng/es_files"); - for(u32bit j = 0; j != source_list.size(); j++) + for(u32bit j = 0; j != source_list.size(); ++j) add_source(source_list[j]); - for(u32bit j = 0; j != defaults.size(); j++) + for(u32bit j = 0; j != defaults.size(); ++j) add_source(defaults[j]); } @@ -38,7 +38,7 @@ u32bit File_EntropySource::slow_poll(byte output[], u32bit length) { u32bit read = 0; - for(u32bit j = 0; j != sources.size(); j++) + for(u32bit j = 0; j != sources.size(); ++j) { std::ifstream random_source(sources[j].c_str(), std::ios::binary); if(!random_source) continue; ============================================================ --- botan/es_file.h a375d7011922508810394364ac39a357a5a75b83 +++ botan/es_file.h fa7288fe9d295666330e1b7f8207ecf32a3c072b @@ -1,6 +1,6 @@ /************************************************* * File EntropySource Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_ENTROPY_SRC_FILE_H__ ============================================================ --- botan/es_win32.cpp e9b9c76342a863825e2a60c12de29627e4f7057d +++ botan/es_win32.cpp 701187eda7ca149bb8c42e72f3bb523954b2d54e @@ -1,6 +1,6 @@ /************************************************* * Win32 EntropySource Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -10,40 +10,11 @@ namespace Botan { /************************************************* -* Win32 Fast Poll * -*************************************************/ -void Win32_EntropySource::do_fast_poll() - { - add_bytes(GetTickCount()); - add_bytes(GetMessagePos()); - add_bytes(GetMessageTime()); - add_bytes(GetInputState()); - add_bytes(GetCurrentProcessId()); - add_bytes(GetCurrentThreadId()); - - SYSTEM_INFO sys_info; - GetSystemInfo(&sys_info); - add_bytes(&sys_info, sizeof(sys_info)); - - MEMORYSTATUS mem_info; - GlobalMemoryStatus(&mem_info); - add_bytes(&mem_info, sizeof(mem_info)); - - POINT point; - GetCursorPos(&point); - add_bytes(&point, sizeof(point)); - GetCaretPos(&point); - add_bytes(&point, sizeof(point)); - } - -/************************************************* * Win32 Slow Poll * *************************************************/ void Win32_EntropySource::do_slow_poll() { const u32bit MAX_ITEMS = 256; - const u32bit HEAP_LISTS_MAX = 32; - const u32bit HEAP_OBJS_PER_LIST = 128; do_fast_poll(); @@ -73,6 +44,9 @@ u32bit heap_lists_found = 0; HEAPLIST32 heap_list; heap_list.dwSize = sizeof(HEAPLIST32); + + const u32bit HEAP_LISTS_MAX = 32; + const u32bit HEAP_OBJS_PER_LIST = 128; if(Heap32ListFirst(snapshot, &heap_list)) { do @@ -101,4 +75,31 @@ CloseHandle(snapshot); } +/************************************************* +* Win32 Fast Poll * +*************************************************/ +void Win32_EntropySource::do_fast_poll() + { + add_bytes(GetTickCount()); + add_bytes(GetMessagePos()); + add_bytes(GetMessageTime()); + add_bytes(GetInputState()); + add_bytes(GetCurrentProcessId()); + add_bytes(GetCurrentThreadId()); + + SYSTEM_INFO sys_info; + GetSystemInfo(&sys_info); + add_bytes(&sys_info, sizeof(sys_info)); + + MEMORYSTATUS mem_info; + GlobalMemoryStatus(&mem_info); + add_bytes(&mem_info, sizeof(mem_info)); + + POINT point; + GetCursorPos(&point); + add_bytes(&point, sizeof(point)); + GetCaretPos(&point); + add_bytes(&point, sizeof(point)); + } + } ============================================================ --- botan/es_win32.h 1c730fe9b6a9a522c7b61e45c055b1f60cf2a8f9 +++ botan/es_win32.h 0251e175291cd4029ae60cbcf588a04dfe62c76c @@ -1,6 +1,6 @@ /************************************************* * Win32 EntropySource Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_EXT_ENTROPY_SRC_WIN32_H__ ============================================================ --- botan/exceptn.cpp f16b034aa7a23055e0b00613752e762e3c5edcb7 +++ botan/exceptn.cpp d83be5a04572fbed2adad3785431999aad9b7017 @@ -1,6 +1,6 @@ /************************************************* * Exceptions Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/exceptn.h 0f90c643393d85de7e81ae26d6a57e0f52fad8b4 +++ botan/exceptn.h 2f717eeccaa793dd63844070e3c5a072fa55bae6 @@ -1,6 +1,6 @@ /************************************************* * Exceptions Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_EXCEPTION_H__ @@ -198,6 +198,15 @@ Internal_Error("Self test failed: " + err) {} }; +/************************************************* +* Memory Allocation Exception * +*************************************************/ +struct Memory_Exhaustion : public Exception + { + Memory_Exhaustion() : + Exception("Ran out of memory, allocation failed") {} + }; + } #endif ============================================================ --- botan/filter.cpp 5df2e58f9ed1de853a151ba0ab43fa0faa50a0d1 +++ botan/filter.cpp c38f149e29ece60b4d79fd2b4aa1746bc98ce37a @@ -1,6 +1,6 @@ /************************************************* * Filter Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -17,6 +17,7 @@ next.resize(1); port_num = 0; filter_owns = 0; + owned = false; } /************************************************* @@ -27,7 +28,7 @@ UI::pulse(UI::PIPE_WRITE); bool nothing_attached = true; - for(u32bit j = 0; j != total_ports(); j++) + for(u32bit j = 0; j != total_ports(); ++j) if(next[j]) { if(write_queue.has_items()) @@ -47,7 +48,7 @@ void Filter::new_msg() { start_msg(); - for(u32bit j = 0; j != total_ports(); j++) + for(u32bit j = 0; j != total_ports(); ++j) if(next[j]) next[j]->new_msg(); } @@ -58,7 +59,7 @@ void Filter::finish_msg() { end_msg(); - for(u32bit j = 0; j != total_ports(); j++) + for(u32bit j = 0; j != total_ports(); ++j) if(next[j]) next[j]->finish_msg(); } @@ -111,7 +112,7 @@ port_num = 0; filter_owns = 0; - for(u32bit j = 0; j != size; j++) + for(u32bit j = 0; j != size; ++j) next[j] = filters[j]; } ============================================================ --- botan/filter.h aaa4e5977156b60de4d6cff9aee6d6ff0352d939 +++ botan/filter.h 7b951b0e26db1861c7a779fdc8e5cf83dc743cbb @@ -1,6 +1,6 @@ /************************************************* * Filter Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_FILTER_H__ @@ -49,6 +49,7 @@ SecureVector write_queue; std::vector next; u32bit port_num, filter_owns; + bool owned; }; /************************************************* ============================================================ --- botan/filters.cpp d8f8d8e488482d394b59ffbe7d666ab190698914 +++ botan/filters.cpp dce61805189ff431083613a331ab42b26aca64ec @@ -1,6 +1,6 @@ /************************************************* * Filters Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/filters.h dba4116f6d25355809ef86ea71b64a4d031029af +++ botan/filters.h 32de15889ec656110b6a1b5a27f22fc86dc65622 @@ -1,6 +1,6 @@ /************************************************* * Filters Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_FILTERS_H__ ============================================================ --- botan/fips140.cpp 19b5950901dd4973dc066cab00220fda9bd34d1f +++ botan/fips140.cpp e42e938b93faaa82ff8d6861ce80d2bf6ab78048 @@ -1,6 +1,6 @@ /************************************************* * FIPS-140 Self Tests Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -147,7 +147,7 @@ "301C393738363533343132343837363932331C", "C209CCB78EE1B606", "0123456789ABCDEFFEDCBA9876543210"); } - catch(std::exception) + catch(std::exception& e) { return false; } ============================================================ --- botan/fips140.h b975066cc64ce52da09af0ba5ed907e786e426b8 +++ botan/fips140.h a48903c8bea50db118624d398d335d506967608b @@ -1,6 +1,6 @@ /************************************************* * FIPS 140 Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_FIPS140_H__ ============================================================ --- botan/get_algo.cpp 83b4c671f852dbf233ce7da7c81c1f8e63e92e46 +++ botan/get_algo.cpp 89ca5531b77ddcbf202cb930d4fd3f863ee38504 @@ -1,6 +1,6 @@ /************************************************* * Algorithm Retrieval Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/get_enc.cpp 3691eb8c87161a3ec8897faaf12e6a081aaca466 +++ botan/get_enc.cpp 8840ce2708a4b2989efef886d8a2c9f63c21993b @@ -1,6 +1,6 @@ /************************************************* * EMSA/EME/KDF/MGF Retrieval Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/get_pbe.cpp ce4d99a19ec0e893483d458e57c8ff86a32c167d +++ botan/get_pbe.cpp 4d13f684cca1485575401f3bf3c0563dac19a318 @@ -1,6 +1,6 @@ /************************************************* * PBE Retrieval Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/hash_id.cpp 30976df969f81420191833f90bfe0f20941a6c8f +++ botan/hash_id.cpp ff0dd27712838713d976bd0f5e13875c9f73ea1c @@ -1,6 +1,6 @@ /************************************************* * Hash Function Identification Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/hash_id.h 518f07b3e6f9ec8ebce5e01bcaa41d005fc509de +++ botan/hash_id.h e807331d09c89bd23cdbeceda4ede53f1f2f18f1 @@ -1,6 +1,6 @@ /************************************************* * Hash Function Identification Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_HASHID_H__ ============================================================ --- botan/hex.cpp cb1b85c614144b7cd3ab2308a1c5221ca43a98bd +++ botan/hex.cpp 875cfbfe15cc074195bab031f907de885496f311 @@ -1,6 +1,6 @@ /************************************************* * Hex Encoder/Decoder Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -47,7 +47,7 @@ *************************************************/ void Hex_Encoder::encode_and_send(const byte block[], u32bit length) { - for(u32bit j = 0; j != length; j++) + for(u32bit j = 0; j != length; ++j) encode(block[j], out + 2*j, casing); if(line_length == 0) @@ -146,7 +146,7 @@ *************************************************/ void Hex_Decoder::decode_and_send(const byte block[], u32bit length) { - for(u32bit j = 0; j != length / 2; j++) + for(u32bit j = 0; j != length / 2; ++j) out[j] = decode(block + 2*j); send(out, length / 2); } @@ -156,7 +156,7 @@ *************************************************/ void Hex_Decoder::write(const byte input[], u32bit length) { - for(u32bit j = 0; j != length; j++) + for(u32bit j = 0; j != length; ++j) { if(is_valid(input[j])) in[position++] = input[j]; ============================================================ --- botan/hex.h 2bba7745b808634f2ff705e21ad9a6d20f6be763 +++ botan/hex.h 065a18cbf522daf1c6283587bec607f788be2e46 @@ -1,6 +1,6 @@ /************************************************* * Hex Encoder/Decoder Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_HEX_H__ ============================================================ --- botan/hmac.cpp f382822b6dfacb4472e9b4568289023ffab33f89 +++ botan/hmac.cpp 219e669226db3c9f450e8d434bbfefc11876070e @@ -1,6 +1,6 @@ /************************************************* * HMAC Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -77,7 +77,7 @@ * HMAC Constructor * *************************************************/ HMAC::HMAC(const std::string& hash_name) : - MessageAuthenticationCode(output_length_of(hash_name), 1, 64), + MessageAuthenticationCode(output_length_of(hash_name), 1, 128), hash(get_hash(hash_name)) { if(hash->HASH_BLOCK_SIZE == 0) ============================================================ --- botan/hmac.h d608aecb93bd9d0d3a9fa47443696c766e0c7a14 +++ botan/hmac.h 953953c1a07de51d1333f2370b515799642a26b4 @@ -1,6 +1,6 @@ /************************************************* * HMAC Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_HMAC_H__ ============================================================ --- botan/if_algo.cpp 4ee708729d33713d47c64828d1d43c646690b4b2 +++ botan/if_algo.cpp b7a2ae76d1318d2e3b0e61d8c9ba50a2b5e23c0f @@ -1,6 +1,6 @@ /************************************************* * IF Scheme Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/if_algo.h d8597f0265745faa4743802b44de16660e326e5e +++ botan/if_algo.h 825399a5fbc274c40ae764c0ba85fc89654c2091 @@ -1,6 +1,6 @@ /************************************************* * IF Scheme Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_IF_ALGO_H__ ============================================================ --- botan/inifile.cpp 98bff4e028a824b8233181bd06a12b5ecb652e7b +++ botan/inifile.cpp 7df6bc16b85ae545ef9ea941a185f7993d5b0321 @@ -1,12 +1,10 @@ /************************************************* * Configuration Reader Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include -#include -#include -#include +#include #include #include #include @@ -24,7 +22,7 @@ bool is_escaped = false, in_quote = false, in_string = false; std::string new_line; - for(std::string::const_iterator j = line.begin(); j != line.end(); j++) + for(std::string::const_iterator j = line.begin(); j != line.end(); ++j) { const char c = *j; @@ -81,6 +79,14 @@ *************************************************/ void load(const std::string& fsname) { + load(fsname, global_state()); + } + +/************************************************* +* Load a configuration file * +*************************************************/ +void load(const std::string& fsname, Library_State& state) + { std::ifstream config(fsname.c_str()); if(!config) @@ -128,11 +134,14 @@ variables[name] = value; if(section == "oids") - OIDS::add_oid(OID(value), name); + { + state.set_option("oid2str", name, value, false); + state.set_option("str2oid", value, name, false); + } else if(section == "aliases") - add_alias(name, value); + state.set_option("alias", name, value); else - set(section + '/' + name, value); + state.set_option("conf", section + '/' + name, value); } } ============================================================ --- botan/init.cpp fcd3ebd72fbe0bbd544a43cdabe5dfada6d3905d +++ botan/init.cpp 9ea095587401c32f31aadec310130f6865711409 @@ -1,86 +1,32 @@ /************************************************* * Initialization Function Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include - -#include -#include +#include +#include #include -#include -#include -#include - -#include +#include +#include +#include #include -#include -#include +#include -#if defined(BOTAN_EXT_MUTEX_PTHREAD) - #include -#elif defined(BOTAN_EXT_MUTEX_WIN32) - #include -#elif defined(BOTAN_EXT_MUTEX_QT) - #include -#endif +namespace Botan { -#if defined(BOTAN_EXT_ALLOC_MMAP) - #include -#endif +/************************************************* +* Botan's global state * +*************************************************/ +Library_State* global_lib_state = 0; -#if defined(BOTAN_EXT_TIMER_HARDWARE) - #include -#elif defined(BOTAN_EXT_TIMER_POSIX) - #include -#elif defined(BOTAN_EXT_TIMER_UNIX) - #include -#elif defined(BOTAN_EXT_TIMER_WIN32) - #include -#endif +Library_State& global_state() + { + if(!global_lib_state) + throw Invalid_State("Library was not intialized correctly"); + return (*global_lib_state); + } -#if defined(BOTAN_EXT_ENGINE_AEP) - #include -#endif - -#if defined(BOTAN_EXT_ENGINE_GNU_MP) - #include -#endif - -#if defined(BOTAN_EXT_ENGINE_OPENSSL) - #include -#endif - -#if defined(BOTAN_EXT_ENTROPY_SRC_AEP) - #include -#endif - -#if defined(BOTAN_EXT_ENTROPY_SRC_EGD) - #include -#endif - -#if defined(BOTAN_EXT_ENTROPY_SRC_UNIX) - #include -#endif - -#if defined(BOTAN_EXT_ENTROPY_SRC_BEOS) - #include -#endif - -#if defined(BOTAN_EXT_ENTROPY_SRC_CAPI) - #include -#endif - -#if defined(BOTAN_EXT_ENTROPY_SRC_WIN32) - #include -#endif - -#if defined(BOTAN_EXT_ENTROPY_SRC_FTW) - #include -#endif - -namespace Botan { - /************************************************* * Library Initialization * *************************************************/ @@ -102,110 +48,13 @@ namespace { /************************************************* -* Register a mutex type, if possible * -*************************************************/ -void set_mutex() - { -#if defined(BOTAN_EXT_MUTEX_PTHREAD) - set_mutex_type(new Pthread_Mutex); -#elif defined(BOTAN_EXT_MUTEX_WIN32) - set_mutex_type(new Win32_Mutex); -#elif defined(BOTAN_EXT_MUTEX_QT) - set_mutex_type(new Qt_Mutex); -#else - throw Exception("LibraryInitializer: thread safety impossible"); -#endif - } - -/************************************************* -* Register a high resolution timer, if possible * -*************************************************/ -void set_timer() - { -#if defined(BOTAN_EXT_TIMER_HARDWARE) - set_timer_type(new Hardware_Timer); -#elif defined(BOTAN_EXT_TIMER_POSIX) - set_timer_type(new POSIX_Timer); -#elif defined(BOTAN_EXT_TIMER_UNIX) - set_timer_type(new Unix_Timer); -#elif defined(BOTAN_EXT_TIMER_WIN32) - set_timer_type(new Win32_Timer); -#endif - } - -/************************************************* -* Register any usable entropy sources * -*************************************************/ -void add_entropy_sources() - { - Global_RNG::add_es(new File_EntropySource); - -#if defined(BOTAN_EXT_ENTROPY_SRC_AEP) - Global_RNG::add_es(new AEP_EntropySource); -#endif - -#if defined(BOTAN_EXT_ENTROPY_SRC_EGD) - Global_RNG::add_es(new EGD_EntropySource); -#endif - -#if defined(BOTAN_EXT_ENTROPY_SRC_CAPI) - Global_RNG::add_es(new Win32_CAPI_EntropySource); -#endif - -#if defined(BOTAN_EXT_ENTROPY_SRC_WIN32) - Global_RNG::add_es(new Win32_EntropySource); -#endif - -#if defined(BOTAN_EXT_ENTROPY_SRC_UNIX) - Global_RNG::add_es(new Unix_EntropySource); -#endif - -#if defined(BOTAN_EXT_ENTROPY_SRC_BEOS) - Global_RNG::add_es(new BeOS_EntropySource); -#endif - -#if defined(BOTAN_EXT_ENTROPY_SRC_FTW) - Global_RNG::add_es(new FTW_EntropySource); -#endif - } - -/************************************************* -* Register a more secure allocator, if possible * -*************************************************/ -void set_safe_allocator() - { -#if defined(BOTAN_EXT_ALLOC_MMAP) - add_allocator_type("mmap", new MemoryMapping_Allocator); - set_default_allocator("mmap"); -#endif - } - -/************************************************* -* Register any usable engines * -*************************************************/ -void set_engines() - { -#if defined(BOTAN_EXT_ENGINE_AEP) - Botan::Engine_Core::add_engine(new Botan::AEP_Engine); -#endif - -#if defined(BOTAN_EXT_ENGINE_GNU_MP) - Botan::Engine_Core::add_engine(new Botan::GMP_Engine); -#endif - -#if defined(BOTAN_EXT_ENGINE_OPENSSL) - Botan::Engine_Core::add_engine(new Botan::OpenSSL_Engine); -#endif - } - -/************************************************* * Parse the options string * *************************************************/ std::map parse_args(const std::string& arg_string) { std::map arg_map; std::vector args = split_on(arg_string, ' '); - for(u32bit j = 0; j != args.size(); j++) + for(u32bit j = 0; j != args.size(); ++j) { if(args[j].find('=') == std::string::npos) arg_map[args[j]] = ""; @@ -237,47 +86,54 @@ { std::map args = parse_args(arg_string); + Mutex_Factory* mutex_factory = 0; if(arg_set(args, "thread_safe")) - set_mutex(); + { + mutex_factory = Modules::get_mutex_factory(); + if(!mutex_factory) + throw Exception("LibraryInitializer: thread safety impossible"); + } - startup_conf(); - startup_oids(); - set_default_options(); - startup_memory_subsystem(); + Library_State* state = new Library_State(mutex_factory, + Modules::get_timer()); - init_lookup_tables(); + global_lib_state = state; + state->add_allocator("malloc", new Malloc_Allocator); + state->add_allocator("locking", new Locking_Allocator); + if(arg_set(args, "secure_memory")) - set_safe_allocator(); - set_timer(); + { + std::map allocators = Modules::get_allocators(); + for(std::map::iterator i = allocators.begin(); + i != allocators.end(); ++i) + state->add_allocator(i->first, i->second); + } - if(!arg_set(args, "no_aliases")) add_default_aliases(); - if(!arg_set(args, "no_oids")) add_default_oids(); if(arg_set(args, "config") && args["config"] != "") - Config::load(args["config"]); + Config::load(args["config"], *state); - startup_engines(); if(arg_set(args, "use_engines")) - set_engines(); - init_rng_subsystem(); - - set_global_rngs(new ANSI_X931_RNG, new ANSI_X931_RNG); - add_entropy_sources(); - - if(!FIPS140::passes_self_tests()) { - deinitialize(); - throw Self_Test_Failure("FIPS-140 startup tests"); + std::vector engines = Modules::get_engines(); + for(u32bit j = 0; j != engines.size(); ++j) + state->add_engine(engines[j]); } + state->add_engine(new Default_Engine); + state->set_prng(new ANSI_X931_RNG); + std::vector sources = Modules::get_entropy_sources(); + for(u32bit j = 0; j != sources.size(); ++j) + state->add_entropy_source(sources[j], true); + const u32bit min_entropy = Config::get_u32bit("rng/min_entropy"); if(min_entropy != 0 && !arg_set(args, "no_rng_seed")) { u32bit total_bits = 0; - for(u32bit j = 0; j != 4; j++) + for(u32bit j = 0; j != 4; ++j) { - total_bits += Global_RNG::seed(true, min_entropy - total_bits); + total_bits += state->seed_prng(true, min_entropy - total_bits); if(total_bits >= min_entropy) break; } @@ -286,7 +142,12 @@ throw PRNG_Unseeded("Unable to collect sufficient entropy"); } - startup_dl_cache(); + if(!FIPS140::passes_self_tests()) + { + delete global_lib_state; + global_lib_state = 0; + throw Self_Test_Failure("FIPS-140 startup tests"); + } } /************************************************* @@ -294,15 +155,8 @@ *************************************************/ void deinitialize() { - shutdown_engines(); - shutdown_rng_subsystem(); - destroy_lookup_tables(); - shutdown_dl_cache(); - shutdown_conf(); - shutdown_oids(); - set_timer_type(0); - set_mutex_type(0); - shutdown_memory_subsystem(); + delete global_lib_state; + global_lib_state = 0; } } ============================================================ --- botan/init.h 78786baa62040f7edeed7524e9529dfdce70401e +++ botan/init.h 825be479b4ab221415be4b0fcd663df176337c5e @@ -1,6 +1,6 @@ /************************************************* * Library Initialization Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_INIT_H__ @@ -20,28 +20,6 @@ void initialize(const std::string& = ""); void deinitialize(); -/************************************************* -* Internal Initialization/Shutdown Functions * -*************************************************/ -void set_mutex_type(Mutex*); -void set_timer_type(Timer*); - -void startup_memory_subsystem(); -void shutdown_memory_subsystem(); - -void startup_engines(); -void shutdown_engines(); - -void startup_dl_cache(); -void shutdown_dl_cache(); - -void startup_oids(); -void shutdown_oids(); - -void startup_conf(); -void shutdown_conf(); -void set_default_options(); - } /************************************************* ============================================================ --- botan/kdf.cpp da6521d210af842b78eaf9a32e6f51a80009b079 +++ botan/kdf.cpp 65f28a1f1a94a55e816feb29eb219910dc92644e @@ -1,6 +1,6 @@ /************************************************* * KDF1/KDF2 Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -47,7 +47,7 @@ while(out_len) { hash->update(secret, secret_len); - for(u32bit j = 0; j != 4; j++) + for(u32bit j = 0; j != 4; ++j) hash->update(get_byte(j, counter)); hash->update(P, P_len); SecureVector hash_result = hash->final(); ============================================================ --- botan/kdf.h 7d0cda0fb2a44516987c1e1508df26cf1016e355 +++ botan/kdf.h 1124198e5c3117544d112eede2a0d4bfa772341c @@ -1,6 +1,6 @@ /************************************************* * KDF Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_KDF_H__ ============================================================ --- botan/keypair.cpp 95b67905dbc153558bdd0d8addee5eb6b1568356 +++ botan/keypair.cpp 91cccf8c1a165d8e0d4da18b36d38b1b0e06210d @@ -1,6 +1,6 @@ /************************************************* * Keypair Checks Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -21,7 +21,7 @@ std::auto_ptr dec(decryptor); SecureVector message(enc->maximum_input_size() - 1); - Global_RNG::randomize(message, message.size(), Nonce); + Global_RNG::randomize(message, message.size()); SecureVector ciphertext = enc->encrypt(message); if(ciphertext == message) @@ -41,7 +41,7 @@ std::auto_ptr ver(verifier); SecureVector message(16); - Global_RNG::randomize(message, message.size(), Nonce); + Global_RNG::randomize(message, message.size()); SecureVector signature = sig->sign_message(message); ============================================================ --- botan/keypair.h 50f23526d06bebe6b49881342da49dc2fb0a19f3 +++ botan/keypair.h a0310efb60669a0abd04b9065c8b7e50e4e10e7c @@ -1,6 +1,6 @@ /************************************************* * Keypair Checks Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_KEYPAIR_H__ ============================================================ --- botan/license.txt 8c0441f989ad0c3c9cb5a463dd4382154187e04e +++ botan/license.txt 0cac4d68711b77376ac6b70d8ca304da89cc613c @@ -1,4 +1,4 @@ -Copyright (C) 1999-2005 The Botan Project. All rights reserved. +Copyright (C) 1999-2006 The Botan Project. All rights reserved. Redistribution and use in source and binary forms, for any use, with or without modification, is permitted provided that the following conditions are met: ============================================================ --- botan/look_add.h 18561a6954c6011dd60b458c5affe02e73a6a0c0 +++ botan/look_add.h 4f1e00b7a693a682a64f80a61d2a56aa63d6f37a @@ -1,6 +1,6 @@ /************************************************* * Lookup Table Management Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_LOOKUP_MANGEMENT_H__ @@ -27,14 +27,6 @@ *************************************************/ void add_alias(const std::string&, const std::string&); -/************************************************* -* Lookup table startup/shutdown * -*************************************************/ -void init_lookup_tables(); -void destroy_lookup_tables(); -void add_default_oids(); -void add_default_aliases(); - } #endif ============================================================ --- botan/look_pk.cpp 870251a124f84ba2c175753b2946377abbd2c4c9 +++ botan/look_pk.cpp 13453c6cbd7be65bf71e38b40f14a8e8c3851c85 @@ -1,6 +1,6 @@ /************************************************* * PK Algorithm Lookup Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/look_pk.h b868af6a79123e844310d943647cd21b63fe5d34 +++ botan/look_pk.h a579cb37238f0eddb5e33277379c676e724f235a @@ -1,6 +1,6 @@ /************************************************* * PK Algorithm Lookup Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_PK_LOOKUP_H__ ============================================================ --- botan/lookup.h aa7bce79307989caf3699175148af3d3d3ab6481 +++ botan/lookup.h 7265880bb34e5c13431307e2e57a57813540a5fa @@ -1,6 +1,6 @@ /************************************************* * Algorithm Lookup Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_LOOKUP_H__ ============================================================ --- botan/make_prm.cpp e7b6ad43b9f2620d6993fc1c991918b541b5dc14 +++ botan/make_prm.cpp 7c867a6d50b8d9d804900d2c634304693d8d5ce1 @@ -1,6 +1,6 @@ /************************************************* * Prime Generation Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -60,15 +60,15 @@ SecureVector W(20 * (n+1)); BigInt X; - for(u32bit j = 0; j != counter_start; j++) - for(u32bit k = 0; k != n + 1; k++) + for(u32bit j = 0; j != counter_start; ++j) + for(u32bit k = 0; k != n + 1; ++k) increment(seed); - for(u32bit j = 0; j != 4096 - counter_start; j++) + for(u32bit j = 0; j != 4096 - counter_start; ++j) { UI::pulse(UI::PRIME_SEARCHING); - for(u32bit k = 0; k != n + 1; k++) + for(u32bit k = 0; k != n + 1; ++k) { increment(seed); sha1->update(seed); @@ -97,7 +97,7 @@ while(true) { - Global_RNG::randomize(seed, seed.size(), Nonce); + Global_RNG::randomize(seed, seed.size()); UI::pulse(UI::PRIME_SEARCHING); if(generate_dsa_primes(p, q, seed, seed.size(), pbits)) return seed; @@ -107,7 +107,7 @@ /************************************************* * Generate a random prime * *************************************************/ -BigInt random_prime(u32bit bits, RNG_Quality level, const BigInt& coprime, +BigInt random_prime(u32bit bits, const BigInt& coprime, u32bit equiv, u32bit modulo) { if(bits <= 48) @@ -125,7 +125,7 @@ { UI::pulse(UI::PRIME_SEARCHING); - BigInt p = random_integer(bits, level); + BigInt p = random_integer(bits); p.set_bit(bits - 2); p.set_bit(0); @@ -135,7 +135,7 @@ const u32bit sieve_size = std::min(bits / 2, PRIME_TABLE_SIZE); SecureVector sieve(sieve_size); - for(u32bit j = 0; j != sieve.size(); j++) + for(u32bit j = 0; j != sieve.size(); ++j) { sieve[j] = p % PRIMES[j]; UI::pulse(UI::PRIME_SIEVING); @@ -153,7 +153,7 @@ counter++; p += modulo; - for(u32bit j = 0; j != sieve.size(); j++) + for(u32bit j = 0; j != sieve.size(); ++j) { sieve[j] = (sieve[j] + modulo) % PRIMES[j]; UI::pulse(UI::PRIME_SIEVING); ============================================================ --- botan/mdx_hash.cpp 7549dd02bb181e14f09af48923bd39f47ea7d235 +++ botan/mdx_hash.cpp e1df6c859d3220d0d6dc4347f366e13b08e2ef9f @@ -1,6 +1,6 @@ /************************************************* * MDx Hash Function Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -61,7 +61,7 @@ void MDx_HashFunction::final_result(byte output[]) { buffer[position] = (BIG_BIT_ENDIAN ? 0x80 : 0x01); - for(u32bit j = position+1; j != HASH_BLOCK_SIZE; j++) + for(u32bit j = position+1; j != HASH_BLOCK_SIZE; ++j) buffer[j] = 0; if(position >= HASH_BLOCK_SIZE - COUNT_SIZE) { @@ -82,7 +82,7 @@ { if(COUNT_SIZE < 8) throw Invalid_State("MDx_HashFunction::write_count: COUNT_SIZE < 8"); - for(u32bit j = 0; j != 8; j++) + for(u32bit j = 0; j != 8; ++j) { const u32bit choose = (BIG_BYTE_ENDIAN ? (j % 8) : (7 - (j % 8))); out[j+COUNT_SIZE-8] = get_byte(choose, 8 * count); ============================================================ --- botan/mdx_hash.h a38578d1f39ffd7ffea279a92e3a6d9e42f3f74c +++ botan/mdx_hash.h 5bdd8beb52cdaf9e8ac1106a542604bb7c309c64 @@ -1,6 +1,6 @@ /************************************************* * MDx Hash Function Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_MDX_BASE_H__ ============================================================ --- botan/mem_ops.h 02ab0ae42b9c6bf677886935d8dfb85e447ab6ba +++ botan/mem_ops.h 92bb05e9488560a8270d4a78b8fbb1ab78fc2eba @@ -1,6 +1,6 @@ /************************************************* * Memory Operations Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_MEMORY_OPS_H__ ============================================================ --- botan/mem_pool.cpp cc2313bdb2ed78668efea720ddd78929c8afb461 +++ botan/mem_pool.cpp 4071bb398b36e883145b5d9d956ca14dd299f093 @@ -1,371 +1,298 @@ /************************************************* * Pooling Allocator Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include +#include #include +#include #include -#include namespace Botan { +namespace { + /************************************************* -* Pooling_Allocator Constructor * +* Decide how much memory to allocate at once * *************************************************/ -Pooling_Allocator::Pooling_Allocator(u32bit size) : - PREF_SIZE(size ? size : Config::get_u32bit("base/memory_chunk")), - ALIGN_TO(16) +u32bit choose_pref_size(u32bit provided) { - if(PREF_SIZE == 0) - throw Internal_Error("The base/memory_chunk option is unset"); - lock = get_mutex(); - initialized = destroyed = false; - defrag_counter = 0; + if(provided) + return provided; + + u32bit result = Config::get_u32bit("base/memory_chunk"); + if(result) + return result; + + return 16*1024; } /************************************************* -* Pooling_Allocator Destructor * +* Return a metric of how 'empty' this bitmap is * *************************************************/ -Pooling_Allocator::~Pooling_Allocator() +u32bit emptiness_metric(u64bit bitmap) { - delete lock; - if(!initialized) - throw Invalid_State("Pooling_Allocator: Was never initialized"); - if(!destroyed) - throw Invalid_State("Pooling_Allocator: Never released memory"); + u32bit metric = 0; + for(u32bit j = 0; j != 8; ++j) + if(get_byte(j, bitmap) == 0) + metric++; + return metric; } +} + /************************************************* -* Allocate some initial buffers * +* Memory_Block Constructor * *************************************************/ -void Pooling_Allocator::init() +Pooling_Allocator::Memory_Block::Memory_Block(void* buf, u32bit map_size, + u32bit block_size) { - if(PREF_SIZE >= 64 && prealloc_bytes()) - { - u32bit allocated = 0; - while(allocated < prealloc_bytes()) - { - void* ptr = 0; - try { - ptr = alloc_block(PREF_SIZE); - allocated += PREF_SIZE; - } - catch(Exception) {} + buffer = static_cast(buf); + bitmap = 0; + how_empty = emptiness_metric(bitmap); + this->block_size = block_size; - if(!ptr) - break; + clear_mem(buffer, block_size * 64); - real_mem.push_back(Buffer(ptr, PREF_SIZE, false)); - } - } - - initialized = true; + if(map_size != 64) + throw Invalid_Argument("Memory_Block: Bad bitmap size, must be 64"); } /************************************************* -* Free all remaining memory * +* See if ptr is contained by this block * *************************************************/ -void Pooling_Allocator::destroy() +bool Pooling_Allocator::Memory_Block::contains(void* ptr, + u32bit length) const throw() { - if(!initialized) - throw Invalid_State("Pooling_Allocator::destroy(): Never initialized"); - if(destroyed) - throw Invalid_State("Pooling_Allocator::destroy(): Already destroyed"); - - destroyed = true; - for(u32bit j = 0; j != real_mem.size(); j++) - dealloc_block(real_mem[j].buf, real_mem[j].length); + return (buffer <= ptr && + ((byte*)ptr+length*block_size) <= (buffer + 64 * block_size)); } /************************************************* -* Buffer Comparison * +* Find a spot for a new allocation * *************************************************/ -bool Pooling_Allocator::is_empty_buffer(const Buffer& block) +bool Pooling_Allocator::Memory_Block::can_alloc(u32bit& start, + u32bit n) const throw() { - return (block.length == 0); - } + start = 0; -/************************************************* -* Return true if these buffers are contiguous * -*************************************************/ -bool Pooling_Allocator::are_contiguous(const Buffer& a, const Buffer& b) - { - if((const byte*)a.buf + a.length == (const byte*)b.buf) + if(n == 0 || n > 64 || (n == 64 && bitmap)) + return false; + + if(n == 64) return true; + + const u64bit mask = ((u64bit)1 << n) - 1; + + for(u32bit j = 0; j != 64 - n; ++j) + { + if((bitmap >> j) & mask) + continue; + + start = j; + return true; + } + return false; } /************************************************* -* See if two free blocks are from the same block * +* Allocate some memory, if possible * *************************************************/ -bool Pooling_Allocator::same_buffer(Buffer& a, Buffer& b) const +byte* Pooling_Allocator::Memory_Block::alloc(u32bit start, + u32bit n) throw() { - return (find_block(a.buf) == find_block(b.buf)); + if(start == 0 && n == 64) + { + bitmap = ~bitmap; + return buffer; + } + + u64bit mask = (((u64bit)1 << n) - 1) << start; + + bitmap |= mask; + how_empty = emptiness_metric(bitmap); + return buffer + start * block_size; } /************************************************* -* Find the block containing this memory * +* Mark this memory as free, if we own it * *************************************************/ -u32bit Pooling_Allocator::find_block(void* addr) const +void Pooling_Allocator::Memory_Block::free(void* ptr, u32bit blocks) throw() { - for(u32bit j = 0; j != real_mem.size(); j++) + clear_mem((byte*)ptr, blocks * block_size); + + const u32bit start = ((byte*)ptr - buffer) / block_size; + + if(start == 0 && blocks == 64) + bitmap = ~bitmap; + else { - const byte* buf_addr = (const byte*)real_mem[j].buf; - if(buf_addr <= (byte*)addr && - (byte*)addr < buf_addr + real_mem[j].length) - return j; + for(u32bit j = 0; j != blocks; ++j) + bitmap &= ~((u64bit)1 << (j+start)); } - throw Internal_Error("Pooling_Allocator::find_block: no buffer found"); + + how_empty = emptiness_metric(bitmap); } /************************************************* -* Remove empty buffers from list * +* Pooling_Allocator Constructor * *************************************************/ -void Pooling_Allocator::remove_empty_buffers(std::vector& list) const +Pooling_Allocator::Pooling_Allocator(u32bit p_size, bool) : + PREF_SIZE(choose_pref_size(p_size)), BLOCK_SIZE(64), BITMAP_SIZE(64) { - std::vector::iterator empty; - - empty = std::find_if(list.begin(), list.end(), is_empty_buffer); - while(empty != list.end()) - { - list.erase(empty); - empty = std::find_if(list.begin(), list.end(), is_empty_buffer); - } + mutex = global_state().get_mutex(); } /************************************************* -* Allocation * +* Pooling_Allocator Destructor * *************************************************/ -void* Pooling_Allocator::allocate(u32bit n) const +Pooling_Allocator::~Pooling_Allocator() { - struct Memory_Exhaustion : public Exception - { - Memory_Exhaustion() : - Exception("Pooling_Allocator: Ran out of memory") {} - }; - - if(n == 0) return 0; - n = round_up(n, ALIGN_TO); - - Mutex_Holder holder(lock); - - void* new_buf = find_free_block(n); - if(new_buf) - return alloc_hook(new_buf, n); - - Buffer block; - block.length = ((n > PREF_SIZE) ? n : PREF_SIZE); - block.buf = get_block(block.length); - if(!block.buf) - throw Memory_Exhaustion(); - free_list.push_back(block); - if(free_list.size() >= 2) - std::inplace_merge(free_list.begin(), free_list.end() - 1, - free_list.end()); - - new_buf = find_free_block(n); - if(new_buf) - return alloc_hook(new_buf, n); - - throw Memory_Exhaustion(); + delete mutex; + if(blocks.size()) + throw Invalid_State("Pooling_Allocator: Never released memory"); } /************************************************* -* Deallocation * +* Allocate some initial buffers * *************************************************/ -void Pooling_Allocator::deallocate(void* ptr, u32bit n) const +void Pooling_Allocator::init() { - const u32bit RUNS_TO_DEFRAGS = 16; + Mutex_Holder lock(mutex); - if(ptr == 0 || n == 0) return; - - n = round_up(n, ALIGN_TO); - std::memset(ptr, 0, n); - - Mutex_Holder holder(lock); - - dealloc_hook(ptr, n); - - free_list.push_back(Buffer(ptr, n)); - if(free_list.size() >= 2) - std::inplace_merge(free_list.begin(), free_list.end() - 1, - free_list.end()); - - defrag_counter = (defrag_counter + 1) % RUNS_TO_DEFRAGS; - if(defrag_counter == 0) - { - for(u32bit j = 0; j != free_list.size(); j++) - { - bool erase = false; - if(free_list[j].buf == 0) continue; - - for(u32bit k = 0; k != real_mem.size(); k++) - if(free_list[j].buf == real_mem[k].buf && - free_list[j].length == real_mem[k].length) - erase = true; - - if(erase) - { - const u32bit buf = find_block(free_list[j].buf); - free_block(real_mem[buf].buf, real_mem[buf].length); - free_list[j].buf = 0; - free_list[j].length = 0; - } - } - - remove_empty_buffers(real_mem); - defrag_free_list(); - } + get_more_core(PREF_SIZE); } /************************************************* -* Handle Allocating New Memory * +* Free all remaining memory * *************************************************/ -void* Pooling_Allocator::get_block(u32bit n) const +void Pooling_Allocator::destroy() { - for(u32bit j = 0; j != real_mem.size(); j++) - if(!real_mem[j].in_use && real_mem[j].length == n) - { - real_mem[j].in_use = true; - return real_mem[j].buf; - } + Mutex_Holder lock(mutex); - void* ptr = 0; - try { - ptr = alloc_block(n); - } - catch(Exception) {} + blocks.clear(); - if(ptr) - real_mem.push_back(Buffer(ptr, n, true)); - return ptr; + for(u32bit j = 0; j != allocated.size(); ++j) + dealloc_block(allocated[j].first, allocated[j].second); + allocated.clear(); } /************************************************* -* Handle Deallocating Memory * +* Allocation * *************************************************/ -void Pooling_Allocator::free_block(void* ptr, u32bit n) const +void* Pooling_Allocator::allocate(u32bit n) { - if(!ptr) return; + Mutex_Holder lock(mutex); - u32bit free_space = 0; - for(u32bit j = 0; j != real_mem.size(); j++) - if(!real_mem[j].in_use) - free_space += real_mem[j].length; + if(n <= BITMAP_SIZE * BLOCK_SIZE) + { + const u32bit block_no = round_up(n, BLOCK_SIZE) / BLOCK_SIZE; - bool free_this_block = false; - if(free_space > keep_free()) - free_this_block = true; + byte* mem = allocate_blocks(block_no); + if(mem) + return mem; - for(u32bit j = 0; j != real_mem.size(); j++) - if(real_mem[j].buf == ptr) - { - if(!real_mem[j].in_use || real_mem[j].length != n) - throw Internal_Error("Pooling_Allocator: Size mismatch in free"); + get_more_core(PREF_SIZE); - if(free_this_block) - { - dealloc_block(real_mem[j].buf, real_mem[j].length); - real_mem[j].buf = 0; - real_mem[j].length = 0; - } - else - real_mem[j].in_use = false; + mem = allocate_blocks(block_no); + if(mem) + return mem; - return; - } + throw Memory_Exhaustion(); + } - throw Internal_Error("Pooling_Allocator: Unknown pointer was freed"); + void* new_buf = alloc_block(n); + if(new_buf) + return new_buf; + + throw Memory_Exhaustion(); } /************************************************* -* Defragment the free list * +* Deallocation * *************************************************/ -void Pooling_Allocator::defrag_free_list() const +void Pooling_Allocator::deallocate(void* ptr, u32bit n) { - if(free_list.size() < 2) return; + if(ptr == 0 && n == 0) + return; - for(u32bit j = 0; j != free_list.size(); j++) + Mutex_Holder lock(mutex); + + if(n <= BITMAP_SIZE * BLOCK_SIZE) { - if(free_list[j].length == 0) - continue; + const u32bit block_no = round_up(n, BLOCK_SIZE) / BLOCK_SIZE; - if(j > 0 && - are_contiguous(free_list[j-1], free_list[j]) && - same_buffer(free_list[j-1], free_list[j])) + std::set::iterator i = blocks.begin(); + while(i != blocks.end()) { - free_list[j].buf = free_list[j-1].buf; - free_list[j].length += free_list[j-1].length; - free_list[j-1].length = 0; + if(i->contains(ptr, block_no)) + { + Memory_Block block = *i; + blocks.erase(i); + + block.free(ptr, block_no); + blocks.insert(block); + return; + } + ++i; } - if(j < free_list.size() - 1 && - are_contiguous(free_list[j], free_list[j+1]) && - same_buffer(free_list[j], free_list[j+1])) - { - free_list[j+1].buf = free_list[j].buf; - free_list[j+1].length += free_list[j].length; - free_list[j].length = 0; - } + throw Invalid_State("Pointer released to the wrong allocator"); } - remove_empty_buffers(free_list); + + dealloc_block(ptr, n); } /************************************************* -* Find a block on the free list * +* Allocate more memory for the pool * *************************************************/ -void* Pooling_Allocator::find_free_block(u32bit n) const +byte* Pooling_Allocator::allocate_blocks(u32bit n) { - void* retval = 0; + std::set::iterator i = blocks.begin(); - for(u32bit j = 0; j != free_list.size(); j++) - if(free_list[j].length >= n) + while(i != blocks.end()) + { + u32bit start = 0; + + if(i->can_alloc(start, n)) { - retval = free_list[j].buf; + Memory_Block block = *i; + blocks.erase(i); - if(free_list[j].length == n) - free_list.erase(free_list.begin() + j); - else if(free_list[j].length > n) - { - free_list[j].length -= n; - free_list[j].buf = ((byte*)free_list[j].buf) + n; - } - break; + byte* mem = block.alloc(start, n); + blocks.insert(block); + + return mem; } - return retval; - } + ++i; + } -/************************************************* -* Allocation hook for debugging * -*************************************************/ -void* Pooling_Allocator::alloc_hook(void* ptr, u32bit) const - { - return ptr; + return 0; } /************************************************* -* Deallocation hook for debugging * +* Allocate more memory for the pool * *************************************************/ -void Pooling_Allocator::dealloc_hook(void*, u32bit) const +void Pooling_Allocator::get_more_core(u32bit in_bytes) { - } + const u32bit TOTAL_BLOCK_SIZE = BLOCK_SIZE * BITMAP_SIZE; -/************************************************* -* Run internal consistency checks * -*************************************************/ -void Pooling_Allocator::consistency_check() const - { - for(u32bit j = 0; j != free_list.size(); j++) - { - const byte* byte_buf = (const byte*)free_list[j].buf; - const u32bit length = free_list[j].length; + const u32bit in_blocks = round_up(in_bytes, BLOCK_SIZE) / TOTAL_BLOCK_SIZE; + const u32bit to_allocate = in_blocks * TOTAL_BLOCK_SIZE; - for(u32bit k = 0; k != length; k++) - if(byte_buf[k]) - throw Internal_Error("Pooling_Allocator: free list corrupted"); - } + byte* ptr = static_cast(alloc_block(to_allocate)); + + if(ptr == 0) + throw Memory_Exhaustion(); + + allocated.push_back(std::make_pair(ptr, to_allocate)); + + for(u32bit j = 0; j != in_blocks; ++j) + blocks.insert( + Memory_Block(ptr + j * TOTAL_BLOCK_SIZE, BITMAP_SIZE, BLOCK_SIZE) + ); } - } ============================================================ --- botan/mem_pool.h 96e6c390b555075bc0335932142680360ef49f8b +++ botan/mem_pool.h dbc05bb8b4dfc24bd07cfef84fd84d5541e8ff43 @@ -1,6 +1,6 @@ /************************************************* * Pooling Allocator Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_POOLING_ALLOCATOR_H__ @@ -9,7 +9,9 @@ #include #include #include +#include #include +#include namespace Botan { @@ -19,57 +21,44 @@ class Pooling_Allocator : public Allocator { public: - void* allocate(u32bit) const; - void deallocate(void*, u32bit) const; + void* allocate(u32bit); + void deallocate(void*, u32bit); void init(); void destroy(); - Pooling_Allocator(u32bit = 0); + Pooling_Allocator(u32bit, bool); ~Pooling_Allocator(); private: - class Buffer - { - public: - void* buf; - u32bit length; - bool in_use; + void get_more_core(u32bit); + byte* allocate_blocks(u32bit); - bool operator<(const Buffer& x) const - { return ((const byte*)buf < (const byte*)x.buf); } + virtual void* alloc_block(u32bit) = 0; + virtual void dealloc_block(void*, u32bit) = 0; - Buffer() { buf = 0; length = 0; in_use = false; } - Buffer(void* b, u32bit l, bool used = false) - { buf = b; length = l; in_use = used; } - }; + struct Memory_Block + { + u64bit bitmap; + byte* buffer; + u32bit block_size, how_empty; - void* get_block(u32bit) const; - void free_block(void*, u32bit) const; + Memory_Block(void*, u32bit, u32bit); - virtual void* alloc_block(u32bit) const = 0; - virtual void dealloc_block(void*, u32bit) const = 0; - virtual u32bit prealloc_bytes() const { return 0; } - virtual u32bit keep_free() const { return 64*1024; } + bool can_alloc(u32bit&, u32bit) const throw(); + bool contains(void*, u32bit) const throw(); - void* alloc_hook(void*, u32bit) const; - void dealloc_hook(void*, u32bit) const; - void consistency_check() const; + byte* alloc(u32bit, u32bit) throw(); + void free(void*, u32bit) throw(); - void* find_free_block(u32bit) const; - void defrag_free_list() const; + bool operator<(const Memory_Block& other) const + { return (how_empty > other.how_empty); } + }; - u32bit find_block(void*) const; - bool same_buffer(Buffer&, Buffer&) const; - void remove_empty_buffers(std::vector&) const; + const u32bit PREF_SIZE, BLOCK_SIZE, BITMAP_SIZE; - static bool is_empty_buffer(const Buffer&); - static bool are_contiguous(const Buffer&, const Buffer&); - - const u32bit PREF_SIZE, ALIGN_TO; - mutable std::vector real_mem, free_list; - mutable Mutex* lock; - mutable u32bit defrag_counter; - bool initialized, destroyed; + std::multiset blocks; + std::vector > allocated; + Mutex* mutex; }; } ============================================================ --- botan/mgf1.cpp 495b1312a4936391dc3d0b246f3849e02eb830a2 +++ botan/mgf1.cpp bf33f05697c4578337fc9cc1410e1a4e84975990 @@ -1,6 +1,6 @@ /************************************************* * MGF1 Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -23,7 +23,7 @@ while(out_len) { hash->update(in, in_len); - for(u32bit j = 0; j != 4; j++) + for(u32bit j = 0; j != 4; ++j) hash->update(get_byte(j, counter)); SecureVector buffer = hash->final(); ============================================================ --- botan/mgf1.h 07c9dbfb8d70d446eb0735b9e7a0109334a728e6 +++ botan/mgf1.h 289afacc20735881b14bd084a4d170fac8703c9f @@ -1,6 +1,6 @@ /************************************************* * MGF1 Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_MGF1_H__ ============================================================ --- botan/mlock.cpp d357780c56771b5779d6c0f95ff7a20ef3f81898 +++ botan/mlock.cpp 4755235e70fac894c364c327397ee9fef15658e3 @@ -1,6 +1,6 @@ /************************************************* * Memory Locking Functions Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/mode_pad.cpp 6e13929f903c51c67f4f9cae3f1636d15a6e94b1 +++ botan/mode_pad.cpp f43891fdce0ba6fc32bfdee10553bb44f7d34937 @@ -1,6 +1,6 @@ /************************************************* * CBC Padding Methods Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -21,7 +21,7 @@ *************************************************/ void PKCS7_Padding::pad(byte block[], u32bit size, u32bit position) const { - for(u32bit j = 0; j != size; j++) + for(u32bit j = 0; j != size; ++j) block[j] = (size-position); } @@ -33,7 +33,7 @@ u32bit position = block[size-1]; if(position > size) throw Decoding_Error(name()); - for(u32bit j = size-position; j != size-1; j++) + for(u32bit j = size-position; j != size-1; ++j) if(block[j] != position) throw Decoding_Error(name()); return (size-position); @@ -55,7 +55,7 @@ *************************************************/ void ANSI_X923_Padding::pad(byte block[], u32bit size, u32bit position) const { - for(u32bit j = 0; j != size-position; j++) + for(u32bit j = 0; j != size-position; ++j) block[j] = 0; block[size-position-1] = (size-position); } @@ -68,7 +68,7 @@ u32bit position = block[size-1]; if(position > size) throw Decoding_Error(name()); - for(u32bit j = size-position; j != size-1; j++) + for(u32bit j = size-position; j != size-1; ++j) if(block[j] != 0) throw Decoding_Error(name()); return (size-position); @@ -91,7 +91,7 @@ void OneAndZeros_Padding::pad(byte block[], u32bit size, u32bit) const { block[0] = 0x80; - for(u32bit j = 1; j != size; j++) + for(u32bit j = 1; j != size; ++j) block[j] = 0x00; } ============================================================ --- botan/mode_pad.h 0ec59170055c96be7b3e7a70aa3a4e25baefbfcd +++ botan/mode_pad.h 9798f98d1e290349efa42220ed0690bdcb45189d @@ -1,12 +1,12 @@ /************************************************* * CBC Padding Methods Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_CBC_PADDING_H__ #define BOTAN_CBC_PADDING_H__ -#include +#include #include namespace Botan { @@ -14,15 +14,13 @@ /************************************************* * Block Cipher Mode Padding Method * *************************************************/ -class BlockCipherModePaddingMethod +class BlockCipherModePaddingMethod : public Algorithm { public: virtual void pad(byte[], u32bit, u32bit) const = 0; virtual u32bit unpad(const byte[], u32bit) const = 0; virtual u32bit pad_bytes(u32bit, u32bit) const; virtual bool valid_blocksize(u32bit) const = 0; - virtual std::string name() const = 0; - virtual ~BlockCipherModePaddingMethod() {} }; /************************************************* ============================================================ --- botan/modebase.cpp f55df855ab15cd85c53f74fcd09019136969253c +++ botan/modebase.cpp cfe177154a0a7dd9006f87f55f17956c3d5bd087 @@ -1,6 +1,6 @@ /************************************************* * Block Cipher Mode Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/modebase.h 9c6b1c98f71e261ecd853037c2a6f2a6abf4a09f +++ botan/modebase.h 11a987c1e68cb7b68203f307febd5c8ab7a54fdd @@ -1,6 +1,6 @@ /************************************************* * Block Cipher Mode Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_MODEBASE_H__ ============================================================ --- botan/mp_comba.cpp fe79003f739437691f78090af30ff3c0d08c7000 +++ botan/mp_comba.cpp ea841c092b0697f5297fb978cff5d71eee142149 @@ -1,32 +1,48 @@ /************************************************* -* Comba Multiplication Source File * -* (C) 1999-2005 The Botan Project * +* Comba Multiplication and Squaring Source File * +* (C) 1999-2006 The Botan Project * *************************************************/ #include -#include +#include namespace Botan { namespace { /************************************************* -* Multiply-Add Accumulator * +* Multiply-Add Accumulators * *************************************************/ -void word3_muladd(word* w2, word* w1, word* w0, word x, word y) +inline void word3_muladd(word* w2, word* w1, word* w0, word x, word y) { - word temp = 0; - bigint_madd(x, y, *w0, 0, w0, &temp); - *w1 += temp; - *w2 += (*w1 < temp) ? 1 : 0; + 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" { + /************************************************* * Comba 4x4 Multiplication * *************************************************/ -void bigint_comba4(word z[8], const word x[4], const word y[4]) +void bigint_comba_mul4(word z[8], const word x[4], const word y[4]) { word w2 = 0, w1 = 0, w0 = 0; @@ -65,7 +81,7 @@ /************************************************* * Comba 6x6 Multiplication * *************************************************/ -void bigint_comba6(word z[12], const word x[6], const word y[6]) +void bigint_comba_mul6(word z[12], const word x[6], const word y[6]) { word w2 = 0, w1 = 0, w0 = 0; @@ -132,7 +148,7 @@ /************************************************* * Comba 8x8 Multiplication * *************************************************/ -void bigint_comba8(word z[16], const word x[8], const word y[8]) +void bigint_comba_mul8(word z[16], const word x[8], const word y[8]) { word w2 = 0, w1 = 0, w0 = 0; @@ -232,4 +248,166 @@ z[15] = w1; } +/************************************************* +* Comba 4x4 Squaring * +*************************************************/ +void bigint_comba_sqr4(word z[8], const word x[4]) + { + word w2 = 0, w1 = 0, w0 = 0; + + word3_muladd(&w2, &w1, &w0, x[0], x[0]); + z[0] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[0], x[1]); + z[1] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[0], x[2]); + word3_muladd(&w2, &w1, &w0, x[1], x[1]); + z[2] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[0], x[3]); + word3_muladd_2(&w2, &w1, &w0, x[1], x[2]); + z[3] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[1], x[3]); + word3_muladd(&w2, &w1, &w0, x[2], x[2]); + z[4] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[2], x[3]); + z[5] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd(&w2, &w1, &w0, x[3], x[3]); + z[6] = w0; + z[7] = w1; + } + +/************************************************* +* Comba 6x6 Squaring * +*************************************************/ +void bigint_comba_sqr6(word z[12], const word x[6]) + { + word w2 = 0, w1 = 0, w0 = 0; + + word3_muladd(&w2, &w1, &w0, x[0], x[0]); + z[0] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[0], x[1]); + z[1] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[0], x[2]); + word3_muladd(&w2, &w1, &w0, x[1], x[1]); + z[2] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[0], x[3]); + word3_muladd_2(&w2, &w1, &w0, x[1], x[2]); + z[3] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[0], x[4]); + word3_muladd_2(&w2, &w1, &w0, x[1], x[3]); + word3_muladd(&w2, &w1, &w0, x[2], x[2]); + z[4] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[0], x[5]); + word3_muladd_2(&w2, &w1, &w0, x[1], x[4]); + word3_muladd_2(&w2, &w1, &w0, x[2], x[3]); + z[5] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[1], x[5]); + word3_muladd_2(&w2, &w1, &w0, x[2], x[4]); + word3_muladd(&w2, &w1, &w0, x[3], x[3]); + z[6] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[2], x[5]); + word3_muladd_2(&w2, &w1, &w0, x[3], x[4]); + z[7] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[3], x[5]); + word3_muladd(&w2, &w1, &w0, x[4], x[4]); + z[8] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[4], x[5]); + z[9] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd(&w2, &w1, &w0, x[5], x[5]); + z[10] = w0; + z[11] = w1; + } + +/************************************************* +* Comba 8x8 Squaring * +*************************************************/ +void bigint_comba_sqr8(word z[16], const word x[8]) + { + word w2 = 0, w1 = 0, w0 = 0; + + word3_muladd(&w2, &w1, &w0, x[0], x[0]); + z[0] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[0], x[1]); + z[1] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[0], x[2]); + word3_muladd(&w2, &w1, &w0, x[1], x[1]); + z[2] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[0], x[3]); + word3_muladd_2(&w2, &w1, &w0, x[1], x[2]); + z[3] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[0], x[4]); + word3_muladd_2(&w2, &w1, &w0, x[1], x[3]); + word3_muladd(&w2, &w1, &w0, x[2], x[2]); + z[4] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[0], x[5]); + word3_muladd_2(&w2, &w1, &w0, x[1], x[4]); + word3_muladd_2(&w2, &w1, &w0, x[2], x[3]); + z[5] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[0], x[6]); + word3_muladd_2(&w2, &w1, &w0, x[1], x[5]); + word3_muladd_2(&w2, &w1, &w0, x[2], x[4]); + word3_muladd(&w2, &w1, &w0, x[3], x[3]); + z[6] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[0], x[7]); + word3_muladd_2(&w2, &w1, &w0, x[1], x[6]); + word3_muladd_2(&w2, &w1, &w0, x[2], x[5]); + word3_muladd_2(&w2, &w1, &w0, x[3], x[4]); + z[7] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[1], x[7]); + word3_muladd_2(&w2, &w1, &w0, x[2], x[6]); + word3_muladd_2(&w2, &w1, &w0, x[3], x[5]); + word3_muladd(&w2, &w1, &w0, x[4], x[4]); + z[8] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[2], x[7]); + word3_muladd_2(&w2, &w1, &w0, x[3], x[6]); + word3_muladd_2(&w2, &w1, &w0, x[4], x[5]); + z[9] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[3], x[7]); + word3_muladd_2(&w2, &w1, &w0, x[4], x[6]); + word3_muladd(&w2, &w1, &w0, x[5], x[5]); + z[10] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[4], x[7]); + word3_muladd_2(&w2, &w1, &w0, x[5], x[6]); + z[11] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[5], x[7]); + word3_muladd(&w2, &w1, &w0, x[6], x[6]); + z[12] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd_2(&w2, &w1, &w0, x[6], x[7]); + z[13] = w0; w0 = w1; w1 = w2; w2 = 0; + + word3_muladd(&w2, &w1, &w0, x[7], x[7]); + z[14] = w0; + z[15] = w1; + } + } + +} ============================================================ --- botan/mp_core.h 5f8d926528ccb7e579d3778bfa61c6fc2d388b43 +++ botan/mp_core.h af2e3afc3189ae2734b60216033ff361edbfda6c @@ -1,6 +1,6 @@ /************************************************* * MPI Algorithms Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_MP_CORE_H__ @@ -15,22 +15,22 @@ *************************************************/ const u32bit MP_WORD_BITS = BOTAN_MP_WORD_BITS; +extern "C" { + /************************************************* -* Two Argument MP Core * +* Addition/Subtraction Operations * *************************************************/ void bigint_add2(word[], u32bit, const word[], u32bit); -void bigint_sub2(word[], u32bit, const word[], u32bit); -void bigint_linmul2(word[], u32bit, word); +void bigint_add3(word[], const word[], u32bit, const word[], u32bit); -/************************************************* -* Three Argument MP Core * -*************************************************/ -void bigint_add3(word[], const word[], u32bit, const word[], u32bit); -void bigint_sub3(word[] , const word[], u32bit, const word[], u32bit); -void bigint_linmul3(word[], const word[], u32bit, word); +word bigint_add2_nc(word[], u32bit, const word[], u32bit); +word bigint_add3_nc(word[], const word[], u32bit, const word[], u32bit); +void bigint_sub2(word[], u32bit, const word[], u32bit); +void bigint_sub3(word[], const word[], u32bit, const word[], u32bit); + /************************************************* -* MP Shifting * +* Shift Operations * *************************************************/ void bigint_shl1(word[], u32bit, u32bit, u32bit); void bigint_shl2(word[], const word[], u32bit, u32bit, u32bit); @@ -38,44 +38,42 @@ void bigint_shr2(word[], const word[], u32bit, u32bit, u32bit); /************************************************* -* Comba Multiplication * +* Linear Multiplication Operations * *************************************************/ -void bigint_comba4(word[8], const word[4], const word[4]); -void bigint_comba6(word[12], const word[6], const word[6]); -void bigint_comba8(word[16], const word[8], const word[8]); +void bigint_linmul2(word[], u32bit, word); +void bigint_linmul3(word[], const word[], u32bit, word); /************************************************* -* Karatsuba Multiplication * +* Misc Utility Operations * *************************************************/ -void bigint_karat16(word[32], const word[16], const word[16]); -void bigint_karat32(word[64], const word[32], const word[32]); -void bigint_karat64(word[128], const word[64], const word[64]); -void bigint_karat128(word[256], const word[128], const word[128]); +u32bit bigint_divcore(word, word, word, word, word, word); +s32bit bigint_cmp(const word[], u32bit, const word[], u32bit); +word bigint_divop(word, word, word); +word bigint_modop(word, word, word); +void bigint_wordmul(word, word, word*, word*); -void bigint_karat12(word[24], const word[12], const word[12]); -void bigint_karat24(word[48], const word[24], const word[24]); -void bigint_karat48(word[96], const word[48], const word[48]); -void bigint_karat96(word[192], const word[96], const word[96]); - /************************************************* -* Simple O(N^2) Multiplication * +* Comba Multiplication / Squaring * *************************************************/ -void bigint_smul(word[], const word[], u32bit, const word[], u32bit); +void bigint_comba_mul4(word[8], const word[4], const word[4]); +void bigint_comba_mul6(word[12], const word[6], const word[6]); +void bigint_comba_mul8(word[16], const word[8], const word[8]); +void bigint_comba_sqr4(word[8], const word[4]); +void bigint_comba_sqr6(word[12], const word[6]); +void bigint_comba_sqr8(word[16], const word[8]); + +} + /************************************************* -* MP Multiplication * +* Multiplication/Squaring Operations * *************************************************/ void bigint_mul3(word[], u32bit, const word[], u32bit, u32bit, const word[], u32bit, u32bit); +void bigint_sqr(word[], u32bit, const word[], u32bit, u32bit); -/************************************************* -* Misc MP Algorithms * -*************************************************/ -u32bit bigint_divcore(word, word, word, word, word, word); -s32bit bigint_cmp(const word[], u32bit, const word[], u32bit); -word bigint_divop(word, word, word); -word bigint_modop(word, word, word); -void bigint_wordmul(word, word, word*, word*); +void bigint_simple_mul(word[], const word[], u32bit, const word[], u32bit); +void bigint_simple_sqr(word[], const word[], u32bit); } ============================================================ --- botan/mp_misc.cpp 14c95fd2efacea3ba45e7f29e71a676ef834433c +++ botan/mp_misc.cpp 403da43006f3563e3f7610b2ad6efff0034b5809 @@ -1,13 +1,15 @@ /************************************************* * MP Misc Functions Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include -#include +#include namespace Botan { +extern "C" { + /************************************************* * Core Division Operation * *************************************************/ @@ -15,8 +17,8 @@ word x1, word x2, word x3) { word y0 = 0; - bigint_madd(q, y2, 0, 0, &y2, &y0); - bigint_madd(q, y1, y0, 0, &y1, &y0); + word_madd(q, y2, 0, 0, &y2, &y0); + word_madd(q, y1, y0, 0, &y1, &y0); if(y0 > x1) return 1; if(y0 < x1) return 0; @@ -56,7 +58,7 @@ { word high = n1 % d; word quotient = 0; - for(u32bit j = 0; j != MP_WORD_BITS; j++) + for(u32bit j = 0; j != MP_WORD_BITS; ++j) { const word mask = (word)1 << (MP_WORD_BITS-1-j); const bool high_top_bit = (high & MP_WORD_TOP_BIT) ? true : false; @@ -79,8 +81,8 @@ { word z0 = n1 / d, z1 = bigint_divop(n1, n0, d); word carry = 0; - bigint_madd(z1, d, 0, 0, &z1, &carry); - bigint_madd(z0, d, carry, 0, &z0, &carry); + word_madd(z1, d, 0, 0, &z1, &carry); + word_madd(z0, d, carry, 0, &z0, &carry); return (n0-z1); } @@ -112,3 +114,5 @@ } } + +} ============================================================ --- botan/mp_mul.cpp 1a89216eb5fb97faaa1b948ed019813cf4404d80 +++ botan/mp_mul.cpp c22efb440d348bddd92f117a37a3296f112a92e9 @@ -1,85 +1,240 @@ /************************************************* -* MP Multiplication Source File * -* (C) 1999-2005 The Botan Project * +* Karatsuba Multiplication Source File * +* (C) 1999-2006 The Botan Project * *************************************************/ #include +#include +#include namespace Botan { -namespace { +/************************************************* +* 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) + { + 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; + } + /************************************************* -* Length Checking * +* Three Operand Linear Multiply * *************************************************/ -bool use_op(u32bit x_sw, u32bit y_sw, - u32bit x_size, u32bit y_size, u32bit z_size, - u32bit limit, u32bit min = 0) +void bigint_linmul3(word z[], const word x[], u32bit x_size, word y) { - return (x_sw <= limit && y_sw <= limit && - x_size >= limit && y_size >= limit && z_size >= 2*limit && - (x_sw + y_sw) >= min); + 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; } /************************************************* -* Attempt a Karatsuba multiply * +* Simple O(N^2) Multiplication * *************************************************/ -bool do_karat(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_simple_mul(word z[], const word x[], u32bit x_size, + const word y[], u32bit y_size) { - const u32bit KARAT_12_BOUND = 20; - const u32bit KARAT_16_BOUND = 24; - const u32bit KARAT_24_BOUND = 38; - const u32bit KARAT_32_BOUND = 46; - const u32bit KARAT_48_BOUND = 66; - const u32bit KARAT_64_BOUND = 80; - const u32bit KARAT_96_BOUND = 114; - const u32bit KARAT_128_BOUND = 136; + const u32bit blocks = y_size - (y_size % 8); - if(use_op(x_sw, y_sw, x_size, y_size, z_size, 12, KARAT_12_BOUND)) - bigint_karat12(z, x, y); - else if(use_op(x_sw, y_sw, x_size, y_size, z_size, 16, KARAT_16_BOUND)) - bigint_karat16(z, x, y); - else if(use_op(x_sw, y_sw, x_size, y_size, z_size, 24, KARAT_24_BOUND)) - bigint_karat24(z, x, y); - else if(use_op(x_sw, y_sw, x_size, y_size, z_size, 32, KARAT_32_BOUND)) - bigint_karat32(z, x, y); - else if(use_op(x_sw, y_sw, x_size, y_size, z_size, 48, KARAT_48_BOUND)) - bigint_karat48(z, x, y); - else if(use_op(x_sw, y_sw, x_size, y_size, z_size, 64, KARAT_64_BOUND)) - bigint_karat64(z, x, y); - else if(use_op(x_sw, y_sw, x_size, y_size, z_size, 96, KARAT_96_BOUND)) - bigint_karat96(z, x, y); - else if(use_op(x_sw, y_sw, x_size, y_size, z_size, 128, KARAT_128_BOUND)) - bigint_karat128(z, x, y); + 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 { + +/************************************************* +* Karatsuba Multiplication Operation * +*************************************************/ +void karatsuba_mul(word z[], const word x[], const word y[], u32bit N, + word workspace[]) + { + const u32bit KARATSUBA_MUL_LOWER_SIZE = BOTAN_KARAT_MUL_THRESHOLD; + + if(N == 6) + bigint_comba_mul6(z, x, y); + else if(N == 8) + bigint_comba_mul8(z, x, y); + else if(N < KARATSUBA_MUL_LOWER_SIZE || N % 2) + bigint_simple_mul(z, x, N, y, N); else - return false; + { + const u32bit N2 = N / 2; - return true; + const word* x0 = x; + const word* x1 = x + N2; + const word* y0 = y; + const word* y1 = y + N2; + word* z0 = z; + word* z1 = z + N; + + const s32bit cmp0 = bigint_cmp(x0, N2, x1, N2); + const s32bit cmp1 = bigint_cmp(y1, N2, y0, N2); + + clear_mem(workspace, 2*N); + + if(cmp0 && cmp1) + { + if(cmp0 > 0) + bigint_sub3(z0, x0, N2, x1, N2); + else + bigint_sub3(z0, x1, N2, x0, N2); + + if(cmp1 > 0) + bigint_sub3(z1, y1, N2, y0, N2); + else + bigint_sub3(z1, y0, N2, y1, N2); + + karatsuba_mul(workspace, z0, z1, N2, workspace+N); + } + + karatsuba_mul(z0, x0, y0, N2, workspace+N); + karatsuba_mul(z1, x1, y1, N2, workspace+N); + + word carry = bigint_add3_nc(workspace+N, z0, N, z1, N); + carry += bigint_add2_nc(z + N2, N, workspace + N, N); + bigint_add2_nc(z + N + N2, N2, &carry, 1); + + if((cmp0 == cmp1) || (cmp0 == 0) || (cmp1 == 0)) + bigint_add2(z + N2, 2*N-N2, workspace, N); + else + bigint_sub2(z + N2, 2*N-N2, workspace, N); + } } +/************************************************* +* Pick a good size for the Karatsuba multiply * +*************************************************/ +u32bit karatsuba_size(u32bit x_size, u32bit x_sw, u32bit y_size, u32bit y_sw) + { + if(x_sw > y_size || y_sw > x_size) + return 0; + if(((x_size == x_sw) && (x_size % 2)) || + ((y_size == y_sw) && (y_size % 2))) + return 0; + u32bit start = (x_sw > y_sw) ? x_sw : y_sw; + u32bit end = (x_size < y_size) ? x_size : y_size; + + if(end < start) + return 0; + + if(start == end) + { + if(start % 2) + return 0; + return start; + } + + for(u32bit j = start; j <= end; ++j) + if(j % 2 == 0 && x_sw <= j && j <= x_size && y_sw <= j && j <= y_size) + { + if(j % 4 == 2 && (j+2) < x_size && (j+2) < y_size) + return (j+2); + return j; + } + return 0; + } + +/************************************************* +* Handle small operand multiplies * +*************************************************/ +void handle_small_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_sw == 1) bigint_linmul3(z, y, y_sw, x[0]); + else if(y_sw == 1) bigint_linmul3(z, x, x_sw, y[0]); + + else if(x_sw <= 4 && y_sw <= 4 && + x_size >= 4 && y_size >= 4 && z_size >= 8) + bigint_comba_mul4(z, x, y); + + else if(x_sw <= 6 && y_sw <= 6 && + x_size >= 6 && y_size >= 6 && z_size >= 12) + bigint_comba_mul6(z, x, y); + + else if(x_sw <= 8 && y_sw <= 8 && + x_size >= 8 && y_size >= 8 && z_size >= 16) + bigint_comba_mul8(z, x, y); + + else + bigint_simple_mul(z, x, x_sw, y, y_sw); + } + } /************************************************* -* MP Multiplication Algorithm Dispatcher * +* 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) { - if(x_sw == 1) bigint_linmul3(z, y, y_sw, x[0]); - else if(y_sw == 1) bigint_linmul3(z, x, x_sw, y[0]); + if(x_size <= 8 || y_size <= 8) + { + handle_small_mul(z, z_size, x, x_size, x_sw, y, y_size, y_sw); + return; + } - else if(use_op(x_sw, y_sw, x_size, y_size, z_size, 4)) - bigint_comba4(z, x, y); - else if(use_op(x_sw, y_sw, x_size, y_size, z_size, 6)) - bigint_comba6(z, x, y); - else if(use_op(x_sw, y_sw, x_size, y_size, z_size, 8)) - bigint_comba8(z, x, y); - else if(!do_karat(z, z_size, x, x_size, x_sw, y, y_size, y_sw)) - bigint_smul(z, x, x_sw, y, y_sw); + const u32bit N = karatsuba_size(x_size, x_sw, y_size, y_sw); + + if(N) + { + word* workspace = new word[2*N]; + clear_mem(workspace, 2*N); + karatsuba_mul(z, x, y, N, workspace); + clear_mem(workspace, 2*N); + delete[] workspace; + } + else + bigint_simple_mul(z, x, x_sw, y, y_sw); } } ============================================================ --- botan/mp_shift.cpp b0d06068404ec8818092b23bfcbdbafe0f804be6 +++ botan/mp_shift.cpp 325a72292b8477bba5aecfede199e01b6ada1992 @@ -1,6 +1,6 @@ /************************************************* * MP Shift Algorithms Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -8,6 +8,8 @@ namespace Botan { +extern "C" { + /************************************************* * Single Operand Left Shift * *************************************************/ @@ -15,7 +17,7 @@ { if(word_shift) { - for(u32bit j = 1; j != x_size + 1; j++) + for(u32bit j = 1; j != x_size + 1; ++j) x[(x_size - j) + word_shift] = x[x_size - j]; clear_mem(x, word_shift); } @@ -23,7 +25,7 @@ if(bit_shift) { word carry = 0; - for(u32bit j = word_shift; j != x_size + word_shift + 1; j++) + for(u32bit j = word_shift; j != x_size + word_shift + 1; ++j) { word temp = x[j]; x[j] = (temp << bit_shift) | carry; @@ -43,9 +45,9 @@ return; } - for(u32bit j = 0; j != x_size - word_shift; j++) + for(u32bit j = 0; j != x_size - word_shift; ++j) x[j] = x[j + word_shift]; - for(u32bit j = x_size - word_shift; j != x_size; j++) + for(u32bit j = x_size - word_shift; j != x_size; ++j) x[j] = 0; if(bit_shift) @@ -66,12 +68,12 @@ void bigint_shl2(word y[], const word x[], u32bit x_size, u32bit word_shift, u32bit bit_shift) { - for(u32bit j = 0; j != x_size; j++) + for(u32bit j = 0; j != x_size; ++j) y[j + word_shift] = x[j]; if(bit_shift) { word carry = 0; - for(u32bit j = word_shift; j != x_size + word_shift + 1; j++) + for(u32bit j = word_shift; j != x_size + word_shift + 1; ++j) { word temp = y[j]; y[j] = (temp << bit_shift) | carry; @@ -88,7 +90,7 @@ { if(x_size < word_shift) return; - for(u32bit j = 0; j != x_size - word_shift; j++) + for(u32bit j = 0; j != x_size - word_shift; ++j) y[j] = x[j + word_shift]; if(bit_shift) { @@ -103,3 +105,5 @@ } } + +} ============================================================ --- botan/mp_types.h 3d35d7b7414c08f0516573f15d99ef5db3b977d2 +++ botan/mp_types.h e9a7d9daa17a17667fc62e90f97ce660092de0ad @@ -1,6 +1,6 @@ /************************************************* * Low Level MPI Types Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_MPI_TYPES_H__ ============================================================ --- botan/mutex.cpp 5178b950cb9ac2c1e726d470bd9edf1e2afb4afb +++ botan/mutex.cpp 879ae577f26b33ad7039c8c63e3a5e1dfd8e3866 @@ -1,23 +1,15 @@ /************************************************* * Mutex Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include -#include -#include namespace Botan { namespace { /************************************************* -* Global Mutex Variables * -*************************************************/ -Mutex* mutex_factory = 0; -Mutex* mutex_init_lock = 0; - -/************************************************* * Default Mutex * *************************************************/ class Default_Mutex : public Mutex @@ -25,7 +17,6 @@ public: void lock(); void unlock(); - Mutex* clone() const { return new Default_Mutex; } Default_Mutex() { locked = false; } private: bool locked; @@ -54,48 +45,29 @@ } /************************************************* -* Get a mew mutex * +* Mutex_Holder Constructor * *************************************************/ -Mutex* get_mutex() +Mutex_Holder::Mutex_Holder(Mutex* m) : mux(m) { - if(mutex_factory == 0) - return new Default_Mutex; - return mutex_factory->clone(); + if(!mux) + throw Invalid_Argument("Mutex_Holder: Argument was NULL"); + mux->lock(); } /************************************************* -* Initialize a mutex atomically * +* Mutex_Holder Destructor * *************************************************/ -void initialize_mutex(Mutex*& mutex) +Mutex_Holder::~Mutex_Holder() { - if(mutex) return; - - if(mutex_init_lock) - { - Mutex_Holder lock(mutex_init_lock); - if(mutex == 0) - mutex = get_mutex(); - } - else - mutex = get_mutex(); + mux->unlock(); } -namespace Init { - /************************************************* -* Set the Mutex type * +* Default Mutex Factory * *************************************************/ -void set_mutex_type(Mutex* mutex) +Mutex* Mutex_Factory::make() { - delete mutex_factory; - delete mutex_init_lock; - - mutex_factory = mutex; - - if(mutex) mutex_init_lock = get_mutex(); - else mutex_init_lock = 0; + return new Default_Mutex; } } - -} ============================================================ --- botan/mutex.h 28413d972111f69c83901ddd9909b532008ba6f2 +++ botan/mutex.h 8a7e3579fcb04cc12d232b5312044486a44508a4 @@ -1,11 +1,13 @@ /************************************************* * Mutex Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_MUTEX_H__ #define BOTAN_MUTEX_H__ +#include + namespace Botan { /************************************************* @@ -16,7 +18,6 @@ public: virtual void lock() = 0; virtual void unlock() = 0; - virtual Mutex* clone() const = 0; virtual ~Mutex() {} }; @@ -26,17 +27,21 @@ class Mutex_Holder { public: - Mutex_Holder(Mutex* m) : mux(m) { mux->lock(); } - ~Mutex_Holder() { mux->unlock(); } + Mutex_Holder(Mutex*); + ~Mutex_Holder(); private: Mutex* mux; }; /************************************************* -* Get/set a mutex * +* Mutex Factory * *************************************************/ -Mutex* get_mutex(); -void initialize_mutex(Mutex*&); +class Mutex_Factory + { + public: + virtual Mutex* make(); + virtual ~Mutex_Factory() {} + }; } ============================================================ --- botan/numthry.cpp 1a9aad79b7e3041179f8f107778421257d2c7bbf +++ botan/numthry.cpp 6a5d1c3ce4a22e0008ef01684c5b9d129dcd23ad @@ -1,9 +1,10 @@ /************************************************* * Number Theory Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include +#include #include namespace Botan { @@ -53,7 +54,7 @@ { 0, 0, 0 } }; - for(u32bit j = 0; tests[j].bits; j++) + for(u32bit j = 0; tests[j].bits; ++j) { if(bits <= tests[j].bits) if(verify) @@ -114,14 +115,6 @@ } /************************************************* -* Square a BigInt * -*************************************************/ -BigInt square(const BigInt& a) - { - return (a * a); - } - -/************************************************* * Find the Modular Inverse * *************************************************/ BigInt inverse_mod(const BigInt& n, const BigInt& mod) @@ -141,7 +134,7 @@ { u32bit zero_bits = low_zero_bits(u); u >>= zero_bits; - for(u32bit j = 0; j != zero_bits; j++) + for(u32bit j = 0; j != zero_bits; ++j) { if(A.is_odd() || B.is_odd()) { A += y; B -= x; } @@ -150,7 +143,7 @@ zero_bits = low_zero_bits(v); v >>= zero_bits; - for(u32bit j = 0; j != zero_bits; j++) + for(u32bit j = 0; j != zero_bits; ++j) { if(C.is_odd() || D.is_odd()) { C += y; D -= x; } @@ -227,6 +220,17 @@ } /************************************************* +* Modular Exponentiation * +*************************************************/ +BigInt power_mod(const BigInt& base, const BigInt& exp, const BigInt& mod) + { + Power_Mod pow_mod(mod); + pow_mod.set_base(base); + pow_mod.set_exponent(exp); + return pow_mod.execute(); + } + +/************************************************* * Do simple tests of primality * *************************************************/ s32bit simple_primality_tests(const BigInt& n) @@ -241,7 +245,7 @@ if(n <= PRIMES[PRIME_TABLE_SIZE-1]) { const word num = n.word_at(0); - for(u32bit j = 0; PRIMES[j]; j++) + for(u32bit j = 0; PRIMES[j]; ++j) { if(num == PRIMES[j]) return PRIME; if(num < PRIMES[j]) return NOT_PRIME; @@ -250,7 +254,7 @@ } u32bit check_first = std::min(n.bits() / 32, PRIME_PRODUCTS_TABLE_SIZE); - for(u32bit j = 0; j != check_first; j++) + for(u32bit j = 0; j != check_first; ++j) if(gcd(n, PRIME_PRODUCTS[j]) != 1) return NOT_PRIME; @@ -316,9 +320,9 @@ u32bit tests = miller_rabin_test_iterations(n.bits(), verify); BigInt nonce; - for(u32bit j = 0; j != tests; j++) + for(u32bit j = 0; j != tests; ++j) { - if(verify) nonce = random_integer(NONCE_BITS, Nonce); + if(verify) nonce = random_integer(NONCE_BITS); else nonce = PRIMES[j]; if(!mr.passes_test(nonce)) @@ -336,15 +340,16 @@ throw Invalid_Argument("Bad size for nonce in Miller-Rabin test"); UI::pulse(UI::PRIME_TESTING); - BigInt y = power_mod(a, r, reducer); + BigInt y = pow_mod(a); if(y == 1 || y == n_minus_1) return true; - for(u32bit j = 1; j != s; j++) + for(u32bit j = 1; j != s; ++j) { UI::pulse(UI::PRIME_TESTING); - y = reducer->square(y); + y = reducer->reduce(square(y)); + if(y == 1) return false; if(y == n_minus_1) @@ -366,7 +371,16 @@ s = low_zero_bits(n_minus_1); r = n_minus_1 >> s; + pow_mod = Fixed_Exponent_Power_Mod(r, n); reducer = get_reducer(n); } +/************************************************* +* Miller-Rabin Constructor * +*************************************************/ +MillerRabin_Test::~MillerRabin_Test() + { + delete reducer; + } + } ============================================================ --- botan/numthry.h 7cd9a6b6f82dfbcb7ae04d7ecbca6a97fba83d67 +++ botan/numthry.h e7a209c8c3b650b8627798c12d01a57a009dfe89 @@ -1,13 +1,13 @@ /************************************************* * Number Theory Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_NUMBTHRY_H__ #define BOTAN_NUMBTHRY_H__ #include -#include +#include namespace Botan { @@ -33,12 +33,8 @@ BigInt square(const BigInt&); BigInt inverse_mod(const BigInt&, const BigInt&); s32bit jacobi(const BigInt&, const BigInt&); -BigInt power(const BigInt&, u32bit); -/************************************************* -* Modular Exponentiation * -*************************************************/ -BigInt power_mod(const BigInt&, const BigInt&, ModularReducer*); +BigInt power(const BigInt&, u32bit); BigInt power_mod(const BigInt&, const BigInt&, const BigInt&); /************************************************* @@ -60,11 +56,10 @@ /************************************************* * Random Number Generation * *************************************************/ -BigInt random_integer(u32bit, RNG_Quality = SessionKey); -BigInt random_integer(const BigInt&, const BigInt&, RNG_Quality = SessionKey); -BigInt random_prime(u32bit, RNG_Quality = SessionKey, const BigInt& = 1, - u32bit = 1, u32bit = 2); -BigInt random_safe_prime(u32bit, RNG_Quality = SessionKey); +BigInt random_integer(u32bit); +BigInt random_integer(const BigInt&, const BigInt&); +BigInt random_prime(u32bit, const BigInt& = 1, u32bit = 1, u32bit = 2); +BigInt random_safe_prime(u32bit); SecureVector generate_dsa_primes(BigInt&, BigInt&, u32bit); bool generate_dsa_primes(BigInt&, BigInt&, const byte[], u32bit, u32bit, @@ -88,13 +83,14 @@ bool passes_test(const BigInt&); MillerRabin_Test(const BigInt&); - ~MillerRabin_Test() { delete reducer; } + ~MillerRabin_Test(); private: MillerRabin_Test(const MillerRabin_Test&) {} MillerRabin_Test& operator=(const MillerRabin_Test&) { return (*this); } BigInt n, r, n_minus_1; u32bit s; - ModularReducer* reducer; + Fixed_Exponent_Power_Mod pow_mod; + class ModularReducer* reducer; }; } ============================================================ --- botan/ofb.cpp c9f5e8a40fda1f792eb91972cb72beccfb14e1d1 +++ botan/ofb.cpp ce7e2a5f1d9f76971ad66c6b79015a7e894fb506 @@ -1,6 +1,6 @@ /************************************************* * OFB Mode Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/ofb.h b829ab377c4d4ffd01d08317ab44af8e94b52ed4 +++ botan/ofb.h 88c86eb33b448ac17ad5d533224ecfc902941d3a @@ -1,6 +1,6 @@ /************************************************* * OFB Mode Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_OFB_H__ ============================================================ --- botan/oids.cpp 2c16a47ec99aa367578e36a96ddb52e4c1315de8 +++ botan/oids.cpp 10fd1940bfb9469d8cc4c8833fa0a28bd5ca4674 @@ -1,115 +1,13 @@ /************************************************* * OID Registry Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include -#include -#include -#include -#include +#include namespace Botan { -namespace { - -/************************************************* -* OID<->String Mappings * -*************************************************/ -class OID_Mapper - { - public: - void add_oid(const OID&, const std::string&); - - bool have_oid(const std::string&); - std::string lookup(const OID&); - OID lookup(const std::string&); - - OID_Mapper() { oid_mutex = get_mutex(); } - ~OID_Mapper() { delete oid_mutex; } - private: - std::map oid_to_str; - std::map str_to_oid; - Mutex* oid_mutex; - }; - -/************************************************* -* Register an OID to string mapping * -*************************************************/ -void OID_Mapper::add_oid(const OID& oid, const std::string& name) - { - Mutex_Holder lock(oid_mutex); - - if(oid_to_str.find(oid) == oid_to_str.end()) - oid_to_str[oid] = name; - if(str_to_oid.find(name) == str_to_oid.end()) - str_to_oid[name] = oid; - } - -/************************************************* -* Do an OID to string lookup * -*************************************************/ -std::string OID_Mapper::lookup(const OID& oid) - { - Mutex_Holder lock(oid_mutex); - - std::map::const_iterator info = oid_to_str.find(oid); - if(info == oid_to_str.end()) - return oid.as_string(); - return info->second; - } - -/************************************************* -* Do a string to OID lookup * -*************************************************/ -OID OID_Mapper::lookup(const std::string& name) - { - Mutex_Holder lock(oid_mutex); - - std::map::const_iterator info = str_to_oid.find(name); - if(info == str_to_oid.end()) - throw Lookup_Error("No known OID for " + name); - return info->second; - } - -/************************************************* -* Check to see if an OID exists in the table * -*************************************************/ -bool OID_Mapper::have_oid(const std::string& name) - { - Mutex_Holder lock(oid_mutex); - - return (str_to_oid.find(name) != str_to_oid.end()); - } - -/************************************************* -* Global OID map * -*************************************************/ -OID_Mapper* mapping = 0; - -} - -namespace Init { - -/************************************************* -* Startup the OID mapping system * -*************************************************/ -void startup_oids() - { - mapping = new OID_Mapper; - } - -/************************************************* -* Shutdown the OID mapping system * -*************************************************/ -void shutdown_oids() - { - delete mapping; - mapping = 0; - } - -} - namespace OIDS { /************************************************* @@ -117,9 +15,12 @@ *************************************************/ void add_oid(const OID& oid, const std::string& name) { - if(!mapping) - throw Internal_Error("OIDS::add_oid: Mapping not initialized"); - mapping->add_oid(oid, name); + const std::string oid_str = oid.as_string(); + + if(!global_state().option_set("oid2str", oid_str)) + global_state().set_option("oid2str", oid_str, name); + if(!global_state().option_set("str2oid", name)) + global_state().set_option("str2oid", name, oid_str); } /************************************************* @@ -127,9 +28,7 @@ *************************************************/ std::string lookup(const OID& oid) { - if(!mapping) - throw Internal_Error("OIDS::lookup: Mapping not initialized"); - return mapping->lookup(oid); + return global_state().get_option("oid2str", oid.as_string()); } /************************************************* @@ -137,9 +36,7 @@ *************************************************/ OID lookup(const std::string& name) { - if(!mapping) - throw Internal_Error("OIDS::lookup: Mapping not initialized"); - return mapping->lookup(name); + return OID(global_state().get_option("str2oid", name)); } /************************************************* @@ -147,9 +44,7 @@ *************************************************/ bool have_oid(const std::string& name) { - if(!mapping) - throw Internal_Error("OIDS::lookup: Mapping not initialized"); - return mapping->have_oid(name); + return global_state().option_set("str2oid", name); } } ============================================================ --- botan/oids.h ff39689a4be354d6e3f7572d8685a35d129f9f44 +++ botan/oids.h 3005c408ccd28f21be6d7e1aa621873059e4c552 @@ -1,6 +1,6 @@ /************************************************* * OID Registry Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_OIDS_H__ ============================================================ --- botan/out_buf.cpp 0389fab8523d683166eec1bb43707c2c68e89dd1 +++ botan/out_buf.cpp 2489a9bec82d69346621189012595616f879bf93 @@ -1,6 +1,6 @@ /************************************************* * Pipe Output Buffer Source file * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -65,6 +65,7 @@ { if(buffers[0] == 0 || buffers[0]->size() == 0) { + delete buffers[0]; buffers.pop_front(); offset++; } @@ -107,7 +108,7 @@ *************************************************/ Output_Buffers::~Output_Buffers() { - for(u32bit j = 0; j != buffers.size(); j++) + for(u32bit j = 0; j != buffers.size(); ++j) delete buffers[j]; } ============================================================ --- botan/out_buf.h 1a0f690209f84f17abbee097aabbb8822dbe0f1e +++ botan/out_buf.h 41a263e3362e4387260349e069f3f60b80798ff1 @@ -1,6 +1,6 @@ /************************************************* * Output Buffer Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_OUTPUT_BUFFER_H__ ============================================================ --- botan/par_hash.h db8899df56e0764c6d1c01cbecf5e8c665fad98b +++ botan/par_hash.h 71d7dccfc77480d0978ed5aa945b8feab9a5e945 @@ -1,6 +1,6 @@ /************************************************* * Parallel Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_PAR_HASH_H__ ============================================================ --- botan/parsing.cpp 18bc352e3dcbf702bbd5aa3d4e6958ce9e76ff85 +++ botan/parsing.cpp 0ec54baf44d58e0db2cdc5e6a188aa1ed7bf5200 @@ -1,6 +1,6 @@ /************************************************* * Parser Functions Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -16,7 +16,7 @@ { u32bit n = 0; - for(std::string::const_iterator j = number.begin(); j != number.end(); j++) + for(std::string::const_iterator j = number.begin(); j != number.end(); ++j) { const u32bit OVERFLOW_MARK = 0xFFFFFFFF / 10; @@ -70,12 +70,12 @@ elems.push_back(name.substr(0, name.find('('))); name = name.substr(name.find('(')); - for(std::string::const_iterator j = name.begin(); j != name.end(); j++) + for(std::string::const_iterator j = name.begin(); j != name.end(); ++j) { char c = *j; if(c == '(') - level++; + ++level; if(c == ')') { if(level == 1 && j == name.end() - 1) @@ -89,7 +89,7 @@ if(level == 0 || (level == 1 && j != name.end() - 1)) throw Invalid_Algorithm_Name(namex); - level--; + --level; } if(c == ',' && level == 1) @@ -119,7 +119,7 @@ if(str == "") return elems; std::string substr; - for(std::string::const_iterator j = str.begin(); j != str.end(); j++) + for(std::string::const_iterator j = str.begin(); j != str.end(); ++j) { if(*j == delim) { @@ -145,7 +145,7 @@ std::string substring; std::vector oid_elems; - for(std::string::const_iterator j = oid.begin(); j != oid.end(); j++) + for(std::string::const_iterator j = oid.begin(); j != oid.end(); ++j) { char c = *j; @@ -178,8 +178,8 @@ std::string::const_iterator p1 = name1.begin(); std::string::const_iterator p2 = name2.begin(); - while((p1 != name1.end()) && is_space(*p1)) p1++; - while((p2 != name2.end()) && is_space(*p2)) p2++; + while((p1 != name1.end()) && is_space(*p1)) ++p1; + while((p2 != name2.end()) && is_space(*p2)) ++p2; while(p1 != name1.end() && p2 != name2.end()) { @@ -188,8 +188,8 @@ if(!is_space(*p2)) return false; - while((p1 != name1.end()) && is_space(*p1)) p1++; - while((p2 != name2.end()) && is_space(*p2)) p2++; + while((p1 != name1.end()) && is_space(*p1)) ++p1; + while((p2 != name2.end()) && is_space(*p2)) ++p2; if(p1 == name1.end() && p2 == name2.end()) return true; @@ -197,12 +197,12 @@ if(to_lower(*p1) != to_lower(*p2)) return false; - p1++; - p2++; + ++p1; + ++p2; } - while((p1 != name1.end()) && is_space(*p1)) p1++; - while((p2 != name2.end()) && is_space(*p2)) p2++; + while((p1 != name1.end()) && is_space(*p1)) ++p1; + while((p2 != name2.end()) && is_space(*p2)) ++p2; if((p1 != name1.end()) || (p2 != name2.end())) return false; @@ -249,7 +249,7 @@ std::string iso2utf(const std::string& iso8859) { std::string utf8; - for(u32bit j = 0; j != iso8859.size(); j++) + for(u32bit j = 0; j != iso8859.size(); ++j) { const byte c = (byte)iso8859[j]; @@ -276,7 +276,7 @@ { std::vector sub_expr = split_on(expr, '+'); u32bit result = 0; - for(u32bit j = 0; j != sub_expr.size(); j++) + for(u32bit j = 0; j != sub_expr.size(); ++j) result += parse_expr(sub_expr[j]); return result; } @@ -284,7 +284,7 @@ { std::vector sub_expr = split_on(expr, '*'); u32bit result = 1; - for(u32bit j = 0; j != sub_expr.size(); j++) + for(u32bit j = 0; j != sub_expr.size(); ++j) result *= parse_expr(sub_expr[j]); return result; } ============================================================ --- botan/parsing.h cc614612daa8f7957ead652e9d7b6155d60e06e4 +++ botan/parsing.h f75201b87b93e3c759253685c584e989ce529711 @@ -1,6 +1,6 @@ /************************************************* * Parser Functions Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_PARSER_H__ ============================================================ --- botan/pbe.h 06e59820482660316ca05b7039f35b3705c5acf5 +++ botan/pbe.h f70f01ec9efa2119a6a28519697bc0d5da8167f0 @@ -1,6 +1,6 @@ /************************************************* * PBE Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_PBE_H__ ============================================================ --- botan/pbe_pkcs.h 3c1f0cfeb63a5ef197b4d25078183f124fec7fad +++ botan/pbe_pkcs.h 13c9b42c84107045259fe22f8723b2a7ec81da85 @@ -1,6 +1,6 @@ /************************************************* * PKCS PBE Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_PBE_PKCS_H__ ============================================================ --- botan/pbes1.cpp 649e6fcfe4fde90cb7423caaaa7303df9e8b169b +++ botan/pbes1.cpp 1d5afb55ee77c3cecac5c76f763c82315f82bf6a @@ -1,6 +1,6 @@ /************************************************* * PKCS #5 PBES1 Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -84,7 +84,7 @@ { iterations = 2048; salt.create(8); - Global_RNG::randomize(salt, salt.size(), Nonce); + Global_RNG::randomize(salt, salt.size()); } /************************************************* ============================================================ --- botan/pbes2.cpp 402a6ec148314cb96273dd54f43360b47a0b0d45 +++ botan/pbes2.cpp 6aa65fd5356d5f5bbb3f5d645d9e0cce53b1484f @@ -1,6 +1,6 @@ /************************************************* * PKCS #5 PBES2 Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -84,8 +84,8 @@ key_length = max_keylength_of(cipher_algo); salt.create(8); iv.create(block_size_of(cipher_algo)); - Global_RNG::randomize(salt, salt.size(), Nonce); - Global_RNG::randomize(iv, iv.size(), Nonce); + Global_RNG::randomize(salt, salt.size()); + Global_RNG::randomize(iv, iv.size()); } /************************************************* ============================================================ --- botan/pem.cpp fe377ccf9051816213ded97776eab82c4f7ebe15 +++ botan/pem.cpp eef9e1120e7547f53786198636a799358f419260 @@ -1,6 +1,6 @@ /************************************************* * PEM Encoding/Decoding Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -128,7 +128,7 @@ u32bit index = 0; - for(u32bit j = 0; j != got; j++) + for(u32bit j = 0; j != got; ++j) { if(search_buf[j] == PEM_HEADER[index]) index++; ============================================================ --- botan/pem.h be2e43f828cff05d5f0ae7b02ee81adf0f1cda8d +++ botan/pem.h fb888d3bc2fed16ec4745cd5179bef5cc1f13b23 @@ -1,6 +1,6 @@ /************************************************* * PEM Encoding/Decoding Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_PEM_H__ ============================================================ --- botan/pipe.cpp 774a4992b6b17495388d6087ada4cae49e2dc9b7 +++ botan/pipe.cpp 7c3a10cad87f8009fa0b163890566b82220bbfd9 @@ -1,6 +1,6 @@ /************************************************* * Pipe Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -41,7 +41,7 @@ Pipe::Pipe(Filter* filter_array[], u32bit count) { init(); - for(u32bit j = 0; j != count; j++) + for(u32bit j = 0; j != count; ++j) append(filter_array[j]); } @@ -84,7 +84,7 @@ { if(!to_kill || dynamic_cast(to_kill)) return; - for(u32bit j = 0; j != to_kill->total_ports(); j++) + for(u32bit j = 0; j != to_kill->total_ports(); ++j) destruct(to_kill->next[j]); delete to_kill; } @@ -181,7 +181,7 @@ *************************************************/ void Pipe::find_endpoints(Filter* f) { - for(u32bit j = 0; j != f->total_ports(); j++) + for(u32bit j = 0; j != f->total_ports(); ++j) if(f->next[j] && !dynamic_cast(f->next[j])) find_endpoints(f->next[j]); else @@ -198,7 +198,7 @@ void Pipe::clear_endpoints(Filter* f) { if(!f) return; - for(u32bit j = 0; j != f->total_ports(); j++) + for(u32bit j = 0; j != f->total_ports(); ++j) { if(f->next[j] && dynamic_cast(f->next[j])) f->next[j] = 0; @@ -217,7 +217,11 @@ return; if(dynamic_cast(filter)) throw Invalid_Argument("Pipe::append: SecureQueue cannot be used"); + if(filter->owned) + throw Invalid_Argument("Filters cannot be shared among multiple Pipes"); + filter->owned = true; + if(!pipe) pipe = filter; else pipe->attach(filter); } @@ -233,7 +237,11 @@ return; if(dynamic_cast(filter)) throw Invalid_Argument("Pipe::prepend: SecureQueue cannot be used"); + if(filter->owned) + throw Invalid_Argument("Filters cannot be shared among multiple Pipes"); + filter->owned = true; + if(pipe) filter->attach(pipe); pipe = filter; } ============================================================ --- botan/pipe.h 2504d23b4aab823fa55180a13725a6d9f56e893b +++ botan/pipe.h 22989c7933461dfe48987a1ed8c7c482e4c7771c @@ -1,6 +1,6 @@ /************************************************* * Pipe Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_PIPE_H__ ============================================================ --- botan/pipe_io.cpp b91a0b4c82f460a14549cbc89580dcaab1aadd47 +++ botan/pipe_io.cpp b834ab95d290b21877ea8a562403b8ca76c10a6f @@ -1,6 +1,6 @@ /************************************************* * Pipe I/O Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/pipe_rw.cpp b8b1c777dbee7ebf724531dc9195a7636e23b0e0 +++ botan/pipe_rw.cpp 98ddc7cd79353b886929f6706a8404bee55aa953 @@ -1,6 +1,6 @@ /************************************************* * Pipe Reading/Writing Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/pk_algs.cpp 4db1878384c2944381591a79e7d615f5d638d229 +++ botan/pk_algs.cpp 4eaf5dca76443211e7486ca651ae5521d7cb7181 @@ -1,6 +1,6 @@ /************************************************* * PK Key Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/pk_algs.h fb2336a4e5ecb6c99ff27495ac9a2a2bda8dd965 +++ botan/pk_algs.h a74b349952353849520a8ccd1547b22f4158917d @@ -1,6 +1,6 @@ /************************************************* * PK Key Factory Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_PK_KEY_FACTORY_H__ ============================================================ --- botan/pk_core.cpp d0e5257141362be13da44c2e83b5d5d90c8925cc +++ botan/pk_core.cpp 0389b1a4f1cd6c7c40ffb64d730529968ee58307 @@ -1,6 +1,6 @@ /************************************************* * PK Algorithm Core Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -20,7 +20,7 @@ const u32bit BLINDING_BITS = Config::get_u32bit("pk/blinder_size"); if(BLINDING_BITS == 0) return 0; - return random_integer(std::min(modulus_size - 1, BLINDING_BITS), Nonce); + return random_integer(std::min(modulus_size - 1, BLINDING_BITS)); } } ============================================================ --- botan/pk_core.h 10477efff2a9f24a8bf0119ca6d341a190563df3 +++ botan/pk_core.h bcdfc58a47396cdd6023fe343683ed34d6cbc42a @@ -1,13 +1,13 @@ /************************************************* * PK Algorithm Core Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_PK_CORE_H__ #define BOTAN_PK_CORE_H__ #include -#include +#include #include #include ============================================================ --- botan/pk_filts.cpp a854cd0ea434d4376b575936345ef2a049d5b047 +++ botan/pk_filts.cpp f0b3034376d079b3c0e142fdf137b747eb59c493 @@ -1,6 +1,6 @@ /************************************************* * PK Filters Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/pk_filts.h 0d1647a1bdf4cad2f490ddd0e4ebce0784955bcc +++ botan/pk_filts.h af8f30ddc7323c166cd55b0440ed913fd7ecb014 @@ -1,6 +1,6 @@ /************************************************* * PK Filters Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_PK_FILTERS_H__ ============================================================ --- botan/pk_keys.cpp 10fcbc235a7fd98607ef6e931b97be3931fb64c9 +++ botan/pk_keys.cpp e96e015886270680f7e9fe6e72dec0f3b45eb717 @@ -1,6 +1,6 @@ /************************************************* * PK Key Types Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/pk_keys.h 708654f66730aef50e3ebbeadeed4f51befec530 +++ botan/pk_keys.h 4c027055ee9f940af7a6a19bd622f8ebb7f49db1 @@ -1,6 +1,6 @@ /************************************************* * PK Key Types Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_PK_KEYS_H__ ============================================================ --- botan/pk_ops.h 3528538ab9d79c80e3f1ca31883cbb0a470451a2 +++ botan/pk_ops.h 70200faf214f2f97b8b9c119ac37938532dd2905 @@ -1,13 +1,13 @@ /************************************************* * Public Key Operations Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_PK_OPS_H__ #define BOTAN_PK_OPS_H__ #include -#include +#include namespace Botan { ============================================================ --- botan/pk_util.cpp 07159fe81e167b59fcffd638f755d4672c8c42fa +++ botan/pk_util.cpp 63673b6371f30e1bc06a7ff8e06ab6b9d998bf8b @@ -1,6 +1,6 @@ /************************************************* * PK Utility Classes Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/pk_util.h f6402de5949c76a9788e261361c7317fd3b18f5b +++ botan/pk_util.h e770acbba30020bcf8b39caaa1c0d42f49710023 @@ -1,6 +1,6 @@ /************************************************* * PK Utility Classes Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_PUBKEY_UTIL_H__ ============================================================ --- botan/pkcs10.cpp 377921951d6c212d506ffd85875229b831ae6769 +++ botan/pkcs10.cpp ad6427f721304d7504519f0aa9f7c7e1faf684b2 @@ -1,6 +1,6 @@ /************************************************* * PKCS #10 Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -77,7 +77,7 @@ cert_req_info.verify_end(); std::vector emails = dn.get_attribute("PKCS9.EmailAddress"); - for(u32bit j = 0; j != emails.size(); j++) + for(u32bit j = 0; j != emails.size(); ++j) subject_alt.add_attribute("RFC822", emails[j]); X509_Code sig_check = X509_Store::check_sig(*this, subject_public_key()); ============================================================ --- botan/pkcs10.h 7fdfce431e83e7cf380f877e3b7c726f3d698c1f +++ botan/pkcs10.h d1509c9fa08d51959265aeb029078e937857d6fe @@ -1,6 +1,6 @@ /************************************************* * PKCS #10 Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_PKCS10_H__ ============================================================ --- botan/pkcs5.cpp cf89d6b74fd2e397176e49e4aa0de7b644ca642b +++ botan/pkcs5.cpp 191a70d25a288701ed5be7d8898129dfe484e348 @@ -1,6 +1,6 @@ /************************************************* * PKCS #5 Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -30,7 +30,7 @@ hash->update(salt, salt_size); SecureVector key = hash->final(); - for(u32bit j = 1; j != iterations; j++) + for(u32bit j = 1; j != iterations; ++j) { hash->update(key); hash->final(key); @@ -83,12 +83,12 @@ SecureVector U(hmac.OUTPUT_LENGTH); hmac.update(salt, salt_size); - for(u32bit j = 0; j != 4; j++) + for(u32bit j = 0; j != 4; ++j) hmac.update(get_byte(j, counter)); hmac.final(U); xor_buf(T, U, T_size); - for(u32bit j = 1; j != iterations; j++) + for(u32bit j = 1; j != iterations; ++j) { hmac.update(U); hmac.final(U); ============================================================ --- botan/pkcs5.h 660436fb11b2f632b3dba051539cf93d023ffaa6 +++ botan/pkcs5.h 8f8553ead419624b1aeb3041c2d84e2ec9cc4a96 @@ -1,6 +1,6 @@ /************************************************* * PKCS #5 Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_PKCS5_H__ ============================================================ --- botan/policy.cpp f695e97b7eef3d49c960d3044b65b53a049e2364 +++ botan/policy.cpp 6d7bcb9a5926060492333a307fcc21a0294821bb @@ -1,12 +1,9 @@ /************************************************* * Default Policy Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ -#include -#include -#include -#include +#include namespace Botan { @@ -15,217 +12,360 @@ /************************************************* * OID loading helper function * *************************************************/ -void add_oid(const std::string& oid_str, const std::string& name) +void add_oid(Library_State* state, + const std::string& oid_str, + const std::string& name) { - OIDS::add_oid(OID(oid_str), name); + if(!state->option_set("oid2str", oid_str)) + state->set_option("oid2str", oid_str, name); + if(!state->option_set("str2oid", name)) + state->set_option("str2oid", name, oid_str); } -} - /************************************************* * Load all of the default OIDs * *************************************************/ -void add_default_oids() +void set_default_oids(Library_State* state) { - add_oid("1.2.840.113549.1.1.1", "RSA"); - add_oid("2.5.8.1.1", "RSA"); - add_oid("1.2.840.10040.4.1", "DSA"); - add_oid("1.2.840.10046.2.1", "DH"); - add_oid("1.3.6.1.4.1.3029.1.2.1", "ELG"); + add_oid(state, "1.2.840.113549.1.1.1", "RSA"); + add_oid(state, "2.5.8.1.1", "RSA"); + add_oid(state, "1.2.840.10040.4.1", "DSA"); + add_oid(state, "1.2.840.10046.2.1", "DH"); + add_oid(state, "1.3.6.1.4.1.3029.1.2.1", "ELG"); - add_oid("1.3.14.3.2.7", "DES/CBC"); - add_oid("1.2.840.113549.3.7", "TripleDES/CBC"); - add_oid("1.2.840.113549.3.2", "RC2/CBC"); - add_oid("1.2.840.113533.7.66.10", "CAST-128/CBC"); - add_oid("2.16.840.1.101.3.4.1.2", "AES-128/CBC"); - add_oid("2.16.840.1.101.3.4.1.22", "AES-192/CBC"); - add_oid("2.16.840.1.101.3.4.1.42", "AES-256/CBC"); + add_oid(state, "1.3.14.3.2.7", "DES/CBC"); + add_oid(state, "1.2.840.113549.3.7", "TripleDES/CBC"); + add_oid(state, "1.2.840.113549.3.2", "RC2/CBC"); + add_oid(state, "1.2.840.113533.7.66.10", "CAST-128/CBC"); + add_oid(state, "2.16.840.1.101.3.4.1.2", "AES-128/CBC"); + add_oid(state, "2.16.840.1.101.3.4.1.22", "AES-192/CBC"); + add_oid(state, "2.16.840.1.101.3.4.1.42", "AES-256/CBC"); - add_oid("1.2.840.113549.2.5", "MD5"); - add_oid("1.3.14.3.2.26", "SHA-160"); - add_oid("1.3.6.1.4.1.11591.12.2", "Tiger(24,3)"); + add_oid(state, "1.2.840.113549.2.5", "MD5"); + add_oid(state, "1.3.14.3.2.26", "SHA-160"); + add_oid(state, "1.3.6.1.4.1.11591.12.2", "Tiger(24,3)"); - add_oid("1.2.840.113549.1.9.16.3.6", "KeyWrap.TripleDES"); - add_oid("1.2.840.113549.1.9.16.3.7", "KeyWrap.RC2"); - add_oid("1.2.840.113533.7.66.15", "KeyWrap.CAST-128"); - add_oid("2.16.840.1.101.3.4.1.5", "KeyWrap.AES-128"); - add_oid("2.16.840.1.101.3.4.1.25", "KeyWrap.AES-192"); - add_oid("2.16.840.1.101.3.4.1.45", "KeyWrap.AES-256"); + add_oid(state, "1.2.840.113549.1.9.16.3.6", "KeyWrap.TripleDES"); + add_oid(state, "1.2.840.113549.1.9.16.3.7", "KeyWrap.RC2"); + add_oid(state, "1.2.840.113533.7.66.15", "KeyWrap.CAST-128"); + add_oid(state, "2.16.840.1.101.3.4.1.5", "KeyWrap.AES-128"); + add_oid(state, "2.16.840.1.101.3.4.1.25", "KeyWrap.AES-192"); + add_oid(state, "2.16.840.1.101.3.4.1.45", "KeyWrap.AES-256"); - add_oid("1.2.840.113549.1.9.16.3.8", "Compression.Zlib"); + add_oid(state, "1.2.840.113549.1.9.16.3.8", "Compression.Zlib"); - add_oid("1.2.840.113549.1.1.1", "RSA/EME-PKCS1-v1_5"); - add_oid("1.2.840.113549.1.1.2", "RSA/EMSA3(MD2)"); - add_oid("1.2.840.113549.1.1.4", "RSA/EMSA3(MD5)"); - add_oid("1.2.840.113549.1.1.5", "RSA/EMSA3(SHA-160)"); - add_oid("1.2.840.113549.1.1.11", "RSA/EMSA3(SHA-256)"); - add_oid("1.2.840.113549.1.1.12", "RSA/EMSA3(SHA-384)"); - add_oid("1.2.840.113549.1.1.13", "RSA/EMSA3(SHA-512)"); - add_oid("1.3.36.3.3.1.2", "RSA/EMSA3(RIPEMD-160)"); - add_oid("1.2.840.10040.4.3", "DSA/EMSA1(SHA-160)"); + add_oid(state, "1.2.840.113549.1.1.1", "RSA/EME-PKCS1-v1_5"); + add_oid(state, "1.2.840.113549.1.1.2", "RSA/EMSA3(MD2)"); + add_oid(state, "1.2.840.113549.1.1.4", "RSA/EMSA3(MD5)"); + add_oid(state, "1.2.840.113549.1.1.5", "RSA/EMSA3(SHA-160)"); + add_oid(state, "1.2.840.113549.1.1.11", "RSA/EMSA3(SHA-256)"); + add_oid(state, "1.2.840.113549.1.1.12", "RSA/EMSA3(SHA-384)"); + add_oid(state, "1.2.840.113549.1.1.13", "RSA/EMSA3(SHA-512)"); + add_oid(state, "1.3.36.3.3.1.2", "RSA/EMSA3(RIPEMD-160)"); + add_oid(state, "1.2.840.10040.4.3", "DSA/EMSA1(SHA-160)"); - add_oid("2.5.4.3", "X520.CommonName"); - add_oid("2.5.4.4", "X520.Surname"); - add_oid("2.5.4.5", "X520.SerialNumber"); - add_oid("2.5.4.6", "X520.Country"); - add_oid("2.5.4.7", "X520.Locality"); - add_oid("2.5.4.8", "X520.State"); - add_oid("2.5.4.10", "X520.Organization"); - add_oid("2.5.4.11", "X520.OrganizationalUnit"); - add_oid("2.5.4.12", "X520.Title"); - add_oid("2.5.4.42", "X520.GivenName"); - add_oid("2.5.4.43", "X520.Initials"); - add_oid("2.5.4.44", "X520.GenerationalQualifier"); - add_oid("2.5.4.46", "X520.DNQualifier"); - add_oid("2.5.4.65", "X520.Pseudonym"); + add_oid(state, "2.5.4.3", "X520.CommonName"); + add_oid(state, "2.5.4.4", "X520.Surname"); + add_oid(state, "2.5.4.5", "X520.SerialNumber"); + add_oid(state, "2.5.4.6", "X520.Country"); + add_oid(state, "2.5.4.7", "X520.Locality"); + add_oid(state, "2.5.4.8", "X520.State"); + add_oid(state, "2.5.4.10", "X520.Organization"); + add_oid(state, "2.5.4.11", "X520.OrganizationalUnit"); + add_oid(state, "2.5.4.12", "X520.Title"); + add_oid(state, "2.5.4.42", "X520.GivenName"); + add_oid(state, "2.5.4.43", "X520.Initials"); + add_oid(state, "2.5.4.44", "X520.GenerationalQualifier"); + add_oid(state, "2.5.4.46", "X520.DNQualifier"); + add_oid(state, "2.5.4.65", "X520.Pseudonym"); - add_oid("1.2.840.113549.1.5.12", "PKCS5.PBKDF2"); - add_oid("1.2.840.113549.1.5.1", "PBE-PKCS5v15(MD2,DES/CBC)"); - add_oid("1.2.840.113549.1.5.4", "PBE-PKCS5v15(MD2,RC2/CBC)"); - add_oid("1.2.840.113549.1.5.3", "PBE-PKCS5v15(MD5,DES/CBC)"); - add_oid("1.2.840.113549.1.5.6", "PBE-PKCS5v15(MD5,RC2/CBC)"); - add_oid("1.2.840.113549.1.5.10", "PBE-PKCS5v15(SHA-160,DES/CBC)"); - add_oid("1.2.840.113549.1.5.11", "PBE-PKCS5v15(SHA-160,RC2/CBC)"); - add_oid("1.2.840.113549.1.5.13", "PBE-PKCS5v20"); + add_oid(state, "1.2.840.113549.1.5.12", "PKCS5.PBKDF2"); + add_oid(state, "1.2.840.113549.1.5.1", "PBE-PKCS5v15(MD2,DES/CBC)"); + add_oid(state, "1.2.840.113549.1.5.4", "PBE-PKCS5v15(MD2,RC2/CBC)"); + add_oid(state, "1.2.840.113549.1.5.3", "PBE-PKCS5v15(MD5,DES/CBC)"); + add_oid(state, "1.2.840.113549.1.5.6", "PBE-PKCS5v15(MD5,RC2/CBC)"); + add_oid(state, "1.2.840.113549.1.5.10", "PBE-PKCS5v15(SHA-160,DES/CBC)"); + add_oid(state, "1.2.840.113549.1.5.11", "PBE-PKCS5v15(SHA-160,RC2/CBC)"); + add_oid(state, "1.2.840.113549.1.5.13", "PBE-PKCS5v20"); - add_oid("1.2.840.113549.1.9.1", "PKCS9.EmailAddress"); - add_oid("1.2.840.113549.1.9.2", "PKCS9.UnstructuredName"); - add_oid("1.2.840.113549.1.9.3", "PKCS9.ContentType"); - add_oid("1.2.840.113549.1.9.4", "PKCS9.MessageDigest"); - add_oid("1.2.840.113549.1.9.7", "PKCS9.ChallengePassword"); - add_oid("1.2.840.113549.1.9.14", "PKCS9.ExtensionRequest"); + add_oid(state, "1.2.840.113549.1.9.1", "PKCS9.EmailAddress"); + add_oid(state, "1.2.840.113549.1.9.2", "PKCS9.UnstructuredName"); + add_oid(state, "1.2.840.113549.1.9.3", "PKCS9.ContentType"); + add_oid(state, "1.2.840.113549.1.9.4", "PKCS9.MessageDigest"); + add_oid(state, "1.2.840.113549.1.9.7", "PKCS9.ChallengePassword"); + add_oid(state, "1.2.840.113549.1.9.14", "PKCS9.ExtensionRequest"); - add_oid("1.2.840.113549.1.7.1", "CMS.DataContent"); - add_oid("1.2.840.113549.1.7.2", "CMS.SignedData"); - add_oid("1.2.840.113549.1.7.3", "CMS.EnvelopedData"); - add_oid("1.2.840.113549.1.7.5", "CMS.DigestedData"); - add_oid("1.2.840.113549.1.7.6", "CMS.EncryptedData"); - add_oid("1.2.840.113549.1.9.16.1.2", "CMS.AuthenticatedData"); - add_oid("1.2.840.113549.1.9.16.1.9", "CMS.CompressedData"); + add_oid(state, "1.2.840.113549.1.7.1", "CMS.DataContent"); + add_oid(state, "1.2.840.113549.1.7.2", "CMS.SignedData"); + add_oid(state, "1.2.840.113549.1.7.3", "CMS.EnvelopedData"); + add_oid(state, "1.2.840.113549.1.7.5", "CMS.DigestedData"); + add_oid(state, "1.2.840.113549.1.7.6", "CMS.EncryptedData"); + add_oid(state, "1.2.840.113549.1.9.16.1.2", "CMS.AuthenticatedData"); + add_oid(state, "1.2.840.113549.1.9.16.1.9", "CMS.CompressedData"); - add_oid("2.5.29.14", "X509v3.SubjectKeyIdentifier"); - add_oid("2.5.29.15", "X509v3.KeyUsage"); - add_oid("2.5.29.17", "X509v3.SubjectAlternativeName"); - add_oid("2.5.29.18", "X509v3.IssuerAlternativeName"); - add_oid("2.5.29.19", "X509v3.BasicConstraints"); - add_oid("2.5.29.20", "X509v3.CRLNumber"); - add_oid("2.5.29.21", "X509v3.ReasonCode"); - add_oid("2.5.29.23", "X509v3.HoldInstructionCode"); - add_oid("2.5.29.24", "X509v3.InvalidityDate"); - add_oid("2.5.29.32", "X509v3.CertificatePolicies"); - add_oid("2.5.29.35", "X509v3.AuthorityKeyIdentifier"); - add_oid("2.5.29.36", "X509v3.PolicyConstraints"); - add_oid("2.5.29.37", "X509v3.ExtendedKeyUsage"); + add_oid(state, "2.5.29.14", "X509v3.SubjectKeyIdentifier"); + add_oid(state, "2.5.29.15", "X509v3.KeyUsage"); + add_oid(state, "2.5.29.17", "X509v3.SubjectAlternativeName"); + add_oid(state, "2.5.29.18", "X509v3.IssuerAlternativeName"); + add_oid(state, "2.5.29.19", "X509v3.BasicConstraints"); + add_oid(state, "2.5.29.20", "X509v3.CRLNumber"); + add_oid(state, "2.5.29.21", "X509v3.ReasonCode"); + add_oid(state, "2.5.29.23", "X509v3.HoldInstructionCode"); + add_oid(state, "2.5.29.24", "X509v3.InvalidityDate"); + add_oid(state, "2.5.29.32", "X509v3.CertificatePolicies"); + add_oid(state, "2.5.29.35", "X509v3.AuthorityKeyIdentifier"); + add_oid(state, "2.5.29.36", "X509v3.PolicyConstraints"); + add_oid(state, "2.5.29.37", "X509v3.ExtendedKeyUsage"); - add_oid("2.5.29.32.0", "X509v3.AnyPolicy"); + add_oid(state, "2.5.29.32.0", "X509v3.AnyPolicy"); - add_oid("1.3.6.1.5.5.7.3.1", "PKIX.ServerAuth"); - add_oid("1.3.6.1.5.5.7.3.2", "PKIX.ClientAuth"); - add_oid("1.3.6.1.5.5.7.3.3", "PKIX.CodeSigning"); - add_oid("1.3.6.1.5.5.7.3.4", "PKIX.EmailProtection"); - add_oid("1.3.6.1.5.5.7.3.5", "PKIX.IPsecEndSystem"); - add_oid("1.3.6.1.5.5.7.3.6", "PKIX.IPsecTunnel"); - add_oid("1.3.6.1.5.5.7.3.7", "PKIX.IPsecUser"); - add_oid("1.3.6.1.5.5.7.3.8", "PKIX.TimeStamping"); - add_oid("1.3.6.1.5.5.7.3.9", "PKIX.OCSPSigning"); + add_oid(state, "1.3.6.1.5.5.7.3.1", "PKIX.ServerAuth"); + add_oid(state, "1.3.6.1.5.5.7.3.2", "PKIX.ClientAuth"); + add_oid(state, "1.3.6.1.5.5.7.3.3", "PKIX.CodeSigning"); + add_oid(state, "1.3.6.1.5.5.7.3.4", "PKIX.EmailProtection"); + add_oid(state, "1.3.6.1.5.5.7.3.5", "PKIX.IPsecEndSystem"); + add_oid(state, "1.3.6.1.5.5.7.3.6", "PKIX.IPsecTunnel"); + add_oid(state, "1.3.6.1.5.5.7.3.7", "PKIX.IPsecUser"); + add_oid(state, "1.3.6.1.5.5.7.3.8", "PKIX.TimeStamping"); + add_oid(state, "1.3.6.1.5.5.7.3.9", "PKIX.OCSPSigning"); - add_oid("1.3.6.1.5.5.7.8.5", "PKIX.XMPPAddr"); + add_oid(state, "1.3.6.1.5.5.7.8.5", "PKIX.XMPPAddr"); } /************************************************* -* Load the list of default aliases * +* Set the default algorithm aliases * *************************************************/ -void add_default_aliases() +void set_default_aliases(Library_State* state) { - add_alias("OpenPGP.Cipher.1", "IDEA"); - add_alias("OpenPGP.Cipher.2", "TripleDES"); - add_alias("OpenPGP.Cipher.3", "CAST-128"); - add_alias("OpenPGP.Cipher.4", "Blowfish"); - add_alias("OpenPGP.Cipher.5", "SAFER-SK(13)"); - add_alias("OpenPGP.Cipher.7", "AES-128"); - add_alias("OpenPGP.Cipher.8", "AES-192"); - add_alias("OpenPGP.Cipher.9", "AES-256"); - add_alias("OpenPGP.Cipher.10", "Twofish"); + state->set_option("alias", "OpenPGP.Cipher.1", "IDEA"); + state->set_option("alias", "OpenPGP.Cipher.2", "TripleDES"); + state->set_option("alias", "OpenPGP.Cipher.3", "CAST-128"); + state->set_option("alias", "OpenPGP.Cipher.4", "Blowfish"); + state->set_option("alias", "OpenPGP.Cipher.5", "SAFER-SK(13)"); + state->set_option("alias", "OpenPGP.Cipher.7", "AES-128"); + state->set_option("alias", "OpenPGP.Cipher.8", "AES-192"); + state->set_option("alias", "OpenPGP.Cipher.9", "AES-256"); + state->set_option("alias", "OpenPGP.Cipher.10", "Twofish"); - add_alias("OpenPGP.Digest.1", "MD5"); - add_alias("OpenPGP.Digest.2", "SHA-1"); - add_alias("OpenPGP.Digest.3", "RIPEMD-160"); - add_alias("OpenPGP.Digest.5", "MD2"); - add_alias("OpenPGP.Digest.6", "Tiger(24,3)"); - add_alias("OpenPGP.Digest.7", "HAVAL(20,5)"); - add_alias("OpenPGP.Digest.8", "SHA-256"); + state->set_option("alias", "OpenPGP.Digest.1", "MD5"); + state->set_option("alias", "OpenPGP.Digest.2", "SHA-1"); + state->set_option("alias", "OpenPGP.Digest.3", "RIPEMD-160"); + state->set_option("alias", "OpenPGP.Digest.5", "MD2"); + state->set_option("alias", "OpenPGP.Digest.6", "Tiger(24,3)"); + state->set_option("alias", "OpenPGP.Digest.7", "HAVAL(20,5)"); + state->set_option("alias", "OpenPGP.Digest.8", "SHA-256"); - add_alias("TLS.Digest.0", "Parallel(MD5,SHA-160)"); + state->set_option("alias", "TLS.Digest.0", "Parallel(MD5,SHA-160)"); - add_alias("EME-PKCS1-v1_5", "PKCS1v15"); - add_alias("OAEP-MGF1", "EME1"); - add_alias("EME-OAEP", "EME1"); - add_alias("X9.31", "EMSA2"); - add_alias("EMSA-PKCS1-v1_5", "EMSA3"); - add_alias("PSS-MGF1", "EMSA4"); - add_alias("EMSA-PSS", "EMSA4"); + state->set_option("alias", "EME-PKCS1-v1_5", "PKCS1v15"); + state->set_option("alias", "OAEP-MGF1", "EME1"); + state->set_option("alias", "EME-OAEP", "EME1"); + state->set_option("alias", "X9.31", "EMSA2"); + state->set_option("alias", "EMSA-PKCS1-v1_5", "EMSA3"); + state->set_option("alias", "PSS-MGF1", "EMSA4"); + state->set_option("alias", "EMSA-PSS", "EMSA4"); - add_alias("Rijndael", "AES"); - add_alias("3DES", "TripleDES"); - add_alias("DES-EDE", "TripleDES"); - add_alias("CAST5", "CAST-128"); - add_alias("SHA1", "SHA-160"); - add_alias("SHA-1", "SHA-160"); - add_alias("SEAL", "SEAL-3.0-BE"); - add_alias("MARK-4", "ARC4(256)"); - add_alias("OMAC", "CMAC"); + state->set_option("alias", "Rijndael", "AES"); + state->set_option("alias", "3DES", "TripleDES"); + state->set_option("alias", "DES-EDE", "TripleDES"); + state->set_option("alias", "CAST5", "CAST-128"); + state->set_option("alias", "SHA1", "SHA-160"); + state->set_option("alias", "SHA-1", "SHA-160"); + state->set_option("alias", "SEAL", "SEAL-3.0-BE"); + state->set_option("alias", "MARK-4", "ARC4(256)"); + state->set_option("alias", "OMAC", "CMAC"); } -namespace Init { +/************************************************* +* Set the default configuration toggles * +*************************************************/ +void set_default_config(Library_State* state) + { + state->set_option("conf", "base/memory_chunk", "64*1024"); + state->set_option("conf", "base/pkcs8_tries", "3"); + state->set_option("conf", "base/default_pbe", + "PBE-PKCS5v20(SHA-1,TripleDES/CBC)"); + state->set_option("conf", "base/default_allocator", "malloc"); + state->set_option("conf", "pk/blinder_size", "64"); + state->set_option("conf", "pk/test/public", "basic"); + state->set_option("conf", "pk/test/private", "basic"); + state->set_option("conf", "pk/test/private_gen", "all"); + + state->set_option("conf", "pem/search", "4*1024"); + state->set_option("conf", "pem/forgive", "8"); + state->set_option("conf", "pem/width", "64"); + + state->set_option("conf", "rng/min_entropy", "256", false); + state->set_option("conf", "rng/ms_capi_prov_type", "INTEL_SEC:RSA_FULL"); + state->set_option("conf", "rng/unix_path", "/usr/ucb:/usr/etc:/etc"); + state->set_option("conf", "rng/es_files", "/dev/urandom:/dev/random"); + state->set_option("conf", "rng/egd_path", + "/var/run/egd-pool:/dev/egd-pool"); + + state->set_option("conf", "x509/validity_slack", "24h"); + state->set_option("conf", "x509/v1_assume_ca", "false"); + state->set_option("conf", "x509/cache_verify_results", "30m"); + + state->set_option("conf", "x509/ca/allow_ca", "false"); + state->set_option("conf", "x509/ca/basic_constraints", "always"); + state->set_option("conf", "x509/ca/default_expire", "1y"); + state->set_option("conf", "x509/ca/signing_offset", "30s"); + state->set_option("conf", "x509/ca/rsa_hash", "SHA-1"); + state->set_option("conf", "x509/ca/str_type", "latin1"); + + state->set_option("conf", "x509/crl/unknown_critical", "ignore"); + state->set_option("conf", "x509/crl/next_update", "7d"); + + state->set_option("conf", "x509/exts/basic_constraints", "critical"); + 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/key_usage", "critical"); + state->set_option("conf", "x509/exts/extended_key_usage", "yes"); + state->set_option("conf", "x509/exts/crl_number", "yes"); + } + /************************************************* -* Set the default options * +* Set the built-in discrete log groups * *************************************************/ -void set_default_options() +void set_default_dl_groups(Library_State* state) { - Config::set("base/memory_chunk", "32*1024"); - Config::set("base/default_pbe", "PBE-PKCS5v20(SHA-1,TripleDES/CBC)"); - Config::set("base/pkcs8_tries", "3"); + state->set_option("dl", "modp/ietf/768", + "-----BEGIN X942 DH PARAMETERS-----" + "MIHIAmEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxObIlFK" + "CHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjo2IP//" + "////////AgECAmB//////////+SH7VEQtGEaYmMxRcBuDmiUgScERTPmOgEF31Md" + "ic2RKKUEPMcaAm73yozZ5p0hjZgVhTb5L4obp/Catrao4SLyQtq7MS8/Y3omIXTT" + "HRsQf/////////8=" + "-----END X942 DH PARAMETERS-----"); - Config::set("pk/blinder_size", "64"); - Config::set("pk/test/public", "basic"); - Config::set("pk/test/private", "basic"); - Config::set("pk/test/private_gen", "all"); + state->set_option("dl", "modp/ietf/1024", + "-----BEGIN X942 DH PARAMETERS-----" + "MIIBCgKBgQD//////////8kP2qIhaMI0xMZii4DcHNEpAk4IimfMdAILvqY7E5si" + "UUoIeY40BN3vlRmzzTpDGzArCm3yXxQ3T+E1bW1RwkXkhbV2Yl5+xvRMQummN+1r" + "C/9ctvQGt+3uOGv7Womfpa6fJBF8Sx/mSShmUezmU4H//////////wIBAgKBgH//" + "////////5IftURC0YRpiYzFFwG4OaJSBJwRFM+Y6AQXfUx2JzZEopQQ8xxoCbvfK" + "jNnmnSGNmBWFNvkvihun8Jq2tqjhIvJC2rsxLz9jeiYhdNMb9rWF/65begNb9vcc" + "Nf2tRM/S10+SCL4lj/MklDMo9nMpwP//////////" + "-----END X942 DH PARAMETERS-----"); - Config::set("pem/search", "4*1024"); - Config::set("pem/forgive", "8"); - Config::set("pem/width", "64"); + state->set_option("dl", "modp/ietf/1536", + "-----BEGIN X942 DH PARAMETERS-----" + "MIIBigKBwQD//////////8kP2qIhaMI0xMZii4DcHNEpAk4IimfMdAILvqY7E5si" + "UUoIeY40BN3vlRmzzTpDGzArCm3yXxQ3T+E1bW1RwkXkhbV2Yl5+xvRMQummN+1r" + "C/9ctvQGt+3uOGv7Womfpa6fJBF8Sx/mSShmUezkWz3CAHy4oWO/BZjaSDYcVdOa" + "aRY/qP0kz1+DZV0j3KOtlhxi81YghVK7ntUpB3CWlm1nDDVOSryYBPF0bAjKI3Mn" + "//////////8CAQICgcB//////////+SH7VEQtGEaYmMxRcBuDmiUgScERTPmOgEF" + "31Mdic2RKKUEPMcaAm73yozZ5p0hjZgVhTb5L4obp/Catrao4SLyQtq7MS8/Y3om" + "IXTTG/a1hf+uW3oDW/b3HDX9rUTP0tdPkgi+JY/zJJQzKPZyLZ7hAD5cULHfgsxt" + "JBsOKunNNIsf1H6SZ6/Bsq6R7lHWyw4xeasQQqldz2qUg7hLSzazhhqnJV5MAni6" + "NgRlEbmT//////////8=" + "-----END X942 DH PARAMETERS-----"); - Config::set("rng/min_entropy", "384", false); - Config::set("rng/es_files", "/dev/urandom:/dev/random"); - Config::set("rng/egd_path", "/var/run/egd-pool:/dev/egd-pool"); - Config::set("rng/ms_capi_prov_type", "INTEL_SEC:RSA_FULL"); - Config::set("rng/unix_path", "/usr/ucb:/usr/etc:/etc"); + state->set_option("dl", "modp/ietf/2048", + "-----BEGIN X942 DH PARAMETERS-----" + "MIICDAKCAQEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxOb" + "IlFKCHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjft" + "awv/XLb0Brft7jhr+1qJn6WunyQRfEsf5kkoZlHs5Fs9wgB8uKFjvwWY2kg2HFXT" + "mmkWP6j9JM9fg2VdI9yjrZYcYvNWIIVSu57VKQdwlpZtZww1Tkq8mATxdGwIyhgh" + "fDKQXkYuNs474553LBgOhgObJ4Oi7Aeij7XFXfBvTFLJ3ivL9pVYFxg5lUl86pVq" + "5RXSJhiY+gUQFXKOWoqsqmj//////////wIBAgKCAQB//////////+SH7VEQtGEa" + "YmMxRcBuDmiUgScERTPmOgEF31Mdic2RKKUEPMcaAm73yozZ5p0hjZgVhTb5L4ob" + "p/Catrao4SLyQtq7MS8/Y3omIXTTG/a1hf+uW3oDW/b3HDX9rUTP0tdPkgi+JY/z" + "JJQzKPZyLZ7hAD5cULHfgsxtJBsOKunNNIsf1H6SZ6/Bsq6R7lHWyw4xeasQQqld" + "z2qUg7hLSzazhhqnJV5MAni6NgRlDBC+GUgvIxcbZx3xzzuWDAdDAc2TwdF2A9FH" + "2uKu+DemKWTvFeX7SqwLjBzKpL51SrVyiukTDEx9AogKuUctRVZVNH//////////" + "-----END X942 DH PARAMETERS-----"); - Config::set("x509/validity_slack", "24h"); - Config::set("x509/v1_assume_ca", "false"); - Config::set("x509/cache_verify_results", "30m"); + state->set_option("dl", "modp/ietf/3072", + "-----BEGIN X942 DH PARAMETERS-----" + "MIIDDAKCAYEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxOb" + "IlFKCHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjft" + "awv/XLb0Brft7jhr+1qJn6WunyQRfEsf5kkoZlHs5Fs9wgB8uKFjvwWY2kg2HFXT" + "mmkWP6j9JM9fg2VdI9yjrZYcYvNWIIVSu57VKQdwlpZtZww1Tkq8mATxdGwIyhgh" + "fDKQXkYuNs474553LBgOhgObJ4Oi7Aeij7XFXfBvTFLJ3ivL9pVYFxg5lUl86pVq" + "5RXSJhiY+gUQFXKOWoqqxC2tMxcNBFB6M6hVIavfHLpk7PuFBFjb7wqK6nFXXQYM" + "fbOXD4Wm4eTHq/WujNsJM9cejJTgSiVhnc7j0iYa0u5r8S/6BtmKCGTYdgJzPshq" + "ZFIfKxgXeyAMu+EXV3phXWx3CYjAutlG4gjiT6B05asxQ9tb/OD9EI5LgtEgqTrS" + "yv//////////AgECAoIBgH//////////5IftURC0YRpiYzFFwG4OaJSBJwRFM+Y6" + "AQXfUx2JzZEopQQ8xxoCbvfKjNnmnSGNmBWFNvkvihun8Jq2tqjhIvJC2rsxLz9j" + "eiYhdNMb9rWF/65begNb9vccNf2tRM/S10+SCL4lj/MklDMo9nItnuEAPlxQsd+C" + "zG0kGw4q6c00ix/UfpJnr8GyrpHuUdbLDjF5qxBCqV3PapSDuEtLNrOGGqclXkwC" + "eLo2BGUMEL4ZSC8jFxtnHfHPO5YMB0MBzZPB0XYD0Ufa4q74N6YpZO8V5ftKrAuM" + "HMqkvnVKtXKK6RMMTH0CiAq5Ry1FVWIW1pmLhoIoPRnUKpDV745dMnZ9woIsbfeF" + "RXU4q66DBj7Zy4fC03DyY9X610ZthJnrj0ZKcCUSsM7ncekTDWl3NfiX/QNsxQQy" + "bDsBOZ9kNTIpD5WMC72QBl3wi6u9MK62O4TEYF1so3EEcSfQOnLVmKHtrf5wfohH" + "JcFokFSdaWV//////////w==" + "-----END X942 DH PARAMETERS-----"); - Config::set("x509/ca/allow_ca", "false"); - Config::set("x509/ca/basic_constraints", "always"); - Config::set("x509/ca/default_expire", "1y"); - Config::set("x509/ca/signing_offset", "30s"); - Config::set("x509/ca/rsa_hash", "SHA-1"); - Config::set("x509/ca/str_type", "latin1"); + state->set_option("dl", "modp/ietf/4096", + "-----BEGIN X942 DH PARAMETERS-----" + "MIIEDAKCAgEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxOb" + "IlFKCHmONATd75UZs806QxswKwpt8l8UN0/hNW1tUcJF5IW1dmJefsb0TELppjft" + "awv/XLb0Brft7jhr+1qJn6WunyQRfEsf5kkoZlHs5Fs9wgB8uKFjvwWY2kg2HFXT" + "mmkWP6j9JM9fg2VdI9yjrZYcYvNWIIVSu57VKQdwlpZtZww1Tkq8mATxdGwIyhgh" + "fDKQXkYuNs474553LBgOhgObJ4Oi7Aeij7XFXfBvTFLJ3ivL9pVYFxg5lUl86pVq" + "5RXSJhiY+gUQFXKOWoqqxC2tMxcNBFB6M6hVIavfHLpk7PuFBFjb7wqK6nFXXQYM" + "fbOXD4Wm4eTHq/WujNsJM9cejJTgSiVhnc7j0iYa0u5r8S/6BtmKCGTYdgJzPshq" + "ZFIfKxgXeyAMu+EXV3phXWx3CYjAutlG4gjiT6B05asxQ9tb/OD9EI5LgtEgqSEI" + "ARpyPBKnh+bXiHGaEL26WyaZwycYavTiPBqUaDS2FQvaJYPpyirUTOjbu8LbBN6O" + "+S6O/BQfvsqmKHxZR05rwF2ZspZPoJDDoiM7oYZRW+ftH2EpcM7i16+4G912IXBI" + "HNAGkSfVsFqpk7TqmI2P3cGG/7fckKbAj030Nck0BjGZ//////////8CAQICggIA" + "f//////////kh+1RELRhGmJjMUXAbg5olIEnBEUz5joBBd9THYnNkSilBDzHGgJu" + "98qM2eadIY2YFYU2+S+KG6fwmra2qOEi8kLauzEvP2N6JiF00xv2tYX/rlt6A1v2" + "9xw1/a1Ez9LXT5IIviWP8ySUMyj2ci2e4QA+XFCx34LMbSQbDirpzTSLH9R+kmev" + "wbKuke5R1ssOMXmrEEKpXc9qlIO4S0s2s4YapyVeTAJ4ujYEZQwQvhlILyMXG2cd" + "8c87lgwHQwHNk8HRdgPRR9rirvg3pilk7xXl+0qsC4wcyqS+dUq1corpEwxMfQKI" + "CrlHLUVVYhbWmYuGgig9GdQqkNXvjl0ydn3Cgixt94VFdTirroMGPtnLh8LTcPJj" + "1frXRm2EmeuPRkpwJRKwzudx6RMNaXc1+Jf9A2zFBDJsOwE5n2Q1MikPlYwLvZAG" + "XfCLq70wrrY7hMRgXWyjcQRxJ9A6ctWYoe2t/nB+iEclwWiQVJCEAI05HglTw/Nr" + "xDjNCF7dLZNM4ZOMNXpxHg1KNBpbCoXtEsH05RVqJnRt3eFtgm9HfJdHfgoP32VT" + "FD4so6c14C7M2Usn0Ehh0RGd0MMorfP2j7CUuGdxa9fcDe67ELgkDmgDSJPq2C1U" + "ydp1TEbH7uDDf9vuSFNgR6b6GuSaAxjM//////////8=" + "-----END X942 DH PARAMETERS-----"); - Config::set("x509/crl/unknown_critical", "ignore"); - Config::set("x509/crl/next_update", "7d"); + state->set_option("dl", "dsa/jce/512", + "-----BEGIN DSA PARAMETERS-----" + "MIGdAkEA/KaCzo4Syrom78z3EQ5SbbB4sF7ey80etKII864WF64B81uRpH5t9jQT" + "xeEu0ImbzRMqzVDZkVG9xD7nN1kuFwIVAJYu3cw2nLqOuyYO5rahJtk0bjjFAkEA" + "3gtU76vylwh+5iPVylWIxkgo70/eT/uuHs0gBndrBbEbgeo83pvDlkwWh8UyW/Q9" + "fM76DQqGvl3/3dDRFD3NdQ==" + "-----END DSA PARAMETERS-----"); - Config::set("x509/exts/basic_constraints", "critical"); - Config::set("x509/exts/subject_key_id", "yes"); - Config::set("x509/exts/authority_key_id", "yes"); - Config::set("x509/exts/subject_alternative_name", "yes"); - Config::set("x509/exts/issuer_alternative_name", "yes"); - Config::set("x509/exts/key_usage", "critical"); - Config::set("x509/exts/extended_key_usage", "yes"); - Config::set("x509/exts/crl_number", "yes"); + state->set_option("dl", "dsa/jce/768", + "-----BEGIN DSA PARAMETERS-----" + "MIHdAmEA6eZCWZ01XzfJf/01ZxILjiXJzUPpJ7OpZw++xdiQFBki0sOzrSSACTeZ" + "hp0ehGqrSfqwrSbSzmoiIZ1HC859d31KIfvpwnC1f2BwAvPO+Dk2lM9F7jaIwRqM" + "VqsSej2vAhUAnNvYTJ8awvOND4D0KrlS5zOL9RECYQDe7p717RUWzn5pXmcrjO5F" + "5s17NuDmOF+JS6hhY/bz5sbU6KgRRtQBfe/dccvZD6Akdlm4i3zByJT0gmn9Txqs" + "CjBTjf9rP8ds+xMcnnlltYhYqwpDtVczWRKoqlR/lWg=" + "-----END DSA PARAMETERS-----"); + + state->set_option("dl", "dsa/jce/1024", + "-----BEGIN DSA PARAMETERS-----" + "MIIBHgKBgQD9f1OBHXUSKVLfSpwu7OTn9hG3UjzvRADDHj+AtlEmaUVdQCJR+1k9" + "jVj6v8X1ujD2y5tVbNeBO4AdNG/yZmC3a5lQpaSfn+gEexAiwk+7qdf+t8Yb+DtX" + "58aophUPBPuD9tPFHsMCNVQTWhaRMvZ1864rYdcq7/IiAxmd0UgBxwIVAJdgUI8V" + "IwvMspK5gqLrhAvwWBz1AoGARpYDUS4wJ4zTlHWV2yLuyYJqYyKtyXNE9B10DDJX" + "JMj577qn1NgD/4xgnc0QDrxb38+tfGpCX66nhuogUOvpg1HqH9of3yTWlHqmuaoj" + "dmlTgC9NfUqOy6BtGXaKJJH/sW0O+cQ6mbX3FnL/bwoktETQc20E04oaEyLa9s3Y" + "jJ0=" + "-----END DSA PARAMETERS-----"); } } +/************************************************* +* Set the default policy * +*************************************************/ +void Library_State::set_default_policy() + { + set_default_config(this); + set_default_aliases(this); + set_default_oids(this); + set_default_dl_groups(this); + } + } ============================================================ --- botan/pow_mod.cpp d329aa0377ba3cb1b4249c155cacadb76cc0a43f +++ botan/pow_mod.cpp 622ad0b2f9cc40a01000c02e1e486e4bd40140b6 @@ -1,142 +1,152 @@ /************************************************* -* Modular Exponentiation Source File * -* (C) 1999-2005 The Botan Project * +* Modular Exponentiation Proxy Source File * +* (C) 1999-2006 The Botan Project * *************************************************/ -#include -#include +#include +#include namespace Botan { -namespace { +/************************************************* +* Power_Mod Constructor * +*************************************************/ +Power_Mod::Power_Mod(const BigInt& n, Usage_Hints hints) + { + core = 0; + set_modulus(n, hints); + } /************************************************* -* Exponentiation Window Size * +* Power_Mod Copy Constructor * *************************************************/ -u32bit window_size(u32bit exp_bits) +Power_Mod::Power_Mod(const Power_Mod& other) { - struct mapping { u32bit bits; u32bit window_size; }; + core = 0; + if(other.core) + core = other.core->copy(); + } - static const mapping wsize[] = { - { 2048, 7 }, - { 1024, 6 }, - { 256, 5 }, - { 128, 4 }, - { 64, 3 }, - { 0, 0 } - }; +/************************************************* +* Power_Mod Assignment Operator * +*************************************************/ +Power_Mod& Power_Mod::operator=(const Power_Mod& other) + { + delete core; + core = 0; + if(other.core) + core = other.core->copy(); + return (*this); + } - for(u32bit j = 0; wsize[j].bits; j++) - { - if(exp_bits >= wsize[j].bits) - return wsize[j].window_size; - } - return 1; +/************************************************* +* Power_Mod Destructor * +*************************************************/ +Power_Mod::~Power_Mod() + { + delete core; } /************************************************* -* Left-to-Right Binary Modular Exponentiation * +* Set the modulus * *************************************************/ -BigInt power_mod_l2r(const BigInt& basex, const BigInt& exp, - ModularReducer* reducer) +void Power_Mod::set_modulus(const BigInt& n, Usage_Hints hints) const { - const BigInt base = reducer->convert_in(basex); - const u32bit exp_bits = exp.bits(); + delete core; + core = ((n == 0) ? 0 : Engine_Core::mod_exp(n, hints)); + } - BigInt x = reducer->convert_in(1); - for(u32bit j = exp_bits; j > 0; j--) - { - x = reducer->square(x); - if(exp.get_bit(j-1)) - x = reducer->multiply(x, base); - } - return reducer->convert_out(x); +/************************************************* +* Set the base * +*************************************************/ +void Power_Mod::set_base(const BigInt& b) const + { + if(b.is_zero() || b.is_negative()) + throw Invalid_Argument("Power_Mod::set_base: arg must be > 0"); + + if(!core) + throw Internal_Error("Power_Mod::set_base: core was NULL"); + core->set_base(b); } /************************************************* -* Modular Exponentiation with g = 2 * +* Set the exponent * *************************************************/ -BigInt power_mod_g2(const BigInt& exp, ModularReducer* reducer) +void Power_Mod::set_exponent(const BigInt& e) const { - if(reducer->must_convert()) - throw Internal_Error("power_mod_g2: Can't use this reducer"); + if(e.is_negative()) + throw Invalid_Argument("Power_Mod::set_exponent: arg must be > 0"); - const u32bit exp_bits = exp.bits(); - BigInt x = 1; - for(u32bit j = exp_bits; j > 0; j--) - { - x = reducer->square(x); - if(exp.get_bit(j-1)) - { - x <<= 1; - x = reducer->reduce(x); - } - } - return x; + if(!core) + throw Internal_Error("Power_Mod::set_exponent: core was NULL"); + core->set_exponent(e); } /************************************************* -* Window Modular Exponentiation * +* Compute the result * *************************************************/ -BigInt power_mod_window(const BigInt& base, const BigInt& exp, - ModularReducer* reducer, u32bit window_bits) +BigInt Power_Mod::execute() const { - if(window_bits < 2) - throw Internal_Error("power_mod_window: Window size too small"); + if(!core) + throw Internal_Error("Power_Mod::execute: core was NULL"); + return core->execute(); + } - std::vector g((1 << window_bits) - 1); +namespace { - g[0] = reducer->convert_in(base); - for(u32bit j = 1; j != g.size(); j++) - g[j] = reducer->multiply(g[j-1], g[0]); +/************************************************* +* Choose potentially useful hints * +*************************************************/ +Power_Mod::Usage_Hints choose_base_hints(const BigInt& b, const BigInt& n) + { + if(b == 2) + return Power_Mod::Usage_Hints(Power_Mod::BASE_IS_2 | + Power_Mod::BASE_IS_SMALL); - const u32bit exp_nibbles = (exp.bits() + window_bits - 1) / window_bits; + const u32bit b_bits = b.bits(); + const u32bit n_bits = n.bits(); - BigInt x = reducer->convert_in(1); - for(u32bit j = exp_nibbles; j > 0; j--) - { - for(u32bit k = 0; k != window_bits; k++) - x = reducer->square(x); - u32bit nibble = exp.get_nibble(j-1, window_bits); - if(nibble) - x = reducer->multiply(x, g[nibble-1]); - } - return reducer->convert_out(x); + if(b_bits < n_bits / 32) + return Power_Mod::BASE_IS_SMALL; + if(b_bits > n_bits / 4) + return Power_Mod::BASE_IS_LARGE; + + return Power_Mod::NO_HINTS; } +Power_Mod::Usage_Hints choose_exp_hints(const BigInt& e, const BigInt& n) + { + const u32bit e_bits = e.bits(); + const u32bit n_bits = n.bits(); + + if(e_bits < n_bits / 32) + return Power_Mod::BASE_IS_SMALL; + if(e_bits > n_bits / 4) + return Power_Mod::BASE_IS_LARGE; + return Power_Mod::NO_HINTS; + } + } /************************************************* -* Modular Exponentiation * +* Fixed_Exponent_Power_Mod Constructor * *************************************************/ -BigInt power_mod(const BigInt& base, const BigInt& exp, const BigInt& mod) +Fixed_Exponent_Power_Mod::Fixed_Exponent_Power_Mod(const BigInt& e, + const BigInt& n, + Usage_Hints hints) : + Power_Mod(n, Usage_Hints(hints | EXP_IS_FIXED | choose_exp_hints(e, n))) { - ModularReducer* reducer = get_reducer(mod); - BigInt x = power_mod(base, exp, reducer); - delete reducer; - return x; + set_exponent(e); } /************************************************* -* Modular Exponentiation Algorithm Dispatch * +* Fixed_Base_Power_Mod Constructor * *************************************************/ -BigInt power_mod(const BigInt& base, const BigInt& exp, - ModularReducer* reducer) +Fixed_Base_Power_Mod::Fixed_Base_Power_Mod(const BigInt& b, const BigInt& n, + Usage_Hints hints) : + Power_Mod(n, Usage_Hints(hints | BASE_IS_FIXED | choose_base_hints(b, n))) { - if(base.is_negative()) - throw Invalid_Argument("power_mod: base must be positive"); - if(exp.is_negative()) - throw Invalid_Argument("power_mod: exponent must be positive"); - if(exp.is_zero()) - return 1; - - const u32bit window_bits = window_size(exp.bits()); - - if(base == 2 && !reducer->must_convert()) - return power_mod_g2(exp, reducer); - if(window_bits > 1) - return power_mod_window(base, exp, reducer, window_bits); - return power_mod_l2r(base, exp, reducer); + set_base(b); } } ============================================================ --- botan/prf_x942.cpp 6510c500215a92d3031d2f143432e45ed95c314c +++ botan/prf_x942.cpp 8878753f4bcf9a5a1f71ac387b1a02c7f0acd23f @@ -1,6 +1,6 @@ /************************************************* * X9.42 PRF Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -20,7 +20,7 @@ MemoryVector encode_x942_int(u32bit n) { byte n_buf[4]; - for(u32bit j = 0; j != 4; j++) + for(u32bit j = 0; j != 4; ++j) n_buf[j] = get_byte(j, n); DER_Encoder encoder; @@ -69,7 +69,7 @@ SecureVector digest = hash->final(); key.append(digest, std::min(digest.size(), key_len - key.size())); - counter++; + ++counter; } return key; ============================================================ --- botan/primes.cpp 6ece0b544fbb2d23c817999b4211dbd5c22cc092 +++ botan/primes.cpp b6bc7dbb320ff24cdf16689cb57361551d6bc693 @@ -1,6 +1,6 @@ /************************************************* * Small Primes Table * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/pubkey.cpp 3fbc4d1720dbaa6d720465ae742d8862e02c1196 +++ botan/pubkey.cpp 82d0927ec5f390da00feeca1e23933c997c18df4 @@ -1,6 +1,6 @@ /************************************************* * Public Key Base Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -192,12 +192,12 @@ const u32bit SIZE_OF_PART = plain_sig.size() / key.message_parts(); std::vector sig_parts(key.message_parts()); - for(u32bit j = 0; j != sig_parts.size(); j++) + for(u32bit j = 0; j != sig_parts.size(); ++j) sig_parts[j].binary_decode(plain_sig + SIZE_OF_PART*j, SIZE_OF_PART); DER_Encoder der_sig; der_sig.start_sequence(); - for(u32bit j = 0; j != sig_parts.size(); j++) + for(u32bit j = 0; j != sig_parts.size(); ++j) DER::encode(der_sig, sig_parts[j]); der_sig.end_sequence(); @@ -299,7 +299,7 @@ BER::decode(ber_sig, sig_part); real_sig.append(BigInt::encode_1363(sig_part, key.message_part_size())); - count++; + ++count; } if(count != key.message_parts()) throw Decoding_Error("PK_Verifier: signature size invalid"); ============================================================ --- botan/pubkey.h f98be2d1a95ff8e0cee18613917206aa7e1c6108 +++ botan/pubkey.h 7ffbfc8f5ce3e9b1c06623dc3d6adceb4c582e17 @@ -1,6 +1,6 @@ /************************************************* * Public Key Interface Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_PUBKEY_H__ ============================================================ --- botan/randpool.cpp cd54358602f6d3d1be416d1175fbd586cf711be6 +++ botan/randpool.cpp 3e6ae9338b29a4a63d97b189a4184b9e18413038 @@ -1,6 +1,6 @@ /************************************************* * Randpool Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -35,16 +35,16 @@ void Randpool::update_buffer() { const u64bit timestamp = system_clock(); - counter++; + ++counter; - for(u32bit j = 0; j != 4; j++) + for(u32bit j = 0; j != 4; ++j) mac->update(get_byte(j, counter)); - for(u32bit j = 0; j != 8; j++) + for(u32bit j = 0; j != 8; ++j) mac->update(get_byte(j, timestamp)); SecureVector mac_val = mac->final(); - for(u32bit j = 0; j != mac_val.size(); j++) + for(u32bit j = 0; j != mac_val.size(); ++j) buffer[j % buffer.size()] ^= mac_val[j]; cipher->encrypt(buffer); @@ -67,7 +67,7 @@ xor_buf(pool, buffer, BLOCK_SIZE); cipher->encrypt(pool); - for(u32bit j = 1; j != POOL_BLOCKS; j++) + for(u32bit j = 1; j != POOL_BLOCKS; ++j) { const byte* previous_block = pool + BLOCK_SIZE*(j-1); byte* this_block = pool + BLOCK_SIZE*j; ============================================================ --- botan/randpool.h ac16cee42189e9d81f1be3927e6ecfc76240fee9 +++ botan/randpool.h bb00fef73a9af0b71f44a5478a668c8aad1211b2 @@ -1,6 +1,6 @@ /************************************************* * Randpool Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_RANDPOOL_H__ ============================================================ --- botan/readme.txt 2e95992aa746384a01dd6ce9c683f040a15539ae +++ botan/readme.txt 5a24d1c1f9a0ab20413df3e5517d6c7f179c4158 @@ -1,4 +1,4 @@ -Botan: Version 1.4.10, December 18, 2005 +Botan: Version 1.5.2, January 15, 2006 Botan is a C++ class library for performing a wide variety of cryptographic operations, including encryption, hashing, authentication, public key @@ -15,9 +15,9 @@ IDEA, KASUMI, Lion, Luby-Rackoff, MARS, MISTY1, RC2, RC5, RC6, SAFER-SK, SEED, Serpent, Skipjack, Square, TEA, Twofish, XTEA -* Stream Ciphers: ARC4, ISAAC, SEAL, WiderWake4+1 +* Stream Ciphers: ARC4, WiderWake4+1, Turing -* Hash Functions: HAS-160, HAVAL, MD2, MD4, MD5, RIPEMD-128, RIPEMD-160, +* Hash Functions: HAS-160, MD2, MD4, MD5, RIPEMD-128, RIPEMD-160, SHA-160, SHA-256, SHA-384, SHA-512, Tiger, Whirlpool * MACs: ANSI X9.19 MAC, CMAC, HMAC ============================================================ --- botan/reducer.cpp af05c42c789bbcfcba6ee93371320052a37f7bd5 +++ botan/reducer.cpp c9bfcbf3595d7d6f59a1e04275a68eb89054b10e @@ -1,54 +1,112 @@ /************************************************* * Modular Reducer Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include #include +#include +#include namespace Botan { +namespace { + /************************************************* -* Construct a ModularReducer * +* Barrett Reducer * *************************************************/ -ModularReducer::ModularReducer(const BigInt& n) : modulus(n) +class Barrett_Reducer : public ModularReducer { + public: + BigInt multiply(const BigInt&, const BigInt&) const; + BigInt square(const BigInt& x) const + { return reduce(Botan::square(x)); } + + BigInt reduce(const BigInt&) const; + const BigInt& get_modulus() const { return modulus; } + + Barrett_Reducer(const BigInt&); + private: + BigInt modulus, mu; + mutable BigInt t1, t2; + u32bit max_bits, k; + }; + +/************************************************* +* Barrett_Reducer Constructor * +*************************************************/ +Barrett_Reducer::Barrett_Reducer(const BigInt& mod) : modulus(mod) + { if(modulus <= 0) - throw Invalid_Argument("ModularReducer: modulus must be positive"); + throw Invalid_Argument("Barrett_Reducer: modulus must be positive"); + if(modulus.size() > 8 && !power_of_2(modulus.size())) modulus.grow_reg((1 << high_bit(modulus.size())) - modulus.size()); + + k = modulus.sig_words(); + mu.set_bit(MP_WORD_BITS * 2 * k); + mu /= modulus; + max_bits = MP_WORD_BITS * 2 * k; + + if(mu.size() > 8 && !power_of_2(mu.size())) + mu.grow_reg((1 << high_bit(mu.size())) - mu.size()); } /************************************************* -* Convert to the modular form * +* Barrett Reduction * *************************************************/ -BigInt ModularReducer::convert_in(const BigInt& i) const +BigInt Barrett_Reducer::reduce(const BigInt& x) const { - return i; - } + if(x.is_positive() && x < modulus) + return x; + if(x.bits() > max_bits) + return (x % modulus); -/************************************************* -* Convert from the modular form * -*************************************************/ -BigInt ModularReducer::convert_out(const BigInt& i) const - { - return i; + t1 = x; + t1.set_sign(BigInt::Positive); + + t1 >>= (MP_WORD_BITS * (k - 1)); + t1 *= mu; + t1 >>= (MP_WORD_BITS * (k + 1)); + + t1 *= modulus; + t1.mask_bits(MP_WORD_BITS * (k+1)); + + t2 = x; + t2.set_sign(BigInt::Positive); + t2.mask_bits(MP_WORD_BITS * (k+1)); + + t2 -= t1; + + if(t2.is_negative()) + { + BigInt b_to_k1(BigInt::Power2, MP_WORD_BITS * (k+1)); + t2 += b_to_k1; + } + while(t2 >= modulus) + t2 -= modulus; + + if(x.is_negative() && t2.is_nonzero()) + t2 = modulus - t2; + + return t2; } /************************************************* -* Modular Multiplication * +* Multiply, followed by a reduction * *************************************************/ -BigInt ModularReducer::multiply(const BigInt& x, const BigInt& y) const +BigInt Barrett_Reducer::multiply(const BigInt& x, const BigInt& y) const { return reduce(x * y); } +} + /************************************************* -* Modular Squaring * +* Acquire a modular reducer * *************************************************/ -BigInt ModularReducer::square(const BigInt& x) const +ModularReducer* get_reducer(const BigInt& n) { - return multiply(x, x); + return new Barrett_Reducer(n); } - } ============================================================ --- botan/reducer.h 3f84481f5c8f523e7d2e2aee651aac211d88b16e +++ botan/reducer.h 5958c1b425b899e44d943db154b4707818789d2b @@ -1,6 +1,6 @@ /************************************************* * Modular Reducer Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_MODARITH_H__ @@ -16,27 +16,19 @@ class ModularReducer { public: - virtual BigInt multiply(const BigInt&, const BigInt&) const; - virtual BigInt square(const BigInt&) const; + virtual BigInt multiply(const BigInt&, const BigInt&) const = 0; + virtual BigInt square(const BigInt&) const = 0; virtual BigInt reduce(const BigInt&) const = 0; - virtual bool must_convert() const { return false; } + virtual const BigInt& get_modulus() const = 0; - virtual BigInt convert_in(const BigInt&) const; - virtual BigInt convert_out(const BigInt&) const; - - const BigInt& get_modulus() const { return modulus; } - - ModularReducer(const BigInt&); virtual ~ModularReducer() {} - protected: - const BigInt modulus; }; /************************************************* * Get a modular reducer * *************************************************/ -ModularReducer* get_reducer(const BigInt&, bool = false); +ModularReducer* get_reducer(const BigInt&); } ============================================================ --- botan/rng.cpp 7c1cdf73c8815e9bc2dbe381e910c999dca9154c +++ botan/rng.cpp 8139450d8cf07f579a396a137018a6a0d34d488e @@ -1,226 +1,30 @@ /************************************************* * Global RNG Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include -#include -#include -#include -#include -#include -#include +#include namespace Botan { -namespace { - -/************************************************* -* Global RNG/EntropySource state * -*************************************************/ -class RNG_State - { - public: - void set_rngs(RandomNumberGenerator*, RandomNumberGenerator*); - void add_es(EntropySource*, bool); - void add_entropy(const byte[], u32bit); - u32bit poll_es(EntropySource*, bool); - - u32bit seed(bool, u32bit); - - void randomize(byte[], u32bit, RNG_Quality); - - RNG_State(); - ~RNG_State(); - private: - void seed_nonce_rng(); - RandomNumberGenerator* global_rng; - RandomNumberGenerator* nonce_rng; - Mutex* rng_mutex; - Mutex* sources_mutex; - std::vector sources; - }; - -/************************************************* -* Create the RNG state * -*************************************************/ -RNG_State::RNG_State() - { - global_rng = nonce_rng = 0; - rng_mutex = get_mutex(); - sources_mutex = get_mutex(); - } - -/************************************************* -* Destroy the RNG state * -*************************************************/ -RNG_State::~RNG_State() - { - delete global_rng; - delete nonce_rng; - for(u32bit j = 0; j != sources.size(); j++) - delete sources[j]; - - delete rng_mutex; - delete sources_mutex; - } - -/************************************************* -* Set the RNG algorithms * -*************************************************/ -void RNG_State::set_rngs(RandomNumberGenerator* rng1, - RandomNumberGenerator* rng2) - { - if(rng1) - { - if(global_rng) - delete global_rng; - global_rng = rng1; - } - - if(rng2) - { - if(nonce_rng) - delete nonce_rng; - nonce_rng = rng2; - } - } - -/************************************************* -* Get entropy from the global RNG * -*************************************************/ -void RNG_State::randomize(byte output[], u32bit size, RNG_Quality level) - { - const std::string LTERM_CIPHER = "WiderWake4+1"; - - Mutex_Holder lock(rng_mutex); - - if(!global_rng || !nonce_rng) - throw Invalid_State("Global_RNG::randomize: The global RNG is unset"); - - if(level == Nonce) - nonce_rng->randomize(output, size); - else if(level == SessionKey) - global_rng->randomize(output, size); - else if(level == LongTermKey) - { - global_rng->randomize(output, size); - if(have_stream_cipher(LTERM_CIPHER)) - { - std::auto_ptr cipher(get_stream_cipher(LTERM_CIPHER)); - SecureVector key(cipher->MAXIMUM_KEYLENGTH); - global_rng->randomize(key.begin(), key.size()); - cipher->set_key(key.begin(), key.size()); - cipher->encrypt(output, size); - } - } - else - throw Invalid_Argument("Global_RNG::randomize: Invalid RNG_Quality"); - } - -/************************************************* -* Add entropy to the RNG * -*************************************************/ -void RNG_State::add_entropy(const byte buf[], u32bit length) - { - Mutex_Holder lock(rng_mutex); - - if(!global_rng || !nonce_rng) - throw Invalid_State("Global_RNG::add_entropy: The global RNG is unset"); - - global_rng->add_entropy(buf, length); - seed_nonce_rng(); - } - -/************************************************* -* Add an EntropySource to the list * -*************************************************/ -void RNG_State::add_es(EntropySource* src, bool last) - { - Mutex_Holder lock(sources_mutex); - if(last) - sources.push_back(src); - else - sources.insert(sources.begin(), src); - } - -/************************************************* -* Seed the nonce RNG * -*************************************************/ -void RNG_State::seed_nonce_rng() - { - if(!global_rng->is_seeded()) - return; - - for(u32bit j = 0; j != 3; j++) - { - if(nonce_rng->is_seeded()) - break; - - SecureVector entropy(64); - global_rng->randomize(entropy.begin(), entropy.size()); - nonce_rng->add_entropy(entropy.begin(), entropy.size()); - } - } - -/************************************************* -* Try to do a poll on an EntropySource * -*************************************************/ -u32bit RNG_State::poll_es(EntropySource* source, bool slow_poll) - { - SecureVector buffer(256); - u32bit got = 0; - - if(slow_poll) got = source->slow_poll(buffer.begin(), buffer.size()); - else got = source->fast_poll(buffer.begin(), buffer.size()); - - add_entropy(buffer.begin(), got); - return entropy_estimate(buffer.begin(), got); - } - -/************************************************* -* Attempt to seed the RNGs * -*************************************************/ -u32bit RNG_State::seed(bool slow_poll, u32bit bits_to_get) - { - Mutex_Holder lock(sources_mutex); - - u32bit bits = 0; - for(u32bit j = 0; j != sources.size(); j++) - { - bits += poll_es(sources[j], slow_poll); - if(bits_to_get && bits >= bits_to_get) - return bits; - } - return bits; - } - -/************************************************* -* The global RNG state * -*************************************************/ -RNG_State* rng_state = 0; - -} - namespace Global_RNG { /************************************************* -* Get entropy from the global RNG * +* Get random bits from the global RNG * *************************************************/ -void randomize(byte output[], u32bit size, RNG_Quality level) +void randomize(byte output[], u32bit size) { - if(!rng_state) - throw Internal_Error("Global_RNG::randomize: RNG state never created"); - rng_state->randomize(output, size, level); + global_state().randomize(output, size); } /************************************************* -* Get entropy from the global RNG * +* Get random bits from the global RNG * *************************************************/ -byte random(RNG_Quality level) +byte random() { byte ret = 0; - randomize(&ret, 1, level); + randomize(&ret, 1); return ret; } @@ -229,9 +33,7 @@ *************************************************/ void add_entropy(const byte entropy[], u32bit size) { - if(!rng_state) - throw Internal_Error("Global_RNG::add_entropy: RNG state never created"); - rng_state->add_entropy(entropy, size); + global_state().add_entropy(entropy, size); } /************************************************* @@ -239,19 +41,15 @@ *************************************************/ void add_entropy(EntropySource& src, bool slow_poll) { - if(!rng_state) - throw Internal_Error("Global_RNG::poll_es: RNG state never created"); - rng_state->poll_es(&src, slow_poll); + global_state().add_entropy(src, slow_poll); } /************************************************* -* Add an EntropySource to the list * +* Add an EntropySource to the RNG seed list * *************************************************/ void add_es(EntropySource* src, bool last) { - if(!rng_state) - throw Internal_Error("Global_RNG::add_es: RNG state never created"); - rng_state->add_es(src, last); + global_state().add_entropy_source(src, last); } /************************************************* @@ -259,42 +57,9 @@ *************************************************/ u32bit seed(bool slow_poll, u32bit bits_to_get) { - if(!rng_state) - throw Internal_Error("Global_RNG::seed: RNG state never created"); - return rng_state->seed(slow_poll, bits_to_get); + return global_state().seed_prng(slow_poll, bits_to_get); } } -namespace Init { - -/************************************************* -* Initialize the RNG system * -*************************************************/ -void init_rng_subsystem() - { - rng_state = new RNG_State; - } - -/************************************************* -* Deinitialize the RNG system * -*************************************************/ -void shutdown_rng_subsystem() - { - delete rng_state; - rng_state = 0; - } - -/************************************************* -* Setup the global RNG * -*************************************************/ -void set_global_rngs(RandomNumberGenerator* rng1, RandomNumberGenerator* rng2) - { - if(!rng_state) - throw Internal_Error("set_global_rngs: RNG state never created"); - rng_state->set_rngs(rng1, rng2); - } - } - -} ============================================================ --- botan/rng.h 23a42a4209ff8c1050f7d12d8b6e75696f549067 +++ botan/rng.h b7323e6afbef620294a9ade850838a996bfc588f @@ -1,6 +1,6 @@ /************************************************* * Global RNG Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_GLOBAL_RNG_H__ @@ -15,8 +15,8 @@ *************************************************/ namespace Global_RNG { -void randomize(byte[], u32bit, RNG_Quality = SessionKey); -byte random(RNG_Quality = SessionKey); +void randomize(byte[], u32bit); +byte random(); void add_entropy(const byte[], u32bit); void add_entropy(EntropySource&, bool = true); @@ -27,17 +27,6 @@ } -/************************************************* -* RNG Control Functions * -*************************************************/ -namespace Init { - -void set_global_rngs(RandomNumberGenerator*, RandomNumberGenerator*); -void init_rng_subsystem(); -void shutdown_rng_subsystem(); - } -} - #endif ============================================================ --- botan/rsa.cpp fd012f7422edfebb9f6cc0c979d0e03d5ef36c22 +++ botan/rsa.cpp e5fb31ae1075baa340d89177d4757f574cf2bda1 @@ -1,6 +1,6 @@ /************************************************* * RSA Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -60,8 +60,8 @@ throw Invalid_Argument(algo_name() + ": Invalid encryption exponent"); e = exp; - p = random_prime((bits + 1) / 2, LongTermKey, e); - q = random_prime(bits - p.bits(), LongTermKey, e); + p = random_prime((bits + 1) / 2, e); + q = random_prime(bits - p.bits(), e); d = inverse_mod(e, lcm(p - 1, q - 1)); PKCS8_load_hook(); ============================================================ --- botan/rsa.h f30ab1f3965b3f7f93c32a1acee311079c780d1a +++ botan/rsa.h f6b55678f033bcdc11bbcd04348058880391327f @@ -1,6 +1,6 @@ /************************************************* * RSA Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_RSA_H__ @@ -33,8 +33,10 @@ /************************************************* * RSA Private Key * *************************************************/ -class RSA_PrivateKey : public RSA_PublicKey, public PK_Decrypting_Key, - public PK_Signing_Key, public IF_Scheme_PrivateKey +class RSA_PrivateKey : public RSA_PublicKey, + public PK_Decrypting_Key, + public PK_Signing_Key, + public IF_Scheme_PrivateKey { public: SecureVector decrypt(const byte[], u32bit) const; ============================================================ --- botan/s2k.cpp ccfb48a2afc91995ebef9d2ddd413ee635db7327 +++ botan/s2k.cpp edc80c7f6a50d8cc113d9e0ab44b2f49a05e54f2 @@ -1,6 +1,6 @@ /************************************************* * S2K Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -47,7 +47,7 @@ void S2K::new_random_salt(u32bit length) { salt.create(length); - Global_RNG::randomize(salt, length, Nonce); + Global_RNG::randomize(salt, length); } } ============================================================ --- botan/s2k.h d7098ee5352337e1cad8416f9f36d07a8ac81d17 +++ botan/s2k.h f0d79e35304bc813713fa30c5f956fb5749ce288 @@ -1,6 +1,6 @@ /************************************************* * S2K Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_S2K_H__ ============================================================ --- botan/secmem.h dd47f6b950495e2337fcf95bc44d4138d1f993f1 +++ botan/secmem.h 7e435e885f9a0f44a51989c8f70615d0f88aabb3 @@ -1,6 +1,6 @@ /************************************************* * Secure Memory Buffers Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_SECURE_MEMORY_BUFFERS_H__ @@ -8,7 +8,6 @@ #include #include -#include namespace Botan { @@ -20,7 +19,6 @@ { public: u32bit size() const { return used; } - u32bit bits() const { return 8*used; } u32bit is_empty() const { return (used == 0); } u32bit has_items() const { return (used != 0); } @@ -48,9 +46,9 @@ { if(this != &in) set(in); return (*this); } void copy(const T in[], u32bit n) - { copy_mem(buf, in, std::min(size(), n)); } + { copy(0, in, n); } void copy(u32bit off, const T in[], u32bit n) - { copy_mem(buf + off, in, std::min(size() - off, n)); } + { copy_mem(buf + off, in, (n > size() - off) ? (size() - off) : n); } void set(const T in[], u32bit n) { create(n); copy(in, n); } void set(const MemoryRegion& in) { set(in.begin(), in.size()); } @@ -89,7 +87,7 @@ mutable T* buf; mutable u32bit used; mutable u32bit allocated; - const Allocator* alloc; + mutable Allocator* alloc; }; /************************************************* @@ -110,8 +108,6 @@ template void MemoryRegion::grow_to(u32bit n) const { - const u32bit VECTOR_OVER_ALLOCATE = BOTAN_VECTOR_OVER_ALLOCATE; - if(n <= used) return; if(n <= allocated) { @@ -119,12 +115,11 @@ used = n; return; } - T* new_buf = allocate(n + VECTOR_OVER_ALLOCATE); + T* new_buf = allocate(n); copy_mem(new_buf, buf, used); deallocate(buf, allocated); buf = new_buf; - used = n; - allocated = n + VECTOR_OVER_ALLOCATE; + allocated = used = n; } /************************************************* ============================================================ --- botan/secqueue.cpp 930ab85903a98bb87794e938282860e57ea06a32 +++ botan/secqueue.cpp 980277872ed4f33cb3164ba90aa6f42e43bbd959 @@ -1,6 +1,6 @@ /************************************************* * SecureQueue Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/secqueue.h c5ce3de0ceda46423443b1abf297341eb6a702ea +++ botan/secqueue.h 76d4ccc109fe988f6fa871fcccc8a044fa35f819 @@ -1,6 +1,6 @@ /************************************************* * SecureQueue Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_SECURE_QUEUE_H__ ============================================================ --- botan/sha160.cpp 7aa930cdbc87357c36b8df16fb74338df660ce6a +++ botan/sha160.cpp f5218e5185ae523f2361838286ea0715b3043274 @@ -1,6 +1,6 @@ /************************************************* * SHA-160 Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -53,9 +53,9 @@ *************************************************/ void SHA_160::hash(const byte input[]) { - for(u32bit j = 0; j != 16; j++) + for(u32bit j = 0; j != 16; ++j) W[j] = make_u32bit(input[4*j], input[4*j+1], input[4*j+2], input[4*j+3]); - for(u32bit j = 16; j != 80; j++) + for(u32bit j = 16; j != 80; ++j) W[j] = rotate_left((W[j-3] ^ W[j-8] ^ W[j-14] ^ W[j-16]), 1); u32bit A = digest[0], B = digest[1], C = digest[2], @@ -102,7 +102,7 @@ *************************************************/ void SHA_160::copy_out(byte output[]) { - for(u32bit j = 0; j != OUTPUT_LENGTH; j++) + for(u32bit j = 0; j != OUTPUT_LENGTH; ++j) output[j] = get_byte(j % 4, digest[j/4]); } ============================================================ --- botan/sha160.h ed9b5ecfb4120f6b0c8f5c930705c56959944ef9 +++ botan/sha160.h 40a4e88a85e02cb8ef53d09e5698ba1f2be4d2f4 @@ -1,6 +1,6 @@ /************************************************* * SHA-160 Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_SHA_160_H__ ============================================================ --- botan/sha256.cpp 6f8f29549c04f271120115f9c14113dd3b47c502 +++ botan/sha256.cpp 5311156645190069e0d83433994737454ed7e748 @@ -1,6 +1,6 @@ /************************************************* * SHA-256 Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -46,9 +46,9 @@ *************************************************/ void SHA_256::hash(const byte input[]) { - for(u32bit j = 0; j != 16; j++) + for(u32bit j = 0; j != 16; ++j) W[j] = make_u32bit(input[4*j], input[4*j+1], input[4*j+2], input[4*j+3]); - for(u32bit j = 16; j != 64; j++) + for(u32bit j = 16; j != 64; ++j) W[j] = sigma(W[j- 2], 17, 19, 10) + W[j- 7] + sigma(W[j-15], 7, 18, 3) + W[j-16]; @@ -99,7 +99,7 @@ *************************************************/ void SHA_256::copy_out(byte output[]) { - for(u32bit j = 0; j != OUTPUT_LENGTH; j++) + for(u32bit j = 0; j != OUTPUT_LENGTH; ++j) output[j] = get_byte(j % 4, digest[j/4]); } ============================================================ --- botan/sha256.h ad8001298ac6bfcef4891124d3f8ebd9c2011366 +++ botan/sha256.h f3fb2c1515d6e4275bfca19cf10c24bd217f9539 @@ -1,6 +1,6 @@ /************************************************* * SHA-256 Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_SHA_256_H__ ============================================================ --- botan/symkey.cpp 2769475d3a051cfa8cdaec178c3e23517b5e9d73 +++ botan/symkey.cpp bf0815d2471b664035f262f40563c4eab7df9164 @@ -1,6 +1,6 @@ /************************************************* * OctetString Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -14,10 +14,10 @@ /************************************************* * Create an OctetString from RNG output * *************************************************/ -void OctetString::change(u32bit length, RNG_Quality level) +void OctetString::change(u32bit length) { bits.create(length); - Global_RNG::randomize(bits, length, level); + Global_RNG::randomize(bits, length); } /************************************************* @@ -26,14 +26,14 @@ void OctetString::change(const std::string& hex_string) { SecureVector hex; - for(u32bit j = 0; j != hex_string.length(); j++) + for(u32bit j = 0; j != hex_string.length(); ++j) if(Hex_Decoder::is_valid(hex_string[j])) hex.append(hex_string[j]); if(hex.size() % 2 != 0) throw Invalid_Argument("OctetString: hex string must encode full bytes"); bits.create(hex.size() / 2); - for(u32bit j = 0; j != bits.size(); j++) + for(u32bit j = 0; j != bits.size(); ++j) bits[j] = Hex_Decoder::decode(hex.begin() + 2*j); } @@ -75,7 +75,7 @@ 0xF1, 0xF1, 0xF2, 0xF2, 0xF4, 0xF4, 0xF7, 0xF7, 0xF8, 0xF8, 0xFB, 0xFB, 0xFD, 0xFD, 0xFE, 0xFE }; - for(u32bit j = 0; j != bits.size(); j++) + for(u32bit j = 0; j != bits.size(); ++j) bits[j] = ODD_PARITY[bits[j]]; } ============================================================ --- botan/symkey.h 4851cea7540a270a7ac4082c3e1a052664453287 +++ botan/symkey.h 4ae3b55ea13aa03145bea1434c8ed08919c22526 @@ -1,6 +1,6 @@ /************************************************* * OctetString Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_SYMKEY_H__ @@ -30,7 +30,7 @@ void set_odd_parity(); - void change(u32bit, RNG_Quality); + void change(u32bit); void change(const std::string&); void change(const byte[], u32bit); void change(const MemoryRegion& in) { bits = in; } @@ -56,7 +56,6 @@ class SymmetricKey : public OctetString { public: - void change(u32bit n) { OctetString::change(n, SessionKey); } SymmetricKey(u32bit len) { change(len); } SymmetricKey(const std::string& str = "") : OctetString(str) {} SymmetricKey(const byte in[], u32bit l) : OctetString(in, l) {} @@ -70,7 +69,6 @@ class InitializationVector : public OctetString { public: - void change(u32bit n) { OctetString::change(n, Nonce); } InitializationVector(u32bit len) { change(len); } InitializationVector(const std::string& str = "") : OctetString(str) {} InitializationVector(const byte in[], u32bit l) : OctetString(in, l) {} ============================================================ --- botan/timers.cpp 0f75eecff82397be0b76891f68c73817e58a8136 +++ botan/timers.cpp 02e9174ce65403c561b579be46ec6dba3dda732e @@ -1,21 +1,15 @@ /************************************************* * Timestamp Functions Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include +#include #include -#include #include namespace Botan { -namespace { - -Timer* global_timer = 0; - -} - /************************************************* * Timer Access Functions * *************************************************/ @@ -26,32 +20,25 @@ u64bit system_clock() { - if(!global_timer) - return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC); - return global_timer->clock(); + return global_state().system_clock(); } /************************************************* -* Combine a two time values into a single one * +* Default Timer clock reading * *************************************************/ -u64bit combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz) +u64bit Timer::clock() const { - const u64bit NANOSECONDS_UNITS = 1000000000; - parts *= (NANOSECONDS_UNITS / parts_hz); - return ((seconds * NANOSECONDS_UNITS) + parts); + return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC); } -namespace Init { - /************************************************* -* Set the Timer type * +* Combine a two time values into a single one * *************************************************/ -void set_timer_type(Timer* timer) +u64bit combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz) { - delete global_timer; - global_timer = timer; + const u64bit NANOSECONDS_UNITS = 1000000000; + parts *= (NANOSECONDS_UNITS / parts_hz); + return ((seconds * NANOSECONDS_UNITS) + parts); } } - -} ============================================================ --- botan/timers.h 7faf9a0353f4d8fe1c11b15bcf76a6db4e34860b +++ botan/timers.h 54ddc626b8eb21354b91f17da4ce23f04553abae @@ -1,6 +1,6 @@ /************************************************* * Timestamp Functions Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_TIMERS_H__ @@ -16,7 +16,7 @@ class Timer { public: - virtual u64bit clock() const = 0; + virtual u64bit clock() const; virtual ~Timer() {} }; ============================================================ --- botan/types.h 6747e38dbc6a39c04386ef1c2b60298a98d6c865 +++ botan/types.h f750f598866f1e3f6def3c798b7e92592e5bc4e1 @@ -1,6 +1,6 @@ /************************************************* * Low Level Types Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_TYPES_H__ ============================================================ --- botan/ui.cpp d5b192eb455808424d41a1e7112d7cb11c5cbe7f +++ botan/ui.cpp 32d9c59fa34f0fd2f122a5cc3b2ff021b3a8898c @@ -1,6 +1,6 @@ /************************************************* * User Interface Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/ui.h a749e0f49028256cd9a159c54c56db95a8a6e66e +++ botan/ui.h b2113a0666a19f2ab5a86669b4aba1b7fb031b1a @@ -1,6 +1,6 @@ /************************************************* * User Interface Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_UI_H__ ============================================================ --- botan/util.cpp ad16ee05002deb5f13a4b9e5e21d2ffa66ae4308 +++ botan/util.cpp e993a6c91b6f3455787fc05d10230307b408c193 @@ -1,6 +1,6 @@ /************************************************* * Utility Functions Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -57,7 +57,7 @@ u32bit estimate = 0; byte last = 0, last_delta = 0, last_delta2 = 0; - for(u32bit j = 0; j != length; j++) + for(u32bit j = 0; j != length; ++j) { byte delta = last ^ buffer[j]; last = buffer[j]; ============================================================ --- botan/util.h 7859becfb3fbbac552c6a78de5b265475fa4a767 +++ botan/util.h 02cce31e55c9e0cf5a237bef31323b20a28d616e @@ -1,6 +1,6 @@ /************************************************* * Utility Functions Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_UTIL_H__ ============================================================ --- botan/version.h f834edcd6981ebe2560d045a4cf24a4fb3946969 +++ botan/version.h 53fa3f9bc084e373ef685a521a5d185125b0ec27 @@ -1,6 +1,6 @@ /************************************************* * Version Information Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_VERSION_H__ ============================================================ --- botan/x509_ca.cpp a6ca91a885bd8be1508fe8348af1282563742659 +++ botan/x509_ca.cpp a94a371ac8b99d786f17441ffd6995ff5e1a6f49 @@ -1,6 +1,6 @@ /************************************************* * X.509 Certificate Authority Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -113,7 +113,7 @@ DER::encode(tbs_cert, X509_CERT_VERSION); tbs_cert.end_explicit(ASN1_Tag(0)); - DER::encode(tbs_cert, random_integer(SERIAL_BITS, Nonce)); + DER::encode(tbs_cert, random_integer(SERIAL_BITS)); DER::encode(tbs_cert, sig_algo); DER::encode(tbs_cert, issuer_dn); tbs_cert.start_sequence(); @@ -170,7 +170,7 @@ if(ex_constraints.size()) { v3_ext.start_sequence(); - for(u32bit j = 0; j != ex_constraints.size(); j++) + for(u32bit j = 0; j != ex_constraints.size(); ++j) DER::encode(v3_ext, ex_constraints[j]); v3_ext.end_sequence(); do_ext(tbs_cert, v3_ext, "X509v3.ExtendedKeyUsage", @@ -252,7 +252,7 @@ throw Invalid_Argument("X509_CA::update_crl: Invalid CRL provided"); std::set > removed_from_crl; - for(u32bit j = 0; j != new_revoked.size(); j++) + for(u32bit j = 0; j != new_revoked.size(); ++j) { if(new_revoked[j].reason == DELETE_CRL_ENTRY) removed_from_crl.insert(new_revoked[j].serial); @@ -260,7 +260,7 @@ all_revoked.push_back(new_revoked[j]); } - for(u32bit j = 0; j != already_revoked.size(); j++) + for(u32bit j = 0; j != already_revoked.size(); ++j) { std::set >::const_iterator i; i = removed_from_crl.find(already_revoked[j].serial); @@ -302,7 +302,7 @@ if(revoked.size()) { tbs_crl.start_sequence(); - for(u32bit j = 0; j != revoked.size(); j++) + for(u32bit j = 0; j != revoked.size(); ++j) DER::encode(tbs_crl, revoked[j]); tbs_crl.end_sequence(); } ============================================================ --- botan/x509_ca.h 8078cf9f2328251a13a938c506447d103a4df5c4 +++ botan/x509_ca.h 06b345d0eea26ad6720442e1972a08604a668eee @@ -1,6 +1,6 @@ /************************************************* * X.509 Certificate Authority Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_X509_CA_H__ ============================================================ --- botan/x509_crl.cpp e3bdb21e5c44ca51be84f8793316df1f66552737 +++ botan/x509_crl.cpp 3a01fdbeaa239a0ab8a4353824707f29ed4f5e4b @@ -1,6 +1,6 @@ /************************************************* * X.509 CRL Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/x509_crl.h 3976dc632eea02244c6cc1e98b6f50b04c0aaf62 +++ botan/x509_crl.h 971ccf0aa5adeea5f68fe008fbb94ef6400fc891 @@ -1,6 +1,6 @@ /************************************************* * X.509 CRL Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_X509_CRL_H__ ============================================================ --- botan/x509_key.cpp 17699009477db1124b409f6e5e393a1cd709c2e4 +++ botan/x509_key.cpp f70c5fd0cc4caf0c0a467abffe3327e594646ae7 @@ -1,6 +1,6 @@ /************************************************* * X.509 Public Key Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -27,7 +27,7 @@ pipe.end_msg(); u64bit hash = 0; - for(u32bit j = 0; j != 8; j++) + for(u32bit j = 0; j != 8; ++j) { byte next = 0; if(pipe.read(next) != 1) ============================================================ --- botan/x509_key.h 1bc439ee441be814c600aa25263bc3a1e9a0f519 +++ botan/x509_key.h 7467cbbbcf62432e7bcb41fb6a3c189924ca94a9 @@ -1,6 +1,6 @@ /************************************************* * X.509 Public Key Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_X509_PUBLIC_KEY_H__ ============================================================ --- botan/x509_obj.cpp 78e2d735c2a3cf3bb74b5ef36e4a7c132661c4ab +++ botan/x509_obj.cpp cc7e829b3d3013e84ed72e06fdb17e9264f766a2 @@ -1,6 +1,6 @@ /************************************************* * X.509 SIGNED Object Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/x509_obj.h 2fa126c9ed1f9229d5a704c55757c48edb7d0d07 +++ botan/x509_obj.h 2188d419f1e56a96277d2936295c65301309d7a2 @@ -1,6 +1,6 @@ /************************************************* * X.509 SIGNED Object Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_X509_OBJECT_H__ ============================================================ --- botan/x509cert.cpp 9eea501682d3e1f6cd0c35caf8dcc0c1acc6349d +++ botan/x509cert.cpp c72dbb61b0aba0c216ae0affca5de53fb130d086 @@ -1,9 +1,10 @@ /************************************************* * X.509 Certificates Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include +#include #include #include #include @@ -22,7 +23,7 @@ typedef std::multimap::const_iterator rdn_iter; std::multimap attr = dn_info.get_attributes(); - for(rdn_iter j = attr.begin(); j != attr.end(); j++) + for(rdn_iter j = attr.begin(); j != attr.end(); ++j) { const std::string oid_name = OIDS::lookup(j->first); @@ -42,12 +43,12 @@ typedef std::multimap::const_iterator rdn_iter; std::multimap attr = alt_info.get_attributes(); - for(rdn_iter j = attr.begin(); j != attr.end(); j++) + for(rdn_iter j = attr.begin(); j != attr.end(); ++j) multimap_insert(names, j->first, j->second); typedef std::multimap::const_iterator on_iter; std::multimap othernames = alt_info.get_othernames(); - for(on_iter j = othernames.begin(); j != othernames.end(); j++) + for(on_iter j = othernames.begin(); j != othernames.end(); ++j) multimap_insert(names, OIDS::lookup(j->first), j->second.value()); } @@ -64,14 +65,14 @@ std::pair range = names.equal_range(what); std::vector results; - for(rdn_iter j = range.first; j != range.second; j++) + for(rdn_iter j = range.first; j != range.second; ++j) { if(std::find(results.begin(), results.end(), j->second) == results.end()) results.push_back(j->second); } std::string value; - for(u32bit j = 0; j != results.size(); j++) + for(u32bit j = 0; j != results.size(); ++j) value += results[j] + '/'; if(value.size()) value.erase(value.size() - 1, 1); @@ -86,7 +87,7 @@ typedef std::multimap::const_iterator rdn_iter; X509_DN new_dn; - for(rdn_iter j = names.begin(); j != names.end(); j++) + for(rdn_iter j = names.begin(); j != names.end(); ++j) { const std::string oid = j->first; const std::string value = j->second; ============================================================ --- botan/x509cert.h 373ec84916c1d04b14060e7591d35c8a0c95b7ca +++ botan/x509cert.h eccae9cdf0fba3b4993dc1e1003bb971b2348548 @@ -1,6 +1,6 @@ /************************************************* * X.509 Certificates Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_X509_CERTS_H__ ============================================================ --- botan/x509find.cpp 3540674cc40657424e46fa805404cb2c782064af +++ botan/x509find.cpp 30b125452b7d1d505e44a439fde5ef23016ced80 @@ -1,6 +1,6 @@ /************************************************* * X.509 Certificate Store Searching Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/x509opt.cpp dd7040911c23c5a13f5682f5fe4e9d475db2b0f8 +++ botan/x509opt.cpp b696ef340bef50a59ae0a05b31b4eb34f2752d8c @@ -1,6 +1,6 @@ /************************************************* * X.509 Certificate Options Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/x509self.cpp 094994e2e470e89abf1975f722f6bfa539063e96 +++ botan/x509self.cpp 11382c4f93c3055cc2564138c9cdef0b5463caf9 @@ -1,6 +1,6 @@ /************************************************* -* X.509 Certificate Authority Source File * -* (C) 1999-2005 The Botan Project * +* PKCS #10/Self Signed Cert Creation Source File * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -128,7 +128,7 @@ if(ex_constraints.size()) { v3_ext.start_sequence(); - for(u32bit j = 0; j != ex_constraints.size(); j++) + for(u32bit j = 0; j != ex_constraints.size(); ++j) DER::encode(v3_ext, ex_constraints[j]); v3_ext.end_sequence(); do_ext(attr_encoder, v3_ext, "X509v3.ExtendedKeyUsage"); ============================================================ --- botan/x509self.h 9e92e9d4c47782f41374b1e4829f65cb51b4dd8e +++ botan/x509self.h 8b65f919952b4445af08142e3a11028c32f14ba8 @@ -1,6 +1,6 @@ /************************************************* * X.509 Self-Signed Certificate Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_X509_SELF_H__ ============================================================ --- botan/x509stor.cpp 5d4584af2b3b825022727421f15a65ef72a2ce58 +++ botan/x509stor.cpp de4a25ae8caad23ac23c10299b2a3805f2c0254d @@ -1,6 +1,6 @@ /************************************************* * X.509 Certificate Store Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include @@ -166,7 +166,7 @@ certs = store.certs; revoked = store.revoked; revoked_info_valid = store.revoked_info_valid; - for(u32bit j = 0; j != store.stores.size(); j++) + for(u32bit j = 0; j != store.stores.size(); ++j) stores[j] = store.stores[j]->clone(); } @@ -175,7 +175,7 @@ *************************************************/ X509_Store::~X509_Store() { - for(u32bit j = 0; j != stores.size(); j++) + for(u32bit j = 0; j != stores.size(); ++j) delete stores[j]; } @@ -206,7 +206,7 @@ if(is_revoked(cert)) return CERT_IS_REVOKED; - for(u32bit j = 0; j != indexes.size() - 1; j++) + for(u32bit j = 0; j != indexes.size() - 1; ++j) { const X509_Certificate& current_cert = certs[indexes[j]].cert; time_check = validity_check(current_cert.start_time(), @@ -228,7 +228,7 @@ u32bit X509_Store::find_cert(const X509_DN& subject_dn, const MemoryRegion& subject_key_id) const { - for(u32bit j = 0; j != certs.size(); j++) + for(u32bit j = 0; j != certs.size(); ++j) { const X509_Certificate& this_cert = certs[j].cert; if(compare_ids(this_cert.subject_key_id(), subject_key_id) && @@ -253,13 +253,13 @@ if(auth_key_id.size()) { - for(u32bit j = 0; j != stores.size(); j++) + for(u32bit j = 0; j != stores.size(); ++j) { std::vector got = stores[j]->by_SKID(auth_key_id); if(got.size() == 0) continue; - for(u32bit k = 0; k != got.size(); k++) + for(u32bit k = 0; k != got.size(); ++k) add_cert(got[k]); return find_cert(issuer_dn, auth_key_id); } @@ -407,7 +407,7 @@ if(revoked_info_valid) return; - for(u32bit j = 0; j != certs.size(); j++) + for(u32bit j = 0; j != certs.size(); ++j) { if((certs[j].is_verified()) && (certs[j].verify_result() != VERIFIED)) continue; @@ -441,7 +441,7 @@ X509_Store::get_certs(const Search_Func& search) const { std::vector found_certs; - for(u32bit j = 0; j != certs.size(); j++) + for(u32bit j = 0; j != certs.size(); ++j) { if(search.match(certs[j].cert)) found_certs.push_back(certs[j].cert); @@ -462,7 +462,7 @@ if(chaining_result != VERIFIED) throw Invalid_State("X509_Store::get_cert_chain: Can't construct chain"); - for(u32bit j = 0; j != indexes.size(); j++) + for(u32bit j = 0; j != indexes.size(); ++j) result.push_back(certs[indexes[j]].cert); return result; } @@ -491,7 +491,7 @@ } else if(trusted) { - for(u32bit j = 0; j != certs.size(); j++) + for(u32bit j = 0; j != certs.size(); ++j) { const X509_Certificate& this_cert = certs[j].cert; if(this_cert == cert) @@ -544,7 +544,7 @@ u32bit cert_index = NO_CERT_FOUND; - for(u32bit j = 0; j != certs.size(); j++) + for(u32bit j = 0; j != certs.size(); ++j) { const X509_Certificate& this_cert = certs[j].cert; if(compare_ids(this_cert.subject_key_id(), crl.authority_key_id())) @@ -569,7 +569,7 @@ std::vector revoked_certs = crl.get_revoked(); - for(u32bit j = 0; j != revoked_certs.size(); j++) + for(u32bit j = 0; j != revoked_certs.size(); ++j) { CRL_Data revoked_info; revoked_info.issuer = crl.issuer_dn(); @@ -603,7 +603,7 @@ std::string X509_Store::PEM_encode() const { std::string cert_store; - for(u32bit j = 0; j != certs.size(); j++) + for(u32bit j = 0; j != certs.size(); ++j) cert_store += certs[j].cert.PEM_encode(); return cert_store; } ============================================================ --- botan/x509stor.h a78774e7bde040bb909220fef6c9e5536540788d +++ botan/x509stor.h 650719caca25ed77dd3308537b453801d12e85a6 @@ -1,6 +1,6 @@ /************************************************* * X.509 Certificate Store Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_X509_CERT_STORE_H__ ============================================================ --- botan/x919_mac.h 7687240f8465f0ad5f51fb74fc246c4851f9fad6 +++ botan/x919_mac.h e60f8158e591a605b501aae9e08e49223f3811d1 @@ -1,6 +1,6 @@ /************************************************* * ANSI X9.19 MAC Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_ANSI_X919_MAC_H__ ============================================================ --- botan/x931_rng.cpp 48f15e5b870a4e1ced8dc06df188e7952feef520 +++ botan/x931_rng.cpp ee85f1d9ebc7be0d7f600386a1070641554a986c @@ -1,6 +1,6 @@ /************************************************* * ANSI X9.31 RNG Source File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #include ============================================================ --- botan/x931_rng.h 7379e614f20e55ff4bd65c3f9d40ed90d990c80e +++ botan/x931_rng.h aed7d488fbbe36d35fe8245abe44bb7d6b98ab98 @@ -1,6 +1,6 @@ /************************************************* * ANSI X9.31 RNG Header File * -* (C) 1999-2005 The Botan Project * +* (C) 1999-2006 The Botan Project * *************************************************/ #ifndef BOTAN_ANSI_X931_RNG_H__ ============================================================ --- mkstemp.cc 03865df03f56044431e1ce1e2eebb27e73e5c248 +++ mkstemp.cc 40607639286f4ffa5428bb9b6a05e7262d19ba30 @@ -42,7 +42,7 @@ tmp = tmpl.substr(0, len-6); for (i = 0; i < 6; ++i) - tmp.append(1, letters[Botan::Global_RNG::random(Botan::Nonce) % NLETTERS]); + tmp.append(1, letters[Botan::Global_RNG::random() % NLETTERS]); fd = open(tmp.c_str(), O_RDWR | O_CREAT | O_EXCL | O_BINARY, 0600); if (fd >= 0) { ============================================================ --- monotone.cc 230bf4a63ae962252dd05590b0b6263b9035ff0d +++ monotone.cc 36b0c9c0582187a7d11a9efcccfaecc9791e7596 @@ -267,7 +267,7 @@ // Set up secure memory allocation etc Botan::Init::initialize(); - Botan::set_default_allocator("malloc"); + //Botan::set_default_allocator("malloc"); // decode all argv values into a UTF-8 array