meanwhile 1.1.1
mw_cipher.h File Reference
#include <glib.h>
#include "mw_common.h"

Go to the source code of this file.

Data Structures

struct  mwCipher
 A cipher. More...
struct  mwCipherInstance
 An instance of a cipher. More...

Typedefs

typedef struct mwCipherInstance *(*) mwCipherInstantiator(struct mwCipher *cipher, struct mwChannel *chan)
 Obtain an instance of a given cipher, which can be used for the processing of a single channel.
typedef int(*) mwCipherProcessor(struct mwCipherInstance *ci, struct mwOpaque *data)
 Process (encrypt or decrypt, depending) the given data.

Enumerations

enum  mwCipherType {
  mwCipher_RC2_40 = 0x0000 ,
  mwCipher_RC2_128 = 0x0001
}
 Common cipher types. More...

Functions

void mwCipher_free (struct mwCipher *cipher)
 destroy a cipher
const char * mwCipher_getDesc (struct mwCipher *cipher)
const char * mwCipher_getName (struct mwCipher *cipher)
struct mwSessionmwCipher_getSession (struct mwCipher *cipher)
guint16 mwCipher_getType (struct mwCipher *cipher)
struct mwCiphermwCipher_new_RC2_128 (struct mwSession *s)
struct mwCiphermwCipher_new_RC2_40 (struct mwSession *s)
struct mwCipherInstancemwCipher_newInstance (struct mwCipher *cipher, struct mwChannel *channel)
struct mwEncryptItemmwCipherInstance_accept (struct mwCipherInstance *ci)
 Accept a cipher offered to our channel.
void mwCipherInstance_accepted (struct mwCipherInstance *ci, struct mwEncryptItem *item)
 Indicates an offered cipher has been accepted.
int mwCipherInstance_decrypt (struct mwCipherInstance *ci, struct mwOpaque *data)
 decrypt data
int mwCipherInstance_encrypt (struct mwCipherInstance *ci, struct mwOpaque *data)
 encrypt data
void mwCipherInstance_free (struct mwCipherInstance *ci)
 destroy a cipher instance
struct mwChannelmwCipherInstance_getChannel (struct mwCipherInstance *ci)
 reference the channel a cipher instance is attached to
struct mwCiphermwCipherInstance_getCipher (struct mwCipherInstance *ci)
 reference the parent cipher of an instance
struct mwEncryptItemmwCipherInstance_offer (struct mwCipherInstance *ci)
 Offer a cipher.
void mwCipherInstance_offered (struct mwCipherInstance *ci, struct mwEncryptItem *item)
 Indicates a cipher has been offered to our channel.
void mwDecrypt (const guchar *key, gsize keylen, guchar *iv, struct mwOpaque *in, struct mwOpaque *out)
 Decrypt data using an expanded form of the given key.
void mwDecryptExpanded (const int *ekey, guchar *iv, struct mwOpaque *in, struct mwOpaque *out)
 Decrypt data using an already expanded key.
void mwEncrypt (const guchar *key, gsize keylen, guchar *iv, struct mwOpaque *in, struct mwOpaque *out)
 Encrypt data using an expanded form of the given key.
void mwEncryptExpanded (const int *ekey, guchar *iv, struct mwOpaque *in, struct mwOpaque *out)
 Encrypt data using an already-expanded key.
void mwIV_init (guchar *iv)
 Setup an Initialization Vector.
void mwKeyExpand (int *ekey, const guchar *key, gsize keylen)
 Expand a variable-length key into a 128-byte key (represented as an an array of 64 ints).
void mwKeyRandom (guchar *key, gsize keylen)
 generate some pseudo-random bytes
void mwMpi_calculateDHShared (struct mwMpi *shared_key, struct mwMpi *remote_key, struct mwMpi *private_key)
 sets the shared key value based on the remote and private keys, using the Sametime Prime and Base
void mwMpi_export (struct mwMpi *i, struct mwOpaque *o)
 Export a value into an opaque.
void mwMpi_free (struct mwMpi *i)
 destroy an mpi value
void mwMpi_import (struct mwMpi *i, struct mwOpaque *o)
 Import a value from an opaque.
struct mwMpimwMpi_new (void)
 prepare a new mpi value
void mwMpi_randDHKeypair (struct mwMpi *private_key, struct mwMpi *public_key)
 sets private to a randomly generated value, and calculates public using the Sametime Prime and Base
