/* * Set ->key and ->tfm. The rest of the key should be filled in before * this function is called.
*/ staticint set_secret(struct ceph_crypto_key *key, void *buf)
{ unsignedint noio_flag; int ret;
key->key = NULL;
key->tfm = NULL;
switch (key->type) { case CEPH_CRYPTO_NONE: return 0; /* nothing to do */ case CEPH_CRYPTO_AES: break; default: return -ENOTSUPP;
}
if (!key->len) return -EINVAL;
key->key = kmemdup(buf, key->len, GFP_NOIO); if (!key->key) {
ret = -ENOMEM; goto fail;
}
/* crypto_alloc_sync_skcipher() allocates with GFP_KERNEL */
noio_flag = memalloc_noio_save();
key->tfm = crypto_alloc_sync_skcipher("cbc(aes)", 0, 0);
memalloc_noio_restore(noio_flag); if (IS_ERR(key->tfm)) {
ret = PTR_ERR(key->tfm);
key->tfm = NULL; goto fail;
}
ret = crypto_sync_skcipher_setkey(key->tfm, key->key, key->len); if (ret) goto fail;
p = buf;
ret = ceph_crypto_key_decode(key, &p, p + blen);
kfree(buf); if (ret) return ret;
dout("crypto_key_unarmor key %p type %d len %d\n", key,
key->type, key->len); return 0;
}
/* * Should be used for buffers allocated with kvmalloc(). * Currently these are encrypt out-buffer (ceph_buffer) and decrypt * in-buffer (msg front). * * Dispose of @sgt with teardown_sgtable(). * * @prealloc_sg is to avoid memory allocation inside sg_alloc_table() * in cases where a single sg is sufficient. No attempt to reduce the * number of sgs by squeezing physically contiguous pages together is * made though, for simplicity.
*/ staticint setup_sgtable(struct sg_table *sgt, struct scatterlist *prealloc_sg, constvoid *buf, unsignedint buf_len)
{ struct scatterlist *sg; constbool is_vmalloc = is_vmalloc_addr(buf); unsignedint off = offset_in_page(buf); unsignedint chunk_cnt = 1; unsignedint chunk_len = PAGE_ALIGN(off + buf_len); int i; int ret;
ret = -EINVAL; if (datalen <= 0 || datalen > 32767 || !prep->data) goto err;
ret = -ENOMEM;
ckey = kmalloc(sizeof(*ckey), GFP_KERNEL); if (!ckey) goto err;
/* TODO ceph_crypto_key_decode should really take const input */
p = (void *)prep->data;
ret = ceph_crypto_key_decode(ckey, &p, (char*)prep->data+datalen); if (ret < 0) goto err_ckey;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.