aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/math
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-03-19 11:00:50 -0400
committerJack Lloyd <[email protected]>2018-03-20 09:36:40 -0400
commit737f33c09a18500e044dca3e2ae13bd2c08bafdd (patch)
tree95b8ae5d2750e1e78dd0e500c33c8c103e8bf42c /src/lib/math
parentb08f7beb877569fd94736c5a67b9e28fcdd968b6 (diff)
Store base point multiplies in a single std::vector
Since the point is public all the values are also, so this reduces pressure on the mlock allocator and may (slightly) help perf through cache read-ahead. Downside is cache based side channels are slightly easier (vs the data being stored in discontigious vectors). But we shouldn't rely on that in any case. And having it be in an array makes a masked table lookup easier to arrange.
Diffstat (limited to 'src/lib/math')
-rw-r--r--src/lib/math/bigint/bigint.cpp11
-rw-r--r--src/lib/math/bigint/bigint.h6
2 files changed, 17 insertions, 0 deletions
diff --git a/src/lib/math/bigint/bigint.cpp b/src/lib/math/bigint/bigint.cpp
index a722e0e4b..a42707e07 100644
--- a/src/lib/math/bigint/bigint.cpp
+++ b/src/lib/math/bigint/bigint.cpp
@@ -118,6 +118,17 @@ int32_t BigInt::cmp(const BigInt& other, bool check_signs) const
other.data(), other.sig_words());
}
+void BigInt::encode_words(word out[], size_t size) const
+ {
+ const size_t words = sig_words();
+
+ if(words > size)
+ throw Encoding_Error("BigInt::encode_words value too large to encode");
+
+ clear_mem(out, size);
+ copy_mem(out, data(), words);
+ }
+
/*
* Return bits {offset...offset+length}
*/
diff --git a/src/lib/math/bigint/bigint.h b/src/lib/math/bigint/bigint.h
index ba17d7ede..3f0eb8523 100644
--- a/src/lib/math/bigint/bigint.h
+++ b/src/lib/math/bigint/bigint.h
@@ -537,6 +537,12 @@ class BOTAN_PUBLIC_API(2,0) BigInt final
size_t encoded_size(Base base = Binary) const;
/**
+ * Place the value into out, zero-padding up to size words
+ * Throw if *this cannot be represented in size words
+ */
+ void encode_words(word out[], size_t size) const;
+
+ /**
* @param rng a random number generator
* @param min the minimum value
* @param max the maximum value