void mwMpi_setDHBase (struct mwMpi *i)
 set a big integer to the Sametime Base value
void mwMpi_setDHPrime (struct mwMpi *i)
 set a big integer to the Sametime Prime value

Typedef Documentation

◆ mwCipherInstantiator

typedef struct mwCipherInstance *(*) mwCipherInstantiator(struct mwCipher *cipher, struct mwChannel *chan)

Obtain an instance of a given cipher, which can be used for the processing of a single channel.

◆ mwCipherProcessor

typedef int(*) mwCipherProcessor(struct mwCipherInstance *ci, struct mwOpaque *data)

Process (encrypt or decrypt, depending) the given data.

The passed buffer may be freed in processing and be replaced with a freshly allocated buffer. The post-processed buffer must in turn be freed after use

Enumeration Type Documentation

◆ mwCipherType

Common cipher types.

Enumerator
mwCipher_RC2_40 
mwCipher_RC2_128 

Function Documentation

◆ mwCipher_free()

void mwCipher_free ( struct mwCipher * cipher)

destroy a cipher

References mwCipher_free().

Referenced by mwCipher_free().

◆ mwCipher_getDesc()

const char * mwCipher_getDesc ( struct mwCipher * cipher)

References mwCipher_getDesc().

Referenced by mwCipher_getDesc().

◆ mwCipher_getName()

const char * mwCipher_getName ( struct mwCipher * cipher)

References mwCipher_getName().

Referenced by mwCipher_getName().

◆ mwCipher_getSession()

struct mwSession * mwCipher_getSession ( struct mwCipher * cipher)

References mwCipher_getSession().

Referenced by mwCipher_getSession().

◆ mwCipher_getType()

guint16 mwCipher_getType ( struct mwCipher * cipher)

References mwCipher_getType().

Referenced by mwCipher_getType().

◆ mwCipher_new_RC2_128()

struct mwCipher * mwCipher_new_RC2_128 ( struct mwSession * s)

References mwCipher_new_RC2_128().

Referenced by mwCipher_new_RC2_128().

◆ mwCipher_new_RC2_40()

struct mwCipher * mwCipher_new_RC2_40 ( struct mwSession * s)

References mwCipher_new_RC2_40().

Referenced by mwCipher_new_RC2_40().

◆ mwCipher_newInstance()

struct mwCipherInstance * mwCipher_newInstance ( struct mwCipher * cipher,
struct mwChannel * channel )

References mwCipher_newInstance().

Referenced by mwCipher_newInstance().

◆ mwCipherInstance_accept()

struct mwEncryptItem * mwCipherInstance_accept ( struct mwCipherInstance * ci)

Accept a cipher offered to our channel.

References mwCipherInstance_accept().

Referenced by mwCipherInstance_accept().

◆ mwCipherInstance_accepted()

void mwCipherInstance_accepted ( struct mwCipherInstance * ci,
struct mwEncryptItem * item )

Indicates an offered cipher has been accepted.

References mwCipherInstance_accepted().

Referenced by mwCipherInstance_accepted().

◆ mwCipherInstance_decrypt()

int mwCipherInstance_decrypt ( struct mwCipherInstance * ci,
struct mwOpaque * data )

decrypt data

References mwCipherInstance_decrypt().

Referenced by mwCipherInstance_decrypt().

◆ mwCipherInstance_encrypt()

int mwCipherInstance_encrypt ( struct mwCipherInstance * ci,
struct mwOpaque * data )

encrypt data

References mwCipherInstance_encrypt().

Referenced by mwCipherInstance_encrypt().

◆ mwCipherInstance_free()

void mwCipherInstance_free ( struct mwCipherInstance * ci)

destroy a cipher instance

References mwCipherInstance_free().

Referenced by mwCipherInstance_free().

◆ mwCipherInstance_getChannel()

struct mwChannel * mwCipherInstance_getChannel ( struct mwCipherInstance * ci)

reference the channel a cipher instance is attached to

References mwCipherInstance_getChannel().

Referenced by mwCipherInstance_getChannel().

◆ mwCipherInstance_getCipher()

struct mwCipher * mwCipherInstance_getCipher ( struct mwCipherInstance * ci)

reference the parent cipher of an instance

References mwCipherInstance_getCipher().

Referenced by mwCipherInstance_getCipher().

