if (dst)
{
*dst = chunk_alloc(data.len);
- this->ops->crypt(this->ops, ALG_OP_DECRYPT, iv, data, dst->ptr);
+ return this->ops->crypt(this->ops, ALG_OP_DECRYPT, iv, data, dst->ptr);
}
- else
- {
- this->ops->crypt(this->ops, ALG_OP_DECRYPT, iv, data, data.ptr);
- }
- return TRUE;
+ return this->ops->crypt(this->ops, ALG_OP_DECRYPT, iv, data, data.ptr);
}
METHOD(crypter_t, encrypt, bool,
if (dst)
{
*dst = chunk_alloc(data.len);
- this->ops->crypt(this->ops, ALG_OP_ENCRYPT, iv, data, dst->ptr);
- }
- else
- {
- this->ops->crypt(this->ops, ALG_OP_ENCRYPT, iv, data, data.ptr);
+ return this->ops->crypt(this->ops, ALG_OP_ENCRYPT, iv, data, dst->ptr);
}
- return TRUE;
+ return this->ops->crypt(this->ops, ALG_OP_ENCRYPT, iv, data, data.ptr);
}
METHOD(crypter_t, get_block_size, size_t,
METHOD(crypter_t, set_key, bool,
private_af_alg_crypter_t *this, chunk_t key)
{
- this->ops->set_key(this->ops, key);
- return TRUE;
+ return this->ops->set_key(this->ops, key);
}
METHOD(crypter_t, destroy, void,
METHOD(hasher_t, get_hash, bool,
private_af_alg_hasher_t *this, chunk_t chunk, u_int8_t *hash)
{
- this->ops->hash(this->ops, chunk, hash, this->size);
- return TRUE;
+ return this->ops->hash(this->ops, chunk, hash, this->size);
}
METHOD(hasher_t, allocate_hash, bool,
}
}
-METHOD(af_alg_ops_t, hash, void,
+METHOD(af_alg_ops_t, hash, bool,
private_af_alg_ops_t *this, chunk_t data, char *out, size_t outlen)
{
ssize_t len;
while (this->op == -1)
{
this->op = accept(this->tfm, NULL, 0);
- if (this->op == -1)
+ if (this->op == -1 && errno != EINTR)
{
DBG1(DBG_LIB, "opening AF_ALG hasher failed: %s", strerror(errno));
- sleep(1);
+ return FALSE;
}
}
+
do
{
len = send(this->op, data.ptr, data.len, out ? 0 : MSG_MORE);
if (len == -1)
{
+ if (errno == EINTR)
+ {
+ continue;
+ }
DBG1(DBG_LIB, "writing to AF_ALG hasher failed: %s", strerror(errno));
- sleep(1);
- }
- else
- {
- data = chunk_skip(data, len);
+ return FALSE;
}
+ data = chunk_skip(data, len);
}
while (data.len);
if (out)
{
- while (read(this->op, out, outlen) != outlen)
+ while (outlen)
{
- DBG1(DBG_LIB, "reading AF_ALG hasher failed: %s", strerror(errno));
- sleep(1);
+ len = read(this->op, out, outlen);
+ if (len == -1)
+ {
+ if (errno == EINTR)
+ {
+ continue;
+ }
+ DBG1(DBG_LIB, "reading AF_ALG hasher failed: %s", strerror(errno));
+ return FALSE;
+ }
+ outlen -= len;
+ out += len;
}
reset(this);
}
+ return TRUE;
}
-METHOD(af_alg_ops_t, crypt, void,
+METHOD(af_alg_ops_t, crypt, bool,
private_af_alg_ops_t *this, u_int32_t type, chunk_t iv, chunk_t data,
char *out)
{
ssize_t len;
int op;
- while ((op = accept(this->tfm, NULL, 0)) == -1)
+ do
{
- DBG1(DBG_LIB, "accepting AF_ALG crypter failed: %s", strerror(errno));
- sleep(1);
+ op = accept(this->tfm, NULL, 0);
+ if (op == -1 && errno != EINTR)
+ {
+ DBG1(DBG_LIB, "accepting AF_ALG crypter failed: %s", strerror(errno));
+ return FALSE;
+ }
}
+ while (op == -1);
memset(buf, 0, sizeof(buf));
len = sendmsg(op, &msg, 0);
if (len == -1)
{
- DBG1(DBG_LIB, "writing to AF_ALG crypter failed: %s",
- strerror(errno));
- sleep(1);
- continue;
+ if (errno == EINTR)
+ {
+ continue;
+ }
+ DBG1(DBG_LIB, "writing to AF_ALG crypter failed: %s", strerror(errno));
+ return FALSE;
}
- if (read(op, out, len) != len)
+ while (read(op, out, len) != len)
{
- DBG1(DBG_LIB, "reading from AF_ALG crypter failed: %s",
- strerror(errno));
+ if (errno != EINTR)
+ {
+ DBG1(DBG_LIB, "reading from AF_ALG crypter failed: %s",
+ strerror(errno));
+ return FALSE;
+ }
}
data = chunk_skip(data, len);
/* no IV for subsequent data chunks */
msg.msg_controllen = 0;
}
close(op);
+ return TRUE;
}
-METHOD(af_alg_ops_t, set_key, void,
+METHOD(af_alg_ops_t, set_key, bool,
private_af_alg_ops_t *this, chunk_t key)
{
if (setsockopt(this->tfm, SOL_ALG, ALG_SET_KEY, key.ptr, key.len) == -1)
{
DBG1(DBG_LIB, "setting AF_ALG key failed: %s", strerror(errno));
+ return FALSE;
}
+ return TRUE;
}
METHOD(af_alg_ops_t, destroy, void,
* @param data data to hash
* @param out buffer to write hash to, NULL for append mode
* @param outlen number of bytes to read into out
+ * @return TRUE if successful
*/
- void (*hash)(af_alg_ops_t *this, chunk_t data, char *out, size_t outlen);
+ bool (*hash)(af_alg_ops_t *this, chunk_t data, char *out, size_t outlen);
/**
* Reset hasher state.
* @param iv iv to use
* @param data data to encrypt/decrypt
* @param out buffer write processed data to
+ * @return TRUE if successful
*/
- void (*crypt)(af_alg_ops_t *this, u_int32_t type, chunk_t iv, chunk_t data,
+ bool (*crypt)(af_alg_ops_t *this, u_int32_t type, chunk_t iv, chunk_t data,
char *out);
/**
* Set the key for en-/decryption or HMAC/XCBC operations.
*
* @param key key to set for transform
+ * @return TRUE if successful
*/
- void (*set_key)(af_alg_ops_t *this, chunk_t key);
+ bool (*set_key)(af_alg_ops_t *this, chunk_t key);
/**
* Destroy a af_alg_ops_t.
METHOD(prf_t, get_bytes, bool,
private_af_alg_prf_t *this, chunk_t seed, u_int8_t *buffer)
{
- this->ops->hash(this->ops, seed, buffer, this->block_size);
- return TRUE;
+ return this->ops->hash(this->ops, seed, buffer, this->block_size);
}
METHOD(prf_t, allocate_bytes, bool,
else if (key.len > this->block_size)
{
memset(buf, 0, this->block_size);
- this->ops->set_key(this->ops, chunk_from_thing(buf));
- this->ops->hash(this->ops, key, buf, this->block_size);
+ if (!this->ops->set_key(this->ops, chunk_from_thing(buf)) ||
+ !this->ops->hash(this->ops, key, buf, this->block_size))
+ {
+ return FALSE;
+ }
key = chunk_from_thing(buf);
}
}
- this->ops->set_key(this->ops, key);
- return TRUE;
+ return this->ops->set_key(this->ops, key);
}
METHOD(prf_t, destroy, void,
METHOD(signer_t, get_signature, bool,
private_af_alg_signer_t *this, chunk_t data, u_int8_t *buffer)
{
- this->ops->hash(this->ops, data, buffer, this->block_size);
- return TRUE;
+ return this->ops->hash(this->ops, data, buffer, this->block_size);
}
METHOD(signer_t, allocate_signature, bool,
METHOD(signer_t, set_key, bool,
private_af_alg_signer_t *this, chunk_t key)
{
- this->ops->set_key(this->ops, key);
- return TRUE;
+ return this->ops->set_key(this->ops, key);
}
METHOD(signer_t, destroy, void,