summaryrefslogtreecommitdiff
path: root/words.h
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2002-10-04 17:31:41 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2002-10-04 17:31:41 +0000
commitb21162cf8e06f40baa1f58be6a8c17435cebc34d (patch)
tree8b045309c238226c32a563b1df6b9c30a2f0e0b3 /words.h
downloadcryptopp-b21162cf8e06f40baa1f58be6a8c17435cebc34d.tar.gz
Initial revision
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@2 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'words.h')
-rw-r--r--words.h103
1 files changed, 103 insertions, 0 deletions
diff --git a/words.h b/words.h
new file mode 100644
index 0000000..8849b61
--- /dev/null
+++ b/words.h
@@ -0,0 +1,103 @@
+#ifndef CRYPTOPP_WORDS_H
+#define CRYPTOPP_WORDS_H
+
+#include "misc.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+inline unsigned int CountWords(const word *X, unsigned int N)
+{
+ while (N && X[N-1]==0)
+ N--;
+ return N;
+}
+
+inline void SetWords(word *r, word a, unsigned int n)
+{
+ for (unsigned int i=0; i<n; i++)
+ r[i] = a;
+}
+
+inline void CopyWords(word *r, const word *a, unsigned int n)
+{
+ for (unsigned int i=0; i<n; i++)
+ r[i] = a[i];
+}
+
+inline void XorWords(word *r, const word *a, const word *b, unsigned int n)
+{
+ for (unsigned int i=0; i<n; i++)
+ r[i] = a[i] ^ b[i];
+}
+
+inline void XorWords(word *r, const word *a, unsigned int n)
+{
+ for (unsigned int i=0; i<n; i++)
+ r[i] ^= a[i];
+}
+
+inline void AndWords(word *r, const word *a, const word *b, unsigned int n)
+{
+ for (unsigned int i=0; i<n; i++)
+ r[i] = a[i] & b[i];
+}
+
+inline void AndWords(word *r, const word *a, unsigned int n)
+{
+ for (unsigned int i=0; i<n; i++)
+ r[i] &= a[i];
+}
+
+inline word ShiftWordsLeftByBits(word *r, unsigned int n, unsigned int shiftBits)
+{
+ assert (shiftBits<WORD_BITS);
+ word u, carry=0;
+ if (shiftBits)
+ for (unsigned int i=0; i<n; i++)
+ {
+ u = r[i];
+ r[i] = (u << shiftBits) | carry;
+ carry = u >> (WORD_BITS-shiftBits);
+ }
+ return carry;
+}
+
+inline word ShiftWordsRightByBits(word *r, unsigned int n, unsigned int shiftBits)
+{
+ assert (shiftBits<WORD_BITS);
+ word u, carry=0;
+ if (shiftBits)
+ for (int i=n-1; i>=0; i--)
+ {
+ u = r[i];
+ r[i] = (u >> shiftBits) | carry;
+ carry = u << (WORD_BITS-shiftBits);
+ }
+ return carry;
+}
+
+inline void ShiftWordsLeftByWords(word *r, unsigned int n, unsigned int shiftWords)
+{
+ shiftWords = STDMIN(shiftWords, n);
+ if (shiftWords)
+ {
+ for (unsigned int i=n-1; i>=shiftWords; i--)
+ r[i] = r[i-shiftWords];
+ SetWords(r, 0, shiftWords);
+ }
+}
+
+inline void ShiftWordsRightByWords(word *r, unsigned int n, unsigned int shiftWords)
+{
+ shiftWords = STDMIN(shiftWords, n);
+ if (shiftWords)
+ {
+ for (unsigned int i=0; i+shiftWords<n; i++)
+ r[i] = r[i+shiftWords];
+ SetWords(r+n-shiftWords, 0, shiftWords);
+ }
+}
+
+NAMESPACE_END
+
+#endif