Fabcoin Core  0.16.2
P2P Digital Currency
words.h
Go to the documentation of this file.
1 #ifndef CRYPTOPP_WORDS_H
2 #define CRYPTOPP_WORDS_H
3 
4 #include "config.h"
5 #include "misc.h"
6 
8 
9 inline size_t CountWords(const word *X, size_t N)
10 {
11  while (N && X[N-1]==0)
12  N--;
13  return N;
14 }
15 
16 inline void SetWords(word *r, word a, size_t n)
17 {
18  for (size_t i=0; i<n; i++)
19  r[i] = a;
20 }
21 
22 inline void CopyWords(word *r, const word *a, size_t n)
23 {
24  if (r != a)
25 #if CRYPTOPP_MSC_VERSION
26  memcpy_s(r, n*WORD_SIZE, a, n*WORD_SIZE);
27 #else
28  memcpy(r, a, n*WORD_SIZE);
29 #endif
30 }
31 
32 inline void XorWords(word *r, const word *a, const word *b, size_t n)
33 {
34  for (size_t i=0; i<n; i++)
35  r[i] = a[i] ^ b[i];
36 }
37 
38 inline void XorWords(word *r, const word *a, size_t n)
39 {
40  for (size_t i=0; i<n; i++)
41  r[i] ^= a[i];
42 }
43 
44 inline void AndWords(word *r, const word *a, const word *b, size_t n)
45 {
46  for (size_t i=0; i<n; i++)
47  r[i] = a[i] & b[i];
48 }
49 
50 inline void AndWords(word *r, const word *a, size_t n)
51 {
52  for (size_t i=0; i<n; i++)
53  r[i] &= a[i];
54 }
55 
56 inline void OrWords(word *r, const word *a, const word *b, size_t n)
57 {
58  for (size_t i=0; i<n; i++)
59  r[i] = a[i] | b[i];
60 }
61 
62 inline void OrWords(word *r, const word *a, size_t n)
63 {
64  for (size_t i=0; i<n; i++)
65  r[i] |= a[i];
66 }
67 
68 inline word ShiftWordsLeftByBits(word *r, size_t n, unsigned int shiftBits)
69 {
70  CRYPTOPP_ASSERT (shiftBits<WORD_BITS);
71  word u, carry=0;
72  if (shiftBits)
73  for (size_t i=0; i<n; i++)
74  {
75  u = r[i];
76  r[i] = (u << shiftBits) | carry;
77  carry = u >> (WORD_BITS-shiftBits);
78  }
79  return carry;
80 }
81 
82 inline word ShiftWordsRightByBits(word *r, size_t n, unsigned int shiftBits)
83 {
84  CRYPTOPP_ASSERT (shiftBits<WORD_BITS);
85  word u, carry=0;
86  if (shiftBits)
87  for (size_t i=n; i>0; i--)
88  {
89  u = r[i-1];
90  r[i-1] = (u >> shiftBits) | carry;
91  carry = u << (WORD_BITS-shiftBits);
92  }
93  return carry;
94 }
95 
96 inline void ShiftWordsLeftByWords(word *r, size_t n, size_t shiftWords)
97 {
98  shiftWords = STDMIN(shiftWords, n);
99  if (shiftWords)
100  {
101  for (size_t i=n-1; i>=shiftWords; i--)
102  r[i] = r[i-shiftWords];
103  SetWords(r, 0, shiftWords);
104  }
105 }
106 
107 inline void ShiftWordsRightByWords(word *r, size_t n, size_t shiftWords)
108 {
109  shiftWords = STDMIN(shiftWords, n);
110  if (shiftWords)
111  {
112  for (size_t i=0; i+shiftWords<n; i++)
113  r[i] = r[i+shiftWords];
114  SetWords(r+n-shiftWords, 0, shiftWords);
115  }
116 }
117 
119 
120 #endif
void CopyWords(word *r, const word *a, size_t n)
Definition: words.h:22
Utility functions for the Crypto++ library.
size_t CountWords(const word *X, size_t N)
Definition: words.h:9
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t count)
Bounds checking replacement for memcpy()
Definition: misc.h:366
Library configuration file.
#define a(i)
void ShiftWordsLeftByWords(word *r, size_t n, size_t shiftWords)
Definition: words.h:96
const unsigned int WORD_BITS
Definition: config.h:317
void SetWords(word *r, word a, size_t n)
Definition: words.h:16
void ShiftWordsRightByWords(word *r, size_t n, size_t shiftWords)
Definition: words.h:107
const unsigned int WORD_SIZE
Definition: config.h:316
#define b(i, j)
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
Definition: misc.h:477
#define CRYPTOPP_ASSERT(exp)
Definition: trap.h:92
#define X(name)
Definition: net.cpp:642
void XorWords(word *r, const word *a, const word *b, size_t n)
Definition: words.h:32
void * memcpy(void *a, const void *b, size_t c)
word ShiftWordsRightByBits(word *r, size_t n, unsigned int shiftBits)
Definition: words.h:82
#define NAMESPACE_END
Definition: config.h:201
word ShiftWordsLeftByBits(word *r, size_t n, unsigned int shiftBits)
Definition: words.h:68
void OrWords(word *r, const word *a, const word *b, size_t n)
Definition: words.h:56
word32 word
Definition: config.h:308
void AndWords(word *r, const word *a, const word *b, size_t n)
Definition: words.h:44