aboutsummaryrefslogtreecommitdiffstats
path: root/src/math/bigint
Commit message (Collapse)AuthorAgeFilesLines
* propagate from branch 'net.randombit.botan' (head ↵lloyd2011-06-132-1/+29
|\ | | | | | | | | | | 150bd11dd8090559ee1e83394b8283bf93a018de) to branch 'net.randombit.botan.c++0x' (head 7480693bb3f1e8a4e039a3e7ba3d9a7007f9730e)
| * propagate from branch 'net.randombit.botan' (head ↵lloyd2011-02-112-1/+29
| |\ | | | | | | | | | | | | | | | 13a0d36dac3709f3cb88e830ed7f8cab9e7433ab) to branch 'net.randombit.botan.c++0x' (head 2221ad8796466e7e096645de77ba856a9c902d14)
| | * propagate from branch 'net.randombit.botan' (head ↵lloyd2010-11-042-1/+29
| | |\ | | | | | | | | | | | | | | | | | | | | 303b2518a80553214b1e5ab4d9b96ef54629cbc7) to branch 'net.randombit.botan.c++0x' (head d734eefabe4816be4dd3e3e6e7bb13b7ab5be148)
| | | * propagate from branch 'net.randombit.botan' (head ↵lloyd2010-10-282-4/+4
| | | |\ | | | | | | | | | | | | | | | | | | | | | | | | | 2841fb518e20d2fe0a374e4f6b08bdbb14d5d158) to branch 'net.randombit.botan.c++0x' (head 0b9275139d6346bd3aa28d63bf8b8a03851d853d)
| | | * \ propagate from branch 'net.randombit.botan' (head ↵lloyd2010-10-132-1/+29
| | | |\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 2898d79f992f27a328a3e41d34b46eb1052da0de) to branch 'net.randombit.botan.c++0x' (head 6cba76268fd69a73195760c021b7f881b8a6552c)
| | | | * \ propagate from branch 'net.randombit.botan' (head ↵lloyd2010-09-032-1/+29
| | | | |\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | a29c41b4a949207b1544096c3afab668f8b5179e) to branch 'net.randombit.botan.c++0x' (head a9d0c2f805b3c20a4c648575d7256959db8329fe)
| | | | | * \ propagate from branch 'net.randombit.botan' (head ↵lloyd2010-08-132-1/+29
| | | | | |\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 0a3348f52bf558bc2282e1066c2913a72a1aeda5) to branch 'net.randombit.botan.c++0x' (head 552c20ae8874f12da779fc25ea368e36e71cbfe8)
| | | | | | * \ propagate from branch 'net.randombit.botan' (head ↵lloyd2010-07-092-1/+29
| | | | | | |\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 161b5c0300b72baa746f101fda1e2b4a7c71818c) to branch 'net.randombit.botan.c++0x' (head 1fc3875bb8daf4ad0e90ba66db72642203cb9984)
| | | | | | | * \ propagate from branch 'net.randombit.botan' (head ↵lloyd2010-06-177-75/+186
| | | | | | | |\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 294e2082ce9231d6165276e2f2a4153a0116aca3) to branch 'net.randombit.botan.c++0x' (head 0b695fad10f924601e07b009fcd781191fafcb28)
| | | | | | | * \ \ propagate from branch 'net.randombit.botan' (head ↵lloyd2010-03-212-4/+36
| | | | | | | |\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 96d0a1885774b624812fd143d541c8bcda319217) to branch 'net.randombit.botan.c++0x' (head e14368ab9d7976f3e111c6bc0adf24eebeb7c114)
| | | | | | | | * \ \ propagate from branch 'net.randombit.botan' (head ↵lloyd2010-03-132-4/+36
| | | | | | | | |\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 5e9c6107cbb15744c2edf2eb0e23f4bfe949f432) to branch 'net.randombit.botan.c++0x' (head 79e5920a8bba479b9e5734f8649b8c36d27d403c)
| | | | | | | | | * \ \ propagate from branch 'net.randombit.botan' (head ↵lloyd2010-02-142-4/+36
| | | | | | | | | |\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 5bfc3e699003b86615c584f8ae40bd6e761f96c0) to branch 'net.randombit.botan.c++0x' (head 8c64a107b58d41f376bfffc69dfab4514d722c5c)
| | | | | | | | | | * \ \ propagate from branch 'net.randombit.botan' (head ↵lloyd2009-12-212-4/+36
| | | | | | | | | | |\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 14c1d4dc8696d2705a70ec3d2403e01d2ca95265) to branch 'net.randombit.botan.c++0x' (head c567fa7310ba082a837562092728c4b4b882bf82)
| | | | | | | | | | | * \ \ propagate from branch 'net.randombit.botan' (head ↵lloyd2009-12-1631-62/+68
| | | | | | | | | | | |\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 744dccf92270cf16b80b50ee2759424c9866b256) to branch 'net.randombit.botan.c++0x' (head 2aa1acac1d05e8ea9991fe39015b1db9abc3b24e)
| | | | | | | | | | | * | | | Define move assignment and constructors in terms of std::swap (whichlloyd2009-11-191-6/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | boils down to BigInt::swap, which uses the memvec swap). Checking with g++ 4.5 -O3 shows it compiles down the same code as before.
| | | | | | | | | | | * | | | Add move assignment and constructor operators to BigInt. On macro benchmarkslloyd2009-11-192-4/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (timing the test suite) there doesn't seem to be much of a difference either way, but putting printfs in the implementations shows they are being used. Since they pretty much can't possibly hurt (right?) and might well help a lot in certain cases, it's worth including. Todo: adding overloads to binary operators taking move operations might be nice. Details in http://cpp-next.com/archive/2009/09/making-your-next-move/
* | | | | | | | | | | | | | | Add base64_decode. Seems to work OK, though incremental decoding islloyd2011-05-121-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | not well tested.
* | | | | | | | | | | | | | | Add back BigInt::to_u32bitlloyd2011-05-102-17/+45
|/ / / / / / / / / / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix BigInt::get_substring when length is equal to 32 - an overflow would cause the mask to be equal to 0 thus producing nothing at all. Disable CVC by default, it's not ready for prime time in any sense.
* / / / / / / / / / / / / / More VC warning fixeslloyd2011-02-091-2/+4
|/ / / / / / / / / / / / /
* | | | | | | | | | | | / Make MemoryRegion::set protected, change all callerslloyd2010-10-291-0/+9
| |_|_|_|_|_|_|_|_|_|_|/ |/| | | | | | | | | | |
* | | | | | | | | | | | BigInt::get_substring really shouldn't return size_t. Revert tolloyd2010-10-182-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | u32bit. Maybe should be word? But that would restrict window sizes more than might be desirable (we couldn't use more than 8 bit window on the assumption that the lib might be using byte limbs). Messy.
* | | | | | | | | | | | For const BigInt::operator[], return a const reference instead of alloyd2010-10-181-1/+1
|/ / / / / / / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | value, so you can always safely capture the result by a const reference.
* | | | | | | | | | | Use size_t in all of math, remove to_u32bitlloyd2010-10-128-136/+111
| | | | | | | | | | |
* | | | | | | | | | | At some point I 'simplified' the divide code to always run thelloyd2010-09-261-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | division algorithm unless x == y, but this could result in n - t + 1 being negative which would cause an attempt to allocate about 4 gigabytes of memory. Fix this, and also add an assertion check in the code to ensure that can't happen in any other way. Never reproduced this with 32 bit digits but it would show up if the build used 8 or 16 bit words.
* | | | | | | | | | | Move the core MPI functions to src/math/mp, leaving src/math/bigint justlloyd2010-09-2427-3742/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | for the implementation of the BigInt class
* | | | | | | | | | | Delete obsolete asm versionslloyd2010-09-247-781/+0
| | | | | | | | | | |
* | | | | | | | | | | Minor performance tweak, avoid zeroing things we'll immediately writelloyd2010-09-241-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | to. Helps more than I would have thought.
* | | | | | | | | | | Modify bigint_monty_redc to take an additional workspace argument.lloyd2010-09-242-27/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Modify it to avoid a timing condition during the compare at the end; this is done by always doing the subtraction, and then copying to the output either the pre-subtraction or post-subtraction value depending on if the final borrow was set or not.
* | | | | | | | | | | s/carry/borrow/ in subtraction routineslloyd2010-09-241-14/+18
| | | | | | | | | | |
* | | | | | | | | | | s/j/i for loop variableslloyd2010-09-241-36/+36
| | | | | | | | | | |
* | | | | | | | | | | Cleanuplloyd2010-09-232-16/+24
| | | | | | | | | | |
* | | | | | | | | | | Make these functions mostly constant-time, and in particular notlloyd2010-09-231-29/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | depending on the value of the final carry out for anything control-flow related.
* | | | | | | | | | | Update all uses of MemoryRegion::append to use either push_back or operator+=lloyd2010-09-151-4/+3
| | | | | | | | | | |
* | | | | | | | | | | More changes to avoid vector to pointer implicit conversionslloyd2010-09-142-6/+6
| | | | | | | | | | |
* | | | | | | | | | | More vector->pointer conversion removals.lloyd2010-09-131-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add RandomNumberGenerator::random_vec, which takes an length n and returns a new SecureVector with randomized contents of that size. This nicely covers most of the cases where randomize was being called on a vector, and is a little cleaner in the code as well, instead of vec.resize(length); rng.randomize(&vec[0], vec.size()); we just write vec = rng.random_vec(length);
* | | | | | | | | | | Anywhere where we use MemoryRegion::begin to get access to the raw pointerlloyd2010-09-133-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | representation (rather than in an interator context), instead use &buf[0], which works for both MemoryRegion and std::vector
* | | | | | | | | | | Big, invasive but mostly automated change, with a further attempt atlloyd2010-09-073-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | harmonising MemoryRegion with std::vector: The MemoryRegion::clear() function would zeroise the buffer, but keep the memory allocated and the size unchanged. This is very different from STL's clear(), which is basically the equivalent to what is called destroy() in MemoryRegion. So to be able to replace MemoryRegion with a std::vector, we have to rename destroy() to clear() and we have to expose the current functionality of clear() in some other way, since vector doesn't support this operation. Do so by adding a global function named zeroise() which takes a MemoryRegion which is zeroed. Remove clear() to ensure all callers are updated.
* | | | | | | | | | | Realization while thinking about the recently added truncate: in a STLlloyd2010-09-072-5/+5
|/ / / / / / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | container like vector, truncate is simply resize, but what MemoryRegion called resize will zap the entire contents, and then what was resize was called grow_to. This is really problematic in terms of the goal of replacing MemoryRegion with a vector with a custom allocator. In this checkin: - Remove MemoryRegion::grow_to and MemoryRegion::truncate - Change the semantics of MemoryRegion::resize to change the size while keeping any current contents intact (up to the new size), zero initializing any new values. Unrelated, just noticed the lack while I was in there, add a version of CryptoBox::decrypt taking a std::string for the input.
* | | | | | | | | | Update some callers that were using Hex_Encoder or Hex_Decoder butlloyd2010-09-031-15/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | really didn't need to. The ones in symkey and big_code were actually calling accessor functions to do the encoding themselves without a Pipe (should have definitely recognized that as a code smell). These versions have changed semantically with this checkin - previously they would completely ignore bad inputs, but now invalid inputs are rejected. For instance, you cannot say SymmetricKey key("Only some of this is hex, most of it isn't"); And expect to get a valid key formed by filtering out the non-hex characters and then decoding it. This is almost certainly a good thing. Also fix include in Botan.xs
* | | | | | | | | | Interesting factoid, turns out that overloading std::swap is notlloyd2010-09-021-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | allowed by the standard, however specializing it is. Fix this for BigInt; it appears the Flexsecure guys knew this since the CurveGFp and PointGFp classes already uses the template specialization rather than an overload.
* | | | | | | | | | Rename mp_amd64_msvc to mp_msvc64 since it supports both AMD64 andlloyd2010-08-253-2/+2
|/ / / / / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | IA-64 (and, hypothetically, any other 64 bit CPU Visual C++ might target in the future).
* | | | | | | | | Also allow clang with 32-bit assembly code, everything seems to worklloyd2010-08-081-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fine with latest SVN.
* | | | | | | | | Clang understands at least some GCC inline asm syntax as well as whatlloyd2010-08-081-0/+1
|/ / / / / / / / | | | | | | | | | | | | | | | | | | | | | | | | an .S file is, so allow it for x86-64. Tested/works with Clang SVN.
* | | | | | | / Make round_up and round_down templates instead of fixed to use u32bitslloyd2010-06-291-5/+5
| |_|_|_|_|_|/ |/| | | | | |
* | | | | | | Use mode(TI) operations to get access to MIPS 64-bit multiply.lloyd2010-06-171-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Required after GCC 4.4
* | | | | | | Doxygen for divide.hlloyd2010-06-161-1/+11
| | | | | | |
* | | | | | | More Doxygen updates. Also, don't expose divide() in numthry.hlloyd2010-06-161-26/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | anymore, only in divide.h
* | | | | | | More BigInt Doxygen comment updateslloyd2010-06-161-19/+20
| | | | | | |
* | | | | | | Cleanup some BigInt doxygen commentslloyd2010-06-161-31/+44
| | | | | | |
* | | | | | | Replace "@return a blah" and "@return the blah" with just "@return blah"lloyd2010-06-161-2/+2
| | | | | | |