* Any key length must be accepted.
*
* @param key key to set
+ * @return TRUE if key set successfully
*/
- void (*set_key) (mac_t *this, chunk_t key);
+ __attribute__((warn_unused_result))
+ bool (*set_key) (mac_t *this, chunk_t key);
/**
* Destroys a mac_t object.
METHOD(prf_t, set_key, bool,
private_prf_t *this, chunk_t key)
{
- this->mac->set_key(this->mac, key);
- return TRUE;
+ return this->mac->set_key(this->mac, key);
}
METHOD(prf_t, destroy, void,
METHOD(signer_t, set_key, bool,
private_signer_t *this, chunk_t key)
{
- this->mac->set_key(this->mac, key);
- return TRUE;
+ return this->mac->set_key(this->mac, key);
}
METHOD(signer_t, destroy, void,
}
}
-METHOD(mac_t, set_key, void,
+METHOD(mac_t, set_key, bool,
private_mac_t *this, chunk_t key)
{
chunk_t resized, iv, l;
{ /* use cmac recursively to resize longer or shorter keys */
resized = chunk_alloca(this->b);
memset(resized.ptr, 0, resized.len);
- set_key(this, resized);
- get_mac(this, key, resized.ptr);
+ if (!set_key(this, resized) ||
+ !get_mac(this, key, resized.ptr))
+ {
+ return FALSE;
+ }
}
/*
derive_key(l);
memcpy(this->k2, l.ptr, l.len);
memwipe(l.ptr, l.len);
+
+ return TRUE;
}
METHOD(mac_t, destroy, void,
return this->h->get_hash_size(this->h);
}
-METHOD(mac_t, set_key, void,
+METHOD(mac_t, set_key, bool,
private_mac_t *this, chunk_t key)
{
int i;
/* begin hashing of inner pad */
this->h->reset(this->h);
this->h->get_hash(this->h, this->ipaded_key, NULL);
+
+ return TRUE;
}
METHOD(mac_t, destroy, void,
return EVP_MD_size(this->hasher);
}
-METHOD(mac_t, set_key, void,
+METHOD(mac_t, set_key, bool,
private_mac_t *this, chunk_t key)
{
chunk_clear(&this->key);
this->key = chunk_clone(key);
- reset(this);
+ return reset(this);
}
METHOD(mac_t, destroy, void,
return this->b;
}
-METHOD(mac_t, set_key, void,
+METHOD(mac_t, set_key, bool,
private_mac_t *this, chunk_t key)
{
chunk_t iv, k1, lengthened;
{ /* shorten key using xcbc */
lengthened = chunk_alloca(this->b);
memset(lengthened.ptr, 0, lengthened.len);
- set_key(this, lengthened);
- get_mac(this, key, lengthened.ptr);
+ if (!set_key(this, lengthened) ||
+ !get_mac(this, key, lengthened.ptr))
+ {
+ return FALSE;
+ }
}
k1 = chunk_alloca(this->b);
this->k1->set_key(this->k1, k1);
memwipe(k1.ptr, k1.len);
+
+ return TRUE;
}
METHOD(mac_t, destroy, void,