32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
40 #if (SHA_CRYPT_SUPPORT == ENABLED)
43 static const char_t base64EncTable[64] =
45 '.',
'/',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
46 'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
47 'U',
'V',
'W',
'X',
'Y',
'Z',
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
48 'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z'
77 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
84 if(hashAlgo == NULL || password == NULL || salt == NULL || output == NULL)
151 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
155 if(hashContext == NULL)
160 hashAlgo->
init(&hashContext[0]);
162 hashAlgo->
update(&hashContext[0], password, passwordLen);
164 hashAlgo->
update(&hashContext[0], salt, saltLen);
167 hashAlgo->
init(&hashContext[1]);
169 hashAlgo->
update(&hashContext[1], password, passwordLen);
171 hashAlgo->
update(&hashContext[1], salt, saltLen);
173 hashAlgo->
update(&hashContext[1], password, passwordLen);
175 hashAlgo->
final(&hashContext[1], digest);
180 for(j = 0; j < passwordLen; j +=
n)
183 hashAlgo->
update(&hashContext[0], digest,
n);
189 for(
n = passwordLen;
n > 0;
n >>= 1)
200 hashAlgo->
update(&hashContext[0], password, passwordLen);
205 hashAlgo->
final(&hashContext[0], digest);
208 hashAlgo->
init(&hashContext[1]);
211 for(j = 0; j < passwordLen; j++)
214 hashAlgo->
update(&hashContext[1], password, passwordLen);
218 hashAlgo->
final(&hashContext[1], dp);
221 hashAlgo->
init(&hashContext[1]);
225 for(j = 0; j < (digest[0] + 16U); j++)
228 hashAlgo->
update(&hashContext[1], salt, saltLen);
232 hashAlgo->
final(&hashContext[1], ds);
236 for(i = 0; i < rounds; i++)
239 hashAlgo->
init(&hashContext[0]);
245 for(j = 0; j < passwordLen; j +=
n)
251 hashAlgo->
update(&hashContext[0], dp,
n);
264 for(j = 0; j < saltLen; j +=
n)
270 hashAlgo->
update(&hashContext[0], ds,
n);
278 for(j = 0; j < passwordLen; j +=
n)
284 hashAlgo->
update(&hashContext[0], dp,
n);
297 for(j = 0; j < passwordLen; j +=
n)
303 hashAlgo->
update(&hashContext[0], dp,
n);
308 hashAlgo->
final(&hashContext[0], digest);
336 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
342 if(outputLen != NULL)
372 for(i = 0, j = 0, k = 0; i < 30; i += 3)
375 value = input[k] << 16;
376 value |= input[(k + 10) % 30] << 8;
377 value |= input[(k + 20) % 30];
380 output[j++] = base64EncTable[
value & 0x3F];
381 output[j++] = base64EncTable[(
value >> 6) & 0x3F];
382 output[j++] = base64EncTable[(
value >> 12) & 0x3F];
383 output[j++] = base64EncTable[(
value >> 18) & 0x3F];
391 value = input[31] << 8;
395 output[j++] = base64EncTable[
value & 0x3F];
396 output[j++] = base64EncTable[(
value >> 6) & 0x3F];
397 output[j++] = base64EncTable[(
value >> 12) & 0x3F];
402 for(i = 0, j = 0, k = 0; i < 63; i += 3)
405 value = input[k] << 16;
406 value |= input[(k + 21) % 63] << 8;
407 value |= input[(k + 42) % 63];
410 output[j++] = base64EncTable[
value & 0x3F];
411 output[j++] = base64EncTable[(
value >> 6) & 0x3F];
412 output[j++] = base64EncTable[(
value >> 12) & 0x3F];
413 output[j++] = base64EncTable[(
value >> 18) & 0x3F];
424 output[j++] = base64EncTable[
value & 0x3F];
425 output[j++] = base64EncTable[(
value >> 6) & 0x3F];