Esempio n. 1
0
bool SrtpSymCrypto::setNewKey(const uint8_t* k, int32_t keyLength) {
    // release an existing key before setting a new one
    if (key != NULL)
        delete[] (uint8_t*)key;

    if (!(keyLength == 16 || keyLength == 32)) {
        return false;
    }
    if (algorithm == SrtpEncryptionAESCM || algorithm == SrtpEncryptionAESF8) {
        key = new uint8_t[sizeof(AES_KEY)];
        memset(key, 0, sizeof(AES_KEY) );
        AES_set_encrypt_key(k, keyLength*8, (AES_KEY *)key);
    }
    else if (algorithm == SrtpEncryptionTWOCM || algorithm == SrtpEncryptionTWOF8) {
        if (!twoFishInit) {
            Twofish_initialise();
            twoFishInit = 1;
        }
        key = new uint8_t[sizeof(Twofish_key)];
        memset(key, 0, sizeof(Twofish_key));
        Twofish_prepare_key((Twofish_Byte*)k, keyLength,  (Twofish_key*)key);
    }
    else
        return false;

    return true;
}
Esempio n. 2
0
bool CTwofish::init(RD_UINT8 *pKey, unsigned long uKeyLen, RD_UINT8 *initVector)
{
	ASSERT(pKey != NULL);
	if(pKey == NULL) return false;
	ASSERT(uKeyLen != 0);
	if(uKeyLen == 0) return false;

	if(g_bInitialized == false)
	{
		Twofish_initialise();
		g_bInitialized = true;
	}

	Twofish_prepare_key((Twofish_Byte *)pKey, uKeyLen, &m_key);

	if(initVector != NULL) memcpy(m_pInitVector, initVector, 16);
	else memset(m_pInitVector, 0, 16);

	return true;
}