/* file struct dcrypt_public_key syntax
* magic (14 bytes)
* version (1 bytes)
* flags (4 bytes)
* size of header (4 bytes)
* sha1 of key id (20 bytes)
* cipher oid
* mac oid
* rounds (4 bytes)
* key data size (4 bytes)
* key data
* cipher data
* mac data (mac specific bytes)
*/
#include "lib.h"
#include "buffer.h"
#include "randgen.h"
#include "dcrypt-iostream.h"
#include "ostream-encrypt.h"
#include "ostream-private.h"
#include "hash-method.h"
#include "sha2.h"
#include "safe-memset.h"
#include "dcrypt.h"
struct encrypt_ostream {
unsigned char *key_data;
bool finalized;
bool failed;
bool prefix_written;
};
static
{
return 0;
else if (ec < 0) {
return -1;
} else {
"ostream-encrypt: Unexpectedly short write to parent stream");
return -1;
}
}
static
{
unsigned char c;
unsigned short s;
/* version */
c = 1;
/* key data length */
/* then write key data */
/* then send it to stream */
}
static
{
unsigned char c;
unsigned int i;
c = 2;
/* store total length of header
9 = version + flags + length
8 = rounds + key data length
*/
i = cpu32_to_be(sizeof(IOSTREAM_CRYPT_MAGIC) + 9 + stream->cipher_oid->used + stream->mac_oid->used + 8 + stream->key_data_len);
}
static
{
/* various temporary buffers */
/* hash the public key first */
return -1;
}
/* hash the key base */
return -1;
}
/* hash the secret data */
/* use it to encrypt the actual encryption key */
return -1;
}
int ec = 0;
/* NB! The old code was broken and used this kind of IV - it is not correct, but
we need to stay compatible with old data */
dcrypt_ctx_sym_set_iv(dctx, (const unsigned char*)"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16);
ec = -1;
}
if (ec != 0) {
return -1;
}
/* same as above */
dcrypt_ctx_sym_set_iv(stream->ctx_sym, (const unsigned char*)"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16);
return -1;
}
/* ephemeral key */
unsigned short s;
/* public key hash */
/* encrypted key hash */
/* encrypted key */
return 0;
}
static
{
const char *error;
if (ktype == DCRYPT_KEY_RSA) {
/* encrypt key as R (as we don't need DH with RSA)*/
return -1;
}
} else if (ktype == DCRYPT_KEY_EC) {
/* R = our ephemeral public key */
/* derive ephemeral key and shared secret */
return -1;
}
}
/* encrypt key with shared secret */
return -1;
}
int ec = 0;
ec = -1;
}
} else {
return -1;
}
/* store key type */
/* store hash of public key as ID */
/* store ephemeral key (if present) */
/* store encrypted key */
return 0;
}
static
{
const char *error;
const unsigned char *ptr;
unsigned int val;
"Encryption init error: Hash algorithm '%s' not supported", malg);
return -1;
}
/* key data length for internal use */
} else {
/* do not include MAC */
tagsize = 0;
}
kl = dcrypt_ctx_sym_get_key_length(stream->ctx_sym) + dcrypt_ctx_sym_get_iv_length(stream->ctx_sym) + tagsize;
/* store number of public key(s) */
/* we can do multiple keys at this point, but do it only once now */
buffer_free(&res);
return -1;
}
/* create hash of the key data */
for(int i = 1; i < 2049; i++) {
}
/* store key data hash */
/* pick up key data that goes into stream */
/* prime contexts */
}
/* clear out private key data */
return -1;
}
return 0;
}
static
{
const char *error;
/* not if finalized */
/* write prefix */
if (!estream->prefix_written) {
T_BEGIN {
else
} T_END;
if (ec < 0) {
return -1;
}
}
/* buffer for encrypted data */
/* encrypt & send all blocks of data at max ciphertext buffer's length */
for(unsigned int i = 0; i < iov_count; i++) {
while(len > 0) {
buffer_set_used_size(&buf, 0);
/* update can emite twice the size of input */
return -1;
}
/* update mac */
return -1;
}
}
/* hopefully upstream can accommodate */
return -1;
}
}
}
return total;
}
static
{
const char *error;
/* we've already flushed the encrypted output. */
return 0;
}
/* if nothing was written, we are done */
if (!estream->prefix_written) return 0;
/* acquire last block */
return -1;
}
/* sometimes final does not emit anything */
/* update mac */
return -1;
}
}
return -1;
}
}
/* write last mac bytes */
buffer_set_used_size(buf, 0);
return -1;
}
}
return -1;
}
return 0;
}
static
{
return -1;
}
return o_stream_flush_parent(stream);
}
static
bool close_parent)
{
if (close_parent) {
}
}
static
{
/* release resources */
}
static
{
const char *error;
return -1;
}
/* then do keying */
} else {
return -1;
}
(*malg++) = '\0';
return -1;
}
/* create cipher and mac context, take note of OIDs */
return -1;
}
/* mac context is optional */
return -1;
}
}
return -1;
}
/* MAC algorithm is used for PBKDF2 and keydata hashing */
}
}
static
struct encrypt_ostream *
{
return estream;
}
struct ostream *
{
int ec;
T_BEGIN {
} T_END;
if (ec != 0) {
}
return os;
}
struct ostream *
{
const char *error;
int ec;
else ec = 0;
if (ec != 0) {
}
return os;
}