mw_cipher.h
Go to the documentation of this file.
/*
Meanwhile - Unofficial Lotus Sametime Community Client Library
Copyright (C) 2004 Christopher (siege) O'Brien
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _MW_CIPHER_H
#define _MW_CIPHER_H
#include <glib.h>
#include "mw_common.h"
#ifdef __cplusplus
extern "C" {
#endif
/* place-holders */
struct mwChannel;
struct mwSession;
enum mwCipherType {
mwCipher_RC2_40 = 0x0000,
mwCipher_RC2_128 = 0x0001,
};
struct mwCipher;
struct mwCipherInstance;
typedef struct mwCipherInstance *(*mwCipherInstantiator)
(struct mwCipher *cipher, struct mwChannel *chan);
typedef int (*mwCipherProcessor)
(struct mwCipherInstance *ci, struct mwOpaque *data);
struct mwCipher {
struct mwSession *session;
guint16 type;
const char *(*get_name)(void);
const char *(*get_desc)(void);
mwCipherInstantiator new_instance;
void (*offered)(struct mwCipherInstance *ci, struct mwEncryptItem *item);
struct mwEncryptItem *(*offer)(struct mwCipherInstance *ci);
void (*accepted)(struct mwCipherInstance *ci, struct mwEncryptItem *item);
struct mwEncryptItem *(*accept)(struct mwCipherInstance *ci);
mwCipherProcessor encrypt;
mwCipherProcessor decrypt;
void (*clear)(struct mwCipher *c);
void (*clear_instance)(struct mwCipherInstance *ci);
};
struct mwCipherInstance {
struct mwCipher *cipher;
struct mwChannel *channel;
};
struct mwCipher *mwCipher_new_RC2_40(struct mwSession *s);
struct mwCipher *mwCipher_new_RC2_128(struct mwSession *s);
struct mwSession *mwCipher_getSession(struct mwCipher *cipher);
guint16 mwCipher_getType(struct mwCipher *cipher);
const char *mwCipher_getName(struct mwCipher *cipher);
const char *mwCipher_getDesc(struct mwCipher *cipher);
struct mwCipherInstance *mwCipher_newInstance(struct mwCipher *cipher,
struct mwChannel *channel);
void mwCipher_free(struct mwCipher* cipher);
struct mwCipher *mwCipherInstance_getCipher(struct mwCipherInstance *ci);
struct mwChannel *mwCipherInstance_getChannel(struct mwCipherInstance *ci);
void mwCipherInstance_offered(struct mwCipherInstance *ci,
struct mwEncryptItem *item);
struct mwEncryptItem *
mwCipherInstance_offer(struct mwCipherInstance *ci);
void mwCipherInstance_accepted(struct mwCipherInstance *ci,
struct mwEncryptItem *item);
struct mwEncryptItem *
mwCipherInstance_accept(struct mwCipherInstance *ci);
int mwCipherInstance_encrypt(struct mwCipherInstance *ci,
struct mwOpaque *data);
int mwCipherInstance_decrypt(struct mwCipherInstance *ci,
struct mwOpaque *data);
void mwCipherInstance_free(struct mwCipherInstance *ci);
/* @{ */
void mwKeyRandom(guchar *key, gsize keylen);
void mwIV_init(guchar *iv);
void mwKeyExpand(int *ekey, const guchar *key, gsize keylen);
void mwEncryptExpanded(const int *ekey, guchar *iv,
struct mwOpaque *in,
struct mwOpaque *out);
void mwEncrypt(const guchar *key, gsize keylen, guchar *iv,
struct mwOpaque *in, struct mwOpaque *out);
void mwDecryptExpanded(const int *ekey, guchar *iv,
struct mwOpaque *in,
struct mwOpaque *out);
void mwDecrypt(const guchar *key, gsize keylen, guchar *iv,
struct mwOpaque *in, struct mwOpaque *out);
/* @} */
/* @{ */
struct mwMpi;
struct mwMpi *mwMpi_new(void);
void mwMpi_free(struct mwMpi *i);
void mwMpi_import(struct mwMpi *i, struct mwOpaque *o);
void mwMpi_export(struct mwMpi *i, struct mwOpaque *o);
void mwMpi_setDHPrime(struct mwMpi *i);
void mwMpi_setDHBase(struct mwMpi *i);
void mwMpi_randDHKeypair(struct mwMpi *private_key, struct mwMpi *public_key);
void mwMpi_calculateDHShared(struct mwMpi *shared_key, struct mwMpi *remote_key,
struct mwMpi *private_key);
/* @} */
#ifdef __cplusplus
}
#endif
#endif /* _MW_CIPHER_H */
mwCipherInstance_accept
struct mwEncryptItem * mwCipherInstance_accept(struct mwCipherInstance *ci)
Accept a cipher offered to our channel.
mwCipherInstance_accepted
void mwCipherInstance_accepted(struct mwCipherInstance *ci, struct mwEncryptItem *item)
Indicates an offered cipher has been accepted.
mwCipher_getName
const char * mwCipher_getName(struct mwCipher *cipher)
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.
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).
mwCipherInstance_decrypt
int mwCipherInstance_decrypt(struct mwCipherInstance *ci, struct mwOpaque *data)
decrypt data
mwCipherInstance_free
void mwCipherInstance_free(struct mwCipherInstance *ci)
destroy a cipher instance
mwMpi_export
void mwMpi_export(struct mwMpi *i, struct mwOpaque *o)
Export a value into an opaque.
mwCipherType
mwCipherType
Common cipher types.
Definition mw_cipher.h:41
mwCipher_RC2_40
@ mwCipher_RC2_40
Definition mw_cipher.h:42
mwCipher_RC2_128
@ mwCipher_RC2_128
Definition mw_cipher.h:43
mwCipher_new_RC2_40
struct mwCipher * mwCipher_new_RC2_40(struct mwSession *s)
mwIV_init
void mwIV_init(guchar *iv)
Setup an Initialization Vector.
mwKeyRandom
void mwKeyRandom(guchar *key, gsize keylen)
generate some pseudo-random bytes
mwCipherInstance_offer
struct mwEncryptItem * mwCipherInstance_offer(struct mwCipherInstance *ci)
Offer a cipher.
mwCipher_free
void mwCipher_free(struct mwCipher *cipher)
destroy a cipher
mwMpi_import
void mwMpi_import(struct mwMpi *i, struct mwOpaque *o)
Import a value from an opaque.
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.
mwCipher_getDesc
const char * mwCipher_getDesc(struct mwCipher *cipher)
mwMpi_free
void mwMpi_free(struct mwMpi *i)
destroy an mpi value
mwCipherProcessor
int(* mwCipherProcessor)(struct mwCipherInstance *ci, struct mwOpaque *data)
Process (encrypt or decrypt, depending) the given data.
Definition mw_cipher.h:62
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
mwMpi_setDHPrime
void mwMpi_setDHPrime(struct mwMpi *i)
set a big integer to the Sametime Prime value
mwEncryptExpanded
void mwEncryptExpanded(const int *ekey, guchar *iv, struct mwOpaque *in, struct mwOpaque *out)
Encrypt data using an already-expanded key.
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
mwCipher_new_RC2_128
struct mwCipher * mwCipher_new_RC2_128(struct mwSession *s)
mwCipher_getType
guint16 mwCipher_getType(struct mwCipher *cipher)
mwCipherInstance_getChannel
struct mwChannel * mwCipherInstance_getChannel(struct mwCipherInstance *ci)
reference the channel a cipher instance is attached to
mwCipher_getSession
struct mwSession * mwCipher_getSession(struct mwCipher *cipher)
mwCipherInstance_offered
void mwCipherInstance_offered(struct mwCipherInstance *ci, struct mwEncryptItem *item)
Indicates a cipher has been offered to our channel.
mwCipherInstantiator
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.
Definition mw_cipher.h:54
mwDecryptExpanded
void mwDecryptExpanded(const int *ekey, guchar *iv, struct mwOpaque *in, struct mwOpaque *out)
Decrypt data using an already expanded key.
mwCipherInstance_getCipher
struct mwCipher * mwCipherInstance_getCipher(struct mwCipherInstance *ci)
reference the parent cipher of an instance
mwCipher_newInstance
struct mwCipherInstance * mwCipher_newInstance(struct mwCipher *cipher, struct mwChannel *channel)
mwMpi_setDHBase
void mwMpi_setDHBase(struct mwMpi *i)
set a big integer to the Sametime Base value
mwMpi_new
struct mwMpi * mwMpi_new(void)
prepare a new mpi value
mwCipherInstance_encrypt
int mwCipherInstance_encrypt(struct mwCipherInstance *ci, struct mwOpaque *data)
encrypt data
mw_common.h
Common data types and functions for handling those types.
mwChannel
Represents a channel to a service.
mwCipherInstance
An instance of a cipher.
Definition mw_cipher.h:105
mwCipherInstance::cipher
struct mwCipher * cipher
the parent cipher.
Definition mw_cipher.h:109
mwCipherInstance::channel
struct mwChannel * channel
the channel this instances processes
Definition mw_cipher.h:113
mwCipher
A cipher.
Definition mw_cipher.h:70
mwCipher::accepted
void(* accepted)(struct mwCipherInstance *ci, struct mwEncryptItem *item)
Definition mw_cipher.h:86
mwCipher::decrypt
mwCipherProcessor decrypt
Definition mw_cipher.h:90
mwCipher::type
guint16 type
Definition mw_cipher.h:76
mwCipher::encrypt
mwCipherProcessor encrypt
Definition mw_cipher.h:89
mwCipher::clear
void(* clear)(struct mwCipher *c)
prepare this cipher for being free'd
Definition mw_cipher.h:94
mwCipher::offered
void(* offered)(struct mwCipherInstance *ci, struct mwEncryptItem *item)
Definition mw_cipher.h:84
mwCipher::new_instance
mwCipherInstantiator new_instance
Generate a new Cipher Instance for use on a channel.
Definition mw_cipher.h:82
mwCipher::session
struct mwSession * session
service this cipher is providing for
Definition mw_cipher.h:74
mwCipher::clear_instance
void(* clear_instance)(struct mwCipherInstance *ci)
clean up a cipher instance before being free'd
Definition mw_cipher.h:98
mwEncryptItem
encryption blocks
Definition mw_common.h:220
mwMpi
mwOpaque
A length of binary data, not null-terminated.
Definition mw_common.h:79
mwOpaque::data
guchar * data
data, normally with no NULL termination
Definition mw_common.h:81
mwSession
Represents a Sametime client session.