int safer_sk128_setup(const unsigned char *key, int keylen, int numrounds, symmetric_key *skey) { LTC_ARGCHK(key != NULL); LTC_ARGCHK(skey != NULL); if (numrounds != 0 && (numrounds < 6 || numrounds > LTC_SAFER_MAX_NOF_ROUNDS)) { return CRYPT_INVALID_ROUNDS; } if (keylen != 16) { return CRYPT_INVALID_KEYSIZE; } Safer_Expand_Userkey(key, key+8, (unsigned int)(numrounds != 0?numrounds:LTC_SAFER_SK128_DEFAULT_NOF_ROUNDS), 1, skey->safer.key); return CRYPT_OK; }
int safer_k64_setup(const unsigned char *key, int keylen, int numrounds, symmetric_key *skey) { _ARGCHK(key != NULL); _ARGCHK(skey != NULL); if (numrounds != 0 && (numrounds < 6 || numrounds > SAFER_MAX_NOF_ROUNDS)) { return CRYPT_INVALID_ROUNDS; } if (keylen != 8) { return CRYPT_INVALID_KEYSIZE; } Safer_Expand_Userkey(key, key, (unsigned int)(numrounds != 0 ?numrounds:SAFER_K64_DEFAULT_NOF_ROUNDS), 0, skey->safer.key); return CRYPT_OK; }
// Safer static dword func5(dword aKey) { static safer_key_t saferKey1; static bool saferInited1 = false; if ( ! saferInited1 ) { Safer_Init_Module(); safer_block_t Key = { 0x9C, 0x56, 0xD1, 0x12, 0x23, 0xC0, 0xB4, 0x37 }; Safer_Expand_Userkey( Key, Key, 8, 0, saferKey1 ); saferInited1 = true; } safer_block_t inBlock = { 0 }; safer_block_t outBlock = { 0 }; *(dword*)(inBlock) = aKey; Safer_Encrypt_Block( inBlock, saferKey1, outBlock ); return *(dword*)(outBlock); }