Friday, 15 December 2017
arrow Previous Versions arrow HashDigester-x 5.0.0.1 arrow baseRipemd160X.cpp (1)
baseRipemd160X.cpp (1) (base Ripemd 160 & 320 hash algorithm source code file) Print E-mail
Get C++ DiceLock cipher architecture source code packages of DiceLock for Microsoft Visual Studio 2013 and DiceLock-x for Linux with Test Driver Programs and Response Test Vector files to verify that both them work as expected.
DiceLock for Windows and Linux
DiceLock Security governing software licenses are Free/Libre Source Code License and Educational and Research License
Get FREE C++ Source Code  
Get Eclipse project and source files !!! visual-studio-2008.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
 
//
// Creator:    http://www.dicelocksecurity.com
// Version:    vers.5.0.0.1
//
// Copyright � 2009-2011 DiceLock Security, LLC. All rights reserved.
//
//                               DISCLAIMER
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// 
// DICELOCK IS A REGISTERED TRADEMARK OR TRADEMARK OF THE OWNERS.
// 
 
#include "baseRipemd160X.h"
 
 
namespace DiceLockSecurity {
  
  namespace Hash {
 
  // Constants for 160 and 320 RIPEMD algorithms
  const unsigned long int BaseRipemd160X::constant4 = 0xA953FD4EUL;
  const unsigned long int BaseRipemd160X::constant8 = 0x7A6D76E9UL;
 
  // Amounts of rotate left
  const unsigned short int BaseRipemd160X::rl_64_79[16] = {9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6};
  // Amounts of prime rotate left 
  const unsigned short int BaseRipemd160X::prime_rl_64_79[16] = {8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11};
 
  // Initial states of Ripemd 160 and 320 algorithms
  const unsigned long int BaseRipemd160X::inistate4 = 0xC3D2E1F0;
 
  // Constructor
  BaseRipemd160X::BaseRipemd160X() {
  }
 
  // Destructor
  BaseRipemd160X::~BaseRipemd160X() {
  }
 
  //  Initializes state of Ripmed 160 and 320 algorithm
  void BaseRipemd160X::Initialize() {
 
    this->BaseRipemd::Initialize();
    this->messageDigest->SetULPosition(4, inistate4);
  }
 
  // First transform set
  void BaseRipemd160X::Transform_F0(unsigned long int* a1, unsigned long int* b1, unsigned long int* c1, unsigned long int* d1, unsigned long int* e1, unsigned long int* X) {
 
    RIPEMD_Transform160X(RIPEMD_F, a1, b1, c1, d1, e1, X[ 0], this->rl_0_15[ 0], this->constant0);
    RIPEMD_Transform160X(RIPEMD_F, e1, a1, b1, c1, d1, X[ 1], this->rl_0_15[ 1], this->constant0);
    RIPEMD_Transform160X(RIPEMD_F, d1, e1, a1, b1, c1, X[ 2], this->rl_0_15[ 2], this->constant0);
    RIPEMD_Transform160X(RIPEMD_F, c1, d1, e1, a1, b1, X[ 3], this->rl_0_15[ 3], this->constant0);
    RIPEMD_Transform160X(RIPEMD_F, b1, c1, d1, e1, a1, X[ 4], this->rl_0_15[ 4], this->constant0);
    RIPEMD_Transform160X(RIPEMD_F, a1, b1, c1, d1, e1, X[ 5], this->rl_0_15[ 5], this->constant0);
    RIPEMD_Transform160X(RIPEMD_F, e1, a1, b1, c1, d1, X[ 6], this->rl_0_15[ 6], this->constant0);
    RIPEMD_Transform160X(RIPEMD_F, d1, e1, a1, b1, c1, X[ 7], this->rl_0_15[ 7], this->constant0);
    RIPEMD_Transform160X(RIPEMD_F, c1, d1, e1, a1, b1, X[ 8], this->rl_0_15[ 8], this->constant0);
    RIPEMD_Transform160X(RIPEMD_F, b1, c1, d1, e1, a1, X[ 9], this->rl_0_15[ 9], this->constant0);
    RIPEMD_Transform160X(RIPEMD_F, a1, b1, c1, d1, e1, X[10], this->rl_0_15[10], this->constant0);
    RIPEMD_Transform160X(RIPEMD_F, e1, a1, b1, c1, d1, X[11], this->rl_0_15[11], this->constant0);
    RIPEMD_Transform160X(RIPEMD_F, d1, e1, a1, b1, c1, X[12], this->rl_0_15[12], this->constant0);
    RIPEMD_Transform160X(RIPEMD_F, c1, d1, e1, a1, b1, X[13], this->rl_0_15[13], this->constant0);
    RIPEMD_Transform160X(RIPEMD_F, b1, c1, d1, e1, a1, X[14], this->rl_0_15[14], this->constant0);
    RIPEMD_Transform160X(RIPEMD_F, a1, b1, c1, d1, e1, X[15], this->rl_0_15[15], this->constant0);
  }
 