◆ mwCipherInstance_offer()

struct mwEncryptItem * mwCipherInstance_offer ( struct mwCipherInstance * ci)

Offer a cipher.

References mwCipherInstance_offer().

Referenced by mwCipherInstance_offer().

◆ mwCipherInstance_offered()

void mwCipherInstance_offered ( struct mwCipherInstance * ci,
struct mwEncryptItem * item )

Indicates a cipher has been offered to our channel.

References mwCipherInstance_offered().

Referenced by mwCipherInstance_offered().

◆ mwDecrypt()

void mwDecrypt ( const guchar * key,
gsize keylen,
guchar * iv,
struct mwOpaque * in,
struct mwOpaque * out )

Decrypt data using an expanded form of the given key.

References mwDecrypt().

Referenced by mwDecrypt().

◆ mwDecryptExpanded()

void mwDecryptExpanded ( const int * ekey,
guchar * iv,
struct mwOpaque * in,
struct mwOpaque * out )

Decrypt data using an already expanded key.

References mwDecryptExpanded().

Referenced by mwDecryptExpanded().

◆ mwEncrypt()

void mwEncrypt ( const guchar * key,
gsize keylen,
guchar * iv,
struct mwOpaque * in,
struct mwOpaque * out )

Encrypt data using an expanded form of the given key.

References mwEncrypt().

Referenced by mwEncrypt().

◆ mwEncryptExpanded()

void mwEncryptExpanded ( const int * ekey,
guchar * iv,
struct mwOpaque * in,
struct mwOpaque * out )

Encrypt data using an already-expanded key.

References mwEncryptExpanded().

Referenced by mwEncryptExpanded().

◆ mwIV_init()

void mwIV_init ( guchar * iv)

Setup an Initialization Vector.

IV must be at least 8 bytes

References mwIV_init().

Referenced by mwIV_init().

◆ mwKeyExpand()

void mwKeyExpand ( int * ekey,
const guchar * key,
gsize keylen )

Expand a variable-length key into a 128-byte key (represented as an an array of 64 ints).

References mwKeyExpand().

Referenced by mwKeyExpand().

◆ mwKeyRandom()

void mwKeyRandom ( guchar * key,
gsize keylen )

generate some pseudo-random bytes

Cipher Functions

These functions are reused where encryption is necessary outside of a channel (eg. session authentication)

Parameters
keylencount of bytes to write into key
keybuffer to write keys into

References mwKeyRandom().

Referenced by mwKeyRandom().

◆ mwMpi_calculateDHShared()

void mwMpi_calculateDHShared ( struct mwMpi * shared_key,
struct mwMpi * remote_key,
struct mwMpi * private_key )

sets the shared key value based on the remote and private keys, using the Sametime Prime and Base

References mwMpi_calculateDHShared().

Referenced by mwMpi_calculateDHShared().

◆ mwMpi_export()

void mwMpi_export ( struct mwMpi * i,
struct mwOpaque * o )

Export a value into an opaque.

References mwMpi_export().

Referenced by mwMpi_export().

◆ mwMpi_free()

void mwMpi_free ( struct mwMpi * i)

destroy an mpi value

References mwMpi_free().

Referenced by mwMpi_free().

◆ mwMpi_import()

void mwMpi_import ( struct mwMpi * i,
struct mwOpaque * o )

Import a value from an opaque.

References mwMpi_import().

Referenced by mwMpi_import().

◆ mwMpi_new()

struct mwMpi * mwMpi_new ( void )

prepare a new mpi value

References mwMpi_new().

Referenced by mwMpi_new().

◆ mwMpi_randDHKeypair()

void mwMpi_randDHKeypair ( struct mwMpi * private_key,
struct mwMpi * public_key )

sets private to a randomly generated value, and calculates public using the Sametime Prime and Base

References mwMpi_randDHKeypair().

Referenced by mwMpi_randDHKeypair().

◆ mwMpi_setDHBase()

void mwMpi_setDHBase ( struct mwMpi * i)

set a big integer to the Sametime Base value

References mwMpi_setDHBase().

Referenced by mwMpi_setDHBase().

◆ mwMpi_setDHPrime()

void mwMpi_setDHPrime ( struct mwMpi * i)

set a big integer to the Sametime Prime value

References mwMpi_setDHPrime().

Referenced by mwMpi_setDHPrime().