Skip to content

Commit ddadf51

Browse files
committed
Use size_t for lengths to allow use on x86 platforms.
1 parent 2e59f42 commit ddadf51

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

source/secured/kdf.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ unittest
150150
assert(toHexString!(LetterCase.lower)(vec3) == "d1aacafea3a9fdf3ee6236b1b45527974ea01539b4a7cc493bba56e15e14d520");
151151
}
152152

153-
@safe public KdfResult hkdf(const ubyte[] key, ulong outputLen) {
153+
@safe public KdfResult hkdf(const ubyte[] key, size_t outputLen) {
154154
KdfResult result;
155155
result.salt = random(getHashLength(HashAlgorithm.SHA2_384));
156156
result.key = hkdf_ex(key, result.salt, string.init, outputLen, HashAlgorithm.SHA2_384);
157157
return result;
158158
}
159159

160-
@trusted public ubyte[] hkdf_ex(const ubyte[] key, const ubyte[] salt, string info, ulong outputLen, HashAlgorithm func) {
160+
@trusted public ubyte[] hkdf_ex(const ubyte[] key, const ubyte[] salt, string info, size_t outputLen, HashAlgorithm func) {
161161
if (key.length == 0) {
162162
throw new CryptographicException("HKDF key cannot be an empty array.");
163163
}
@@ -232,12 +232,12 @@ unittest
232232
return result;
233233
}
234234

235-
@trusted public ubyte[] scrypt_ex(string password, const ubyte[] salt, ulong n, ulong r, ulong p, ulong maxMemory, ulong length) {
235+
@trusted public ubyte[] scrypt_ex(string password, const ubyte[] salt, ulong n, ulong r, ulong p, ulong maxMemory, size_t length) {
236236
import std.string;
237237
return scrypt_ex(cast(ubyte[])password.representation, salt, n, r, p, maxMemory, length);
238238
}
239239

240-
@trusted public ubyte[] scrypt_ex(const ubyte[] password, const ubyte[] salt, ulong n, ulong r, ulong p, ulong maxMemory, ulong length) {
240+
@trusted public ubyte[] scrypt_ex(const ubyte[] password, const ubyte[] salt, ulong n, ulong r, ulong p, ulong maxMemory, size_t length) {
241241
ubyte[] hash = new ubyte[length];
242242

243243
if (EVP_PBE_scrypt((cast(char[])password).ptr, password.length, salt.ptr, salt.length, n, r, p, maxMemory, hash.ptr, length) <= 0) {

source/secured/symmetric.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public immutable struct CryptoBlockHeader {
109109
this.encryptedLength = cast(immutable)bytes.read!uint();
110110
}
111111

112-
@safe public @property ulong getBlockLength() {
112+
@safe public @property size_t getBlockLength() {
113113
const uint saltLen = getHashLength(this.hash);
114114
const uint ivLen = getCipherIVLength(this.symmetric);
115115
const uint authLen = getAuthLength(this.symmetric, this.hash);
@@ -208,11 +208,11 @@ private immutable struct CryptoBlock {
208208
const ushort chunks = to!ushort(floor(tcc)+1);
209209

210210
CryptoBlock[] blocks;
211-
ulong processed = 0;
212-
ulong totalSize = additional.length;
211+
size_t processed = 0;
212+
size_t totalSize = additional.length;
213213
for(ushort i = 0; i < chunks; i++) {
214214
//Prepare data for encryption
215-
const ulong chunkLen = (data.length-processed) >= chunkSize ? chunkSize : (data.length-processed);
215+
const size_t chunkLen = (data.length-processed) >= chunkSize ? chunkSize : (data.length-processed);
216216
const ubyte[] ad = (chunkLen < chunkSize) ? additional : null;
217217
const ubyte[] ep = data[processed..processed+chunkLen];
218218
ubyte[] iv = random(getCipherIVLength(symmetric));

0 commit comments

Comments
 (0)