  // Second transform set
  void BaseRipemd160X::Transform_G1(unsigned long int* a1, unsigned long int* b1, unsigned long int* c1, unsigned long int* d1, unsigned long int* e1, unsigned long int* X) {
 
    RIPEMD_Transform160X(RIPEMD_G, e1, a1, b1, c1, d1, X[ 7], this->rl_16_31[ 0], this->constant1);
    RIPEMD_Transform160X(RIPEMD_G, d1, e1, a1, b1, c1, X[ 4], this->rl_16_31[ 1], this->constant1);
    RIPEMD_Transform160X(RIPEMD_G, c1, d1, e1, a1, b1, X[13], this->rl_16_31[ 2], this->constant1);
    RIPEMD_Transform160X(RIPEMD_G, b1, c1, d1, e1, a1, X[ 1], this->rl_16_31[ 3], this->constant1);
    RIPEMD_Transform160X(RIPEMD_G, a1, b1, c1, d1, e1, X[10], this->rl_16_31[ 4], this->constant1);
    RIPEMD_Transform160X(RIPEMD_G, e1, a1, b1, c1, d1, X[ 6], this->rl_16_31[ 5], this->constant1);
    RIPEMD_Transform160X(RIPEMD_G, d1, e1, a1, b1, c1, X[15], this->rl_16_31[ 6], this->constant1);
    RIPEMD_Transform160X(RIPEMD_G, c1, d1, e1, a1, b1, X[ 3], this->rl_16_31[ 7], this->constant1);
    RIPEMD_Transform160X(RIPEMD_G, b1, c1, d1, e1, a1, X[12], this->rl_16_31[ 8], this->constant1);
    RIPEMD_Transform160X(RIPEMD_G, a1, b1, c1, d1, e1, X[ 0], this->rl_16_31[ 9], this->constant1);
    RIPEMD_Transform160X(RIPEMD_G, e1, a1, b1, c1, d1, X[ 9], this->rl_16_31[10], this->constant1);
    RIPEMD_Transform160X(RIPEMD_G, d1, e1, a1, b1, c1, X[ 5], this->rl_16_31[11], this->constant1);
    RIPEMD_Transform160X(RIPEMD_G, c1, d1, e1, a1, b1, X[ 2], this->rl_16_31[12], this->constant1);
    RIPEMD_Transform160X(RIPEMD_G, b1, c1, d1, e1, a1, X[14], this->rl_16_31[13], this->constant1);
    RIPEMD_Transform160X(RIPEMD_G, a1, b1, c1, d1, e1, X[11], this->rl_16_31[14], this->constant1);
    RIPEMD_Transform160X(RIPEMD_G, e1, a1, b1, c1, d1, X[ 8], this->rl_16_31[15], this->constant1);
  }
 
  // Third transform set
  void BaseRipemd160X::Transform_H2(unsigned long int* a1, unsigned long int* b1, unsigned long int* c1, unsigned long int* d1, unsigned long int* e1, unsigned long int* X) {
 
    RIPEMD_Transform160X(RIPEMD_H, d1, e1, a1, b1, c1, X[ 3], this->rl_32_47[ 0], this->constant2);
    RIPEMD_Transform160X(RIPEMD_H, c1, d1, e1, a1, b1, X[10], this->rl_32_47[ 1], this->constant2);
    RIPEMD_Transform160X(RIPEMD_H, b1, c1, d1, e1, a1, X[14], this->rl_32_47[ 2], this->constant2);
    RIPEMD_Transform160X(RIPEMD_H, a1, b1, c1, d1, e1, X[ 4], this->rl_32_47[ 3], this->constant2);
    RIPEMD_Transform160X(RIPEMD_H, e1, a1, b1, c1, d1, X[ 9], this->rl_32_47[ 4], this->constant2);
    RIPEMD_Transform160X(RIPEMD_H, d1, e1, a1, b1, c1, X[15], this->rl_32_47[ 5], this->constant2);
    RIPEMD_Transform160X(RIPEMD_H, c1, d1, e1, a1, b1, X[ 8], this->rl_32_47[ 6], this->constant2);
    RIPEMD_Transform160X(RIPEMD_H, b1, c1, d1, e1, a1, X[ 1], this->rl_32_47[ 7], this->constant2);
    RIPEMD_Transform160X(RIPEMD_H, a1, b1, c1, d1, e1, X[ 2], this->rl_32_47[ 8], this->constant2);
    RIPEMD_Transform160X(RIPEMD_H, e1, a1, b1, c1, d1, X[ 7], this->rl_32_47[ 9], this->constant2);
    RIPEMD_Transform160X(RIPEMD_H, d1, e1, a1, b1, c1, X[ 0], this->rl_32_47[10], this->constant2);
    RIPEMD_Transform160X(RIPEMD_H, c1, d1, e1, a1, b1, X[ 6], this->rl_32_47[11], this->constant2);
    RIPEMD_Transform160X(RIPEMD_H, b1, c1, d1, e1, a1, X[13], this->rl_32_47[12], this->constant2);
    RIPEMD_Transform160X(RIPEMD_H, a1, b1, c1, d1, e1, X[11], this->rl_32_47[13], this->constant2);
    RIPEMD_Transform160X(RIPEMD_H, e1, a1, b1, c1, d1, X[ 5], this->rl_32_47[14], this->constant2);
    RIPEMD_Transform160X(RIPEMD_H, d1, e1, a1, b1, c1, X[12], this->rl_32_47[15], this->constant2);
  }
 
  // Fourth transform set
  void BaseRipemd160X::Transform_I3(unsigned long int* a1, unsigned long int* b1, unsigned long int* c1, unsigned long int* d1, unsigned long int* e1, unsigned long int* X) {
 
    RIPEMD_Transform160X(RIPEMD_I, c1, d1, e1, a1, b1, X[ 1], this->rl_48_63[ 0], this->constant3);
    RIPEMD_Transform160X(RIPEMD_I, b1, c1, d1, e1, a1, X[ 9], this->rl_48_63[ 1], this->constant3);
    RIPEMD_Transform160X(RIPEMD_I, a1, b1, c1, d1, e1, X[11], this->rl_48_63[ 2], this->constant3);
    RIPEMD_Transform160X(RIPEMD_I, e1, a1, b1, c1, d1, X[10], this->rl_48_63[ 3], this->constant3);
    RIPEMD_Transform160X(RIPEMD_I, d1, e1, a1, b1, c1, X[ 0], this->rl_48_63[ 4], this->constant3);
    RIPEMD_Transform160X(RIPEMD_I, c1, d1, e1, a1, b1, X[ 8], this->rl_48_63[ 5], this->constant3);
    RIPEMD_Transform160X(RIPEMD_I, b1, c1, d1, e1, a1, X[12], this->rl_48_63[ 6], this->constant3);
    RIPEMD_Transform160X(RIPEMD_I, a1, b1, c1, d1, e1, X[ 4], this->rl_48_63[ 7], this->constant3);
    RIPEMD_Transform160X(RIPEMD_I, e1, a1, b1, c1, d1, X[13], this->rl_48_63[ 8], this->constant3);
    RIPEMD_Transform160X(RIPEMD_I, d1, e1, a1, b1, c1, X[ 3], this->rl_48_63[ 9], this->constant3);
    RIPEMD_Transform160X(RIPEMD_I, c1, d1, e1, a1, b1, X[ 7], this->rl_48_63[10], this->constant3);
    RIPEMD_Transform160X(RIPEMD_I, b1, c1, d1, e1, a1, X[15], this->rl_48_63[11], this->constant3);
    RIPEMD_Transform160X(RIPEMD_I, a1, b1, c1, d1, e1, X[14], this->rl_48_63[12], this->constant3);
    RIPEMD_Transform160X(RIPEMD_I, e1, a1, b1, c1, d1, X[ 5], this->rl_48_63[13], this->constant3);
    RIPEMD_Transform160X(RIPEMD_I, d1, e1, a1, b1, c1, X[ 6], this->rl_48_63[14], this->constant3);
    RIPEMD_Transform160X(RIPEMD_I, c1, d1, e1, a1, b1, X[ 2], this->rl_48_63[15], this->constant3);
  }