MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / deskey

Function deskey

extern/libtomcrypt/src/ciphers/des.c:1304–1351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1302static void _deskey(const unsigned char *key, short edf, ulong32 *keyout)
1303#else
1304static void deskey(const unsigned char *key, short edf, ulong32 *keyout)
1305#endif
1306{
1307 ulong32 i, j, l, m, n, kn[32];
1308 unsigned char pc1m[56], pcr[56];
1309
1310 for (j=0; j < 56; j++) {
1311 l = (ulong32)pc1[j];
1312 m = l & 7;
1313 pc1m[j] = (unsigned char)((key[l >> 3U] & bytebit[m]) == bytebit[m] ? 1 : 0);
1314 }
1315
1316 for (i=0; i < 16; i++) {
1317 if (edf == DE1) {
1318 m = (15 - i) << 1;
1319 } else {
1320 m = i << 1;
1321 }
1322 n = m + 1;
1323 kn[m] = kn[n] = 0L;
1324 for (j=0; j < 28; j++) {
1325 l = j + (ulong32)totrot[i];
1326 if (l < 28) {
1327 pcr[j] = pc1m[l];
1328 } else {
1329 pcr[j] = pc1m[l - 28];
1330 }
1331 }
1332 for (/*j = 28*/; j < 56; j++) {
1333 l = j + (ulong32)totrot[i];
1334 if (l < 56) {
1335 pcr[j] = pc1m[l];
1336 } else {
1337 pcr[j] = pc1m[l - 28];
1338 }
1339 }
1340 for (j=0; j < 24; j++) {
1341 if ((int)pcr[(int)pc2[j]] != 0) {
1342 kn[m] |= bigbyte[j];
1343 }
1344 if ((int)pcr[(int)pc2[j+24]] != 0) {
1345 kn[n] |= bigbyte[j];
1346 }
1347 }
1348 }
1349
1350 cookey(kn, keyout);
1351}
1352
1353#ifdef LTC_CLEAN_STACK
1354static void deskey(const unsigned char *key, short edf, ulong32 *keyout)

Callers 2

des_setupFunction · 0.85
des3_setupFunction · 0.85

Calls 2

cookeyFunction · 0.85
burn_stackFunction · 0.85

Tested by

no test coverage detected