mco_crypt_stream

Encrypts or decrypts a stream of data using the encryption context and state.

For an overview see page Encryption C API

Prototype

    void mco_crypt_stream(mco_crypt_ctx_t const* crypt_ctx,
                mco_crypt_state_t* state,
                uint1* buf,
                uint4 size);

Arguments

crypt_ctx
The address of the pre-initialized encryption context.
state
The address of the encryption state structure indicating the encryption process at the current location of the stream.
buf
The address of the data buffer to encrypt / decrypt.
size
The size to be placed into or retrieved from the buffer buf.

Description

This function encrypts or decrypts a data buffer buf of size size to be placed into or retrieved from a stream. Unlike the block-based function mco_crypt_block(), this function assumes an arbitrary buffer size that is the usual usage pattern for stream-based operations.

Return Codes

void
No value returned.

Example

The following code snippet demonstrates encrypting / decrypting an external file:

    /* Code sample for stream-based encryption */
    FILE *fin, *fout;
    char buff[100];
    const int buff_size = sizeof(buff);
    const char *cipher = "my cipher key";
    mco_crypt_ctx_t crypt_ctx;
    mco_crypt_state_t crypt_state;
    size_t n;

    mco_crypt_init_ctx(&crypt_ctx, cipher);
    mco_crypt_init_state(&crypt_ctx, &crypt_state);
    fin = fopen("unencrypted.file", "rb");
    fout = fopen("encrypted.file", "wb");
    do
    {
        n = fread(buff, buff_size, 1, fin);
        mco_crypt_stream(&crypt_ctx, &crypt_state, buff, (uint4)n);

        fwrite(buff, n, 1, fout);
    } while (n == buff_size);
    fclose(fin);
    fclose(fout);

Files

Header file:
mco.h
Source file:
mcocryptaes.c
Library:
libmcocryptaes.a
Header file:
mco.h
Source file:
mcocryptstub.c
Library:
libmcocryptstub.a