The Assimilation Project  based on Assimilation version 1.1.7.1474836767
CryptCurve25519 class

Class for encrypting FrameSets. More...

Collaboration diagram for CryptCurve25519 class:

Macros

#define DEBUGCKSUM2(msg, buf, bufsize)   {if (DEBUG >= 2) cryptcurve25519_debug_checksum(__FUNCTION__, __LINE__, msg, buf, bufsize);}
 
#define DEBUGCKSUM3(msg, buf, bufsize)   {if (DEBUG >= 3) cryptcurve25519_debug_checksum(__FUNCTION__, __LINE__, msg, buf, bufsize);}
 
#define DEBUGCKSUM4(msg, buf, bufsize)   {if (DEBUG >= 4) cryptcurve25519_debug_checksum(__FUNCTION__, __LINE__, msg, buf, bufsize);}
 
#define TLVLEN(receiverkey_id, senderkey_id)
 

Functions

FSTATIC void _cryptcurve25519_finalize (AssimObj *aself)
 Finalize (free) a CryptCurve25519 object. More...
 
FSTATIC gboolean _cryptcurve25519_default_isvalid (const Frame *fself,gconstpointer tlvstart,gconstpointer pktend)
 CryptCurve25519 class 'isvalid' member function (checks for valid cryptcurve25519 objects) More...
 
FSTATIC void _cryptcurve25519_updatedata (Frame *f,gpointer tlvstart,gconstpointer pktend,FrameSet *unused_fs)
 We update the data in the packet from our CryptCurve25519 object with the side-effect of encrypting all the frames already put into the packet. More...
 
FSTATIC gboolean _is_valid_curve25519_key_id (const char *key_id,enum keytype ktype)
 CryptCurve25519 class function to check if a given curve25519 key id is valid This name might come from a bad guy, so let's carefully scrub the name More...
 
FSTATIC gboolean _is_legal_curve25519_key_id (const char *key_id)
 CryptCurve25519 class function to check if a given curve25519 key id is properly formatted This name might come from a bad guy, so let's carefully scrub the name More...
 
FSTATIC char * _cache_curve25519_key_id_to_dirname (const char *key_id,enum keytype ktype)
 Map a key name on the wire to a file name in the filesystem We make this a function on the idea that we might eventually want to have hashed subdirectories or something similar... More...
 
FSTATIC void _cryptcurve25519_make_cryptdir (const char *dirname)
 Make a directory for storing keys in... More...
 
FSTATIC gboolean _cache_curve25519_keypair (const char *key_id)
 Validate and cache the requested curve25519 keypair (or just public if no private) If it's already in memory (like a temporary key) we won't look for it on disk. More...
 
FSTATIC gboolean _cryptcurve25519_save_a_key (const char *key_id, enum keytype ktype,gconstpointer key)
 Save a curve25519 key to a file. More...
 
FSTATIC enum keytype _cryptcurve25519_keytype_from_filename (const char *filename)
 Determine the type of key this might be according to its filename. More...
 
FSTATIC char * _cryptcurve25519_key_id_from_filename (const char *filename)
 Determine the key_id this might is according to its pathname. More...
 
FSTATIC void dump_memory (const char *label, const guint8 *start, const guint8 *end)
 
FSTATIC char * cryptcurve25519_naming_checksum (const guint8 *buf,size_t buflen)
 Return a malloced string containing the KEY_NAMING_CHECKSUM type checksum of the given data. More...
 
FSTATIC void cryptcurve25519_debug_checksum (const char *function,int lineno,const char *message,const guint8 *buf,size_t bufsize)
 Print a debug checksum message. More...
 
WINEXPORT char * curve25519_key_id_to_filename (const char *key_id, enum keytype ktype)
 
WINEXPORT gboolean cryptcurve25519_purge_keypair (const char *key_id)
 Purge a cryptcurve25519 key from the filesystem and from memory. More...
 
WINEXPORT void cryptcurve25519_cache_all_keypairs (void)
 We read in and cache all the key pairs (or public keys) that we find in CRYPTKEYDIR. More...
 
CryptCurve25519cryptcurve25519_new (guint16 frame_type, const char *sender_key_id, const char *receiver_key_id, gboolean forsending, gsize objsize)
 Construct a new CryptCurve25519 object (frame). More...
 
WINEXPORT Framecryptcurve25519_tlvconstructor (gpointer tlvstart, gconstpointer pktend, gpointer *ignorednewpkt, gpointer *ignoredpktend)
 Given marshalled packet data corresponding to an CryptCurve25519 frame return the corresponding Frame In other words, un-marshall the data... More...
 
WINEXPORT void cryptcurve25519_gen_temp_keypair (const char *key_id)
 Generate a temporary (non-persistent) key pair. More...
 
WINEXPORT char * cryptcurve25519_gen_persistent_keypair (const char *giveitaname)
 Create a persistent keypair and write it to disk Returns a MALLOCed string with the key id for the key pair. More...
 
WINEXPORT gboolean cryptcurve25519_save_public_key (const char *key_id, gpointer public_key, int keysize)
 Save a public key away to disk so it's completely usable... More...
 
WINEXPORT CryptFramecryptcurve25519_new_generic (const char *sender_key_id, const char *receiver_key_id, gboolean forsending)
 Generic "new" function to use with cryptframe_set_encryption_method() More...
 
WINEXPORT void cryptcurve25519_set_encryption_method (void)
 Function just to make setting the encryption method simpler from Python. More...
 
enum  keytype { NOTAKEY, PUBLICKEY, PRIVATEKEY }
 

Detailed Description

Class for encrypting FrameSets.

Macro Definition Documentation

#define DEBUGCKSUM2 (   msg,
  buf,
  bufsize 
)    {if (DEBUG >= 2) cryptcurve25519_debug_checksum(__FUNCTION__, __LINE__, msg, buf, bufsize);}

Definition at line 66 of file cryptcurve25519.c.

#define DEBUGCKSUM3 (   msg,
  buf,
  bufsize 
)    {if (DEBUG >= 3) cryptcurve25519_debug_checksum(__FUNCTION__, __LINE__, msg, buf, bufsize);}

Definition at line 67 of file cryptcurve25519.c.

Referenced by cryptcurve25519_new().

#define DEBUGCKSUM4 (   msg,
  buf,
  bufsize 
)    {if (DEBUG >= 4) cryptcurve25519_debug_checksum(__FUNCTION__, __LINE__, msg, buf, bufsize);}
#define TLVLEN (   receiverkey_id,
  senderkey_id 
)
Value:
(4 + strnlen(receiverkey_id, MAXCRYPTNAMELENGTH+1) + strnlen(senderkey_id, MAXCRYPTNAMELENGTH+1) \
+ crypto_box_NONCEBYTES + crypto_box_MACBYTES)
#define MAXCRYPTNAMELENGTH

Definition at line 100 of file cryptcurve25519.c.

Referenced by _cryptcurve25519_default_isvalid(), and cryptcurve25519_new().

Enumeration Type Documentation

enum keytype

Which kind of key (half of the key-pair) are we dealing with?

Enumerator
NOTAKEY 
PUBLICKEY 
PRIVATEKEY 

Definition at line 39 of file cryptcurve25519.h.

Function Documentation

FSTATIC char * _cache_curve25519_key_id_to_dirname ( const char *  key_id,
enum keytype  ktype 
)

Map a key name on the wire to a file name in the filesystem We make this a function on the idea that we might eventually want to have hashed subdirectories or something similar...

Given how we structure the nanoprobe names, using the last three characters of the filename as the directory name would be a win. That would give us around 4096 subdirectories for the total. Of course, this only makes sense if you're going to have many more than 40K files (systems*2) to manage.

Parameters
key_idkey_id to convert to a filename
ktypeWhich type of key?

Definition at line 112 of file cryptcurve25519.c.

References CRYPTKEYDIR, and WINEXPORT.

Referenced by _cryptcurve25519_save_a_key(), and curve25519_key_id_to_filename().

Here is the caller graph for this function:

FSTATIC gboolean _cache_curve25519_keypair ( const char *  key_id)

Validate and cache the requested curve25519 keypair (or just public if no private) If it's already in memory (like a temporary key) we won't look for it on disk.

Parameters
key_idKey id of keypair to cache

Definition at line 230 of file cryptcurve25519.c.

References __FUNCTION__, cryptframe_privatekey_new(), cryptframe_public_key_by_id(), cryptframe_publickey_new(), curve25519_key_id_to_filename(), DEBUGCKSUM4, PRIVATEKEY, PUBLICKEY, and WINEXPORT.

Referenced by _cryptcurve25519_save_a_key(), _is_valid_curve25519_key_id(), cryptcurve25519_cache_all_keypairs(), and cryptcurve25519_gen_persistent_keypair().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC gboolean _cryptcurve25519_default_isvalid ( const Frame fself,
gconstpointer  tlvstart,
gconstpointer  pktend 
)

CryptCurve25519 class 'isvalid' member function (checks for valid cryptcurve25519 objects)

Parameters
[in]fselfCryptCurve25519 object ('this')
[in]tlvstartPointer to the TLV for this CryptCurve25519
[in]pktendPointer to one byte past the end of the packet

Definition at line 428 of file cryptcurve25519.c.

References __FUNCTION__, _is_valid_curve25519_key_id(), CASTTOCONSTCLASS, get_generic_tlv_len(), get_generic_tlv_value(), _Frame::length, MAXCRYPTNAMELENGTH, PRIVATEKEY, PUBLICKEY, tlv_get_guint8(), and TLVLEN.

Referenced by cryptcurve25519_new().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void _cryptcurve25519_finalize ( AssimObj aself)

Finalize (free) a CryptCurve25519 object.

Parameters
aselfObject to finalize/free

Definition at line 587 of file cryptcurve25519.c.

References CASTTOCLASS, UNREF, and WINEXPORT.

Referenced by cryptcurve25519_new().

Here is the caller graph for this function:

FSTATIC char * _cryptcurve25519_key_id_from_filename ( const char *  filename)

Determine the key_id this might is according to its pathname.

Parameters
filenamefilename to examine

Definition at line 175 of file cryptcurve25519.c.

References _cryptcurve25519_keytype_from_filename(), _is_legal_curve25519_key_id(), DIRDELIM, FSTATIC, NOTAKEY, PRIVATEKEY, PRIVATEKEYSUFFIX, and PUBKEYSUFFIX.

Referenced by cryptcurve25519_cache_all_keypairs().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC enum keytype _cryptcurve25519_keytype_from_filename ( const char *  filename)

Determine the type of key this might be according to its filename.

Parameters
filenameFilename to classify

Definition at line 154 of file cryptcurve25519.c.

References FSTATIC, NOTAKEY, PRIVATEKEY, PRIVATEKEYSUFFIX, PUBKEYSUFFIX, and PUBLICKEY.

Referenced by _cryptcurve25519_key_id_from_filename(), and cryptcurve25519_cache_all_keypairs().

Here is the caller graph for this function:

FSTATIC void _cryptcurve25519_make_cryptdir ( const char *  dirname)

Make a directory for storing keys in...

Definition at line 877 of file cryptcurve25519.c.

References __FUNCTION__, CMAUSERID, FREE, and FSTATIC.

Referenced by _cryptcurve25519_save_a_key(), and cryptcurve25519_cache_all_keypairs().

Here is the caller graph for this function:

FSTATIC gboolean _cryptcurve25519_save_a_key ( const char *  key_id,
enum keytype  ktype,
gconstpointer  key 
)

Save a curve25519 key to a file.

Parameters
[in]key_idkey_id to save
[in]ktypetype of key being saved
[in]keypointer to key

Definition at line 904 of file cryptcurve25519.c.

References __FUNCTION__, _cache_curve25519_key_id_to_dirname(), _cache_curve25519_keypair(), _cryptcurve25519_make_cryptdir(), _is_legal_curve25519_key_id(), cryptframe_public_key_by_id(), curve25519_key_id_to_filename(), DEBUGCKSUM4, DEBUGMSG1, DEBUGMSG4, cma.query::dirname, FREE, g_unlink, PRIVATEKEY, CryptFramePublicKey::public_key, PUBLICKEY, and WINEXPORT.

Referenced by cryptcurve25519_gen_persistent_keypair(), and cryptcurve25519_save_public_key().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void _cryptcurve25519_updatedata ( Frame f,
gpointer  tlvstart,
gconstpointer  pktend,
FrameSet unused_fs 
)

We update the data in the packet from our CryptCurve25519 object with the side-effect of encrypting all the frames already put into the packet.

Note that this only works because we always construct the packet from the end back to the beginning. We do this in-place - fortunately the algorithms allow that... We effectively suck all the remaining frames into a single encrypted frame...

Parameters
fFrame to marshall
tlvstartStart of our Frame in the packet
pktendLast byte in the allocated packet
unused_fsPointer to our containing frameset

Definition at line 689 of file cryptcurve25519.c.

References __FUNCTION__, _Frame::baseclass, CASTTOCLASS, DEBUGCKSUM4, DEBUGMSG3, DEBUGMSG4, DUMP3, get_generic_tlv_nonconst_value(), _Frame::length, set_generic_tlv_len(), set_generic_tlv_type(), tlv_set_guint8(), and WINEXPORT.

Referenced by cryptcurve25519_new().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC gboolean _is_legal_curve25519_key_id ( const char *  key_id)

CryptCurve25519 class function to check if a given curve25519 key id is properly formatted This name might come from a bad guy, so let's carefully scrub the name

Parameters
key_idKey id to validate

Definition at line 135 of file cryptcurve25519.c.

References EOS, FSTATIC, and MAXCRYPTKEYNAMELENGTH.

Referenced by _cryptcurve25519_key_id_from_filename(), _cryptcurve25519_save_a_key(), _is_valid_curve25519_key_id(), and cryptcurve25519_purge_keypair().

Here is the caller graph for this function:

FSTATIC gboolean _is_valid_curve25519_key_id ( const char *  key_id,
enum keytype  ktype 
)

CryptCurve25519 class function to check if a given curve25519 key id is valid This name might come from a bad guy, so let's carefully scrub the name

Parameters
key_idkey_id to validate
ktypewhich kind of key is it?

Definition at line 205 of file cryptcurve25519.c.

References __FUNCTION__, _cache_curve25519_keypair(), _is_legal_curve25519_key_id(), cryptframe_private_key_by_id(), FSTATIC, and PRIVATEKEY.

Referenced by _cryptcurve25519_default_isvalid(), cryptcurve25519_new(), and cryptcurve25519_tlvconstructor().

Here is the call graph for this function:

Here is the caller graph for this function:

WINEXPORT void cryptcurve25519_cache_all_keypairs ( void  )

We read in and cache all the key pairs (or public keys) that we find in CRYPTKEYDIR.

Definition at line 399 of file cryptcurve25519.c.

References __FUNCTION__, _cache_curve25519_keypair(), _cryptcurve25519_key_id_from_filename(), _cryptcurve25519_keytype_from_filename(), _cryptcurve25519_make_cryptdir(), CRYPTKEYDIR, FSTATIC, and PUBLICKEY.

Referenced by cma.assimcli.genkeys::execute(), cma.AssimCclasses.pyCryptCurve25519::initkeys(), and nanoprobe_initialize_keys().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void cryptcurve25519_debug_checksum ( const char *  function,
int  lineno,
const char *  message,
const guint8 *  buf,
size_t  bufsize 
)

Print a debug checksum message.

Parameters
[in]functionfunction name
[in]linenoline number
[in]messagemessage
[in]bufbuffer to checksum
[in]bufsizebuffer size

Definition at line 785 of file cryptcurve25519.c.

References cryptcurve25519_naming_checksum(), and WINEXPORT.

Here is the call graph for this function:

WINEXPORT char* cryptcurve25519_gen_persistent_keypair ( const char *  giveitaname)

Create a persistent keypair and write it to disk Returns a MALLOCed string with the key id for the key pair.

Please free!

Parameters
giveitanamegiveitaname can be NULL

Definition at line 799 of file cryptcurve25519.c.

References __FUNCTION__, _cache_curve25519_keypair(), _cryptcurve25519_save_a_key(), cryptcurve25519_naming_checksum(), cryptcurve25519_purge_keypair(), cryptframe_privatekey_new(), cryptframe_publickey_new(), DEBUGMSG1, PRIVATEKEY, proj_get_sysname(), PUBLICKEY, and WINEXPORT.

Referenced by cma.assimcli.genkeys::execute(), cma.AssimCclasses.pyCryptCurve25519::initkeys(), and nanoprobe_initialize_keys().

Here is the call graph for this function:

Here is the caller graph for this function:

WINEXPORT void cryptcurve25519_gen_temp_keypair ( const char *  key_id)

Generate a temporary (non-persistent) key pair.

Parameters
key_idkey_id CANNOT be NULL

Definition at line 765 of file cryptcurve25519.c.

References cryptframe_privatekey_new(), cryptframe_publickey_new(), and FSTATIC.

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC char * cryptcurve25519_naming_checksum ( const guint8 *  buf,
size_t  buflen 
)

Return a malloced string containing the KEY_NAMING_CHECKSUM type checksum of the given data.

Parameters
[in]bufbuffer to checksum
[in]buflenlength of 'buf'

Definition at line 777 of file cryptcurve25519.c.

References FSTATIC, and KEY_NAMING_CHECKSUM.

Referenced by cryptcurve25519_debug_checksum(), and cryptcurve25519_gen_persistent_keypair().

Here is the caller graph for this function:

CryptCurve25519* cryptcurve25519_new ( guint16  frame_type,
const char *  sender_key_id,
const char *  receiver_key_id,
gboolean  forsending,
gsize  objsize 
)

Construct a new CryptCurve25519 object (frame).

Parameters
[in]frame_typeTLV type of CryptCurve25519
[in]sender_key_idname of sender's key
[in]receiver_key_idname of receiver's key
[in]forsendingTRUE if this is for sending
[in]objsizesizeof(this object) - or zero for default

Definition at line 524 of file cryptcurve25519.c.

References __FUNCTION__, _cryptcurve25519_default_isvalid(), _cryptcurve25519_finalize(), _cryptcurve25519_updatedata(), _AssimObj::_finalize, _is_valid_curve25519_key_id(), _Frame::baseclass, _CryptCurve25519::baseclass, _CryptFrame::baseclass, BINDDEBUG, cryptframe_get_signing_key_id(), cryptframe_new(), cryptframe_private_key_by_id(), cryptframe_public_key_by_id(), DEBUGCKSUM3, DEBUGMSG2, DUMP3, _CryptCurve25519::forsending, FSTATIC, _Frame::isvalid, _Frame::length, NEWSUBCLASS, CryptFramePrivateKey::private_key, _CryptCurve25519::private_key, CryptFramePublicKey::public_key, _CryptCurve25519::public_key, PUBLICKEY, REF, TLVLEN, UNREF3, and _Frame::updatedata.

Referenced by cma.AssimCclasses.pyCryptCurve25519::__init__(), cryptcurve25519_new_generic(), and cryptcurve25519_tlvconstructor().

Here is the call graph for this function:

Here is the caller graph for this function:

WINEXPORT CryptFrame* cryptcurve25519_new_generic ( const char *  sender_key_id,
const char *  receiver_key_id,
gboolean  forsending 
)

Generic "new" function to use with cryptframe_set_encryption_method()

Parameters
sender_key_idsender's key id
receiver_key_idreceiver's key id
forsendingTRUE if this is for sending

Definition at line 979 of file cryptcurve25519.c.

References _CryptCurve25519::baseclass, cryptcurve25519_new(), FRAMETYPE_CRYPTCURVE25519, and WINEXPORT.

Referenced by cryptcurve25519_set_encryption_method(), fakecma_startup(), main(), and nanoprobe_initialize_keys().

Here is the call graph for this function:

Here is the caller graph for this function:

WINEXPORT gboolean cryptcurve25519_purge_keypair ( const char *  key_id)

Purge a cryptcurve25519 key from the filesystem and from memory.

This will modify the filesystem. It will return success if at the end of the call the files do not exist, and regardless of the return value it will purge them from our in-memory key cache

Parameters
key_idKey id of keypair to purge

Definition at line 367 of file cryptcurve25519.c.

References __FUNCTION__, _is_legal_curve25519_key_id(), cryptframe_purge_key_id(), curve25519_key_id_to_filename(), g_unlink, PRIVATEKEY, PUBLICKEY, and WINEXPORT.

Referenced by cryptcurve25519_gen_persistent_keypair(), and cryptcurve25519_save_public_key().

Here is the call graph for this function:

Here is the caller graph for this function:

WINEXPORT gboolean cryptcurve25519_save_public_key ( const char *  key_id,
gpointer  public_key,
int  keysize 
)

Save a public key away to disk so it's completely usable...

Parameters
key_idkey id to save key under
public_keypointer to public key data
keysizesize of key

Definition at line 839 of file cryptcurve25519.c.

References __FUNCTION__, _cryptcurve25519_save_a_key(), cryptcurve25519_purge_keypair(), cryptframe_public_key_by_id(), cryptframe_publickey_new(), DEBUG, FSTATIC, CryptFramePublicKey::public_key, and PUBLICKEY.

Referenced by cma.dispatchtarget.DispatchSTARTUP::dispatch(), and fakecma_startup().

Here is the call graph for this function:

Here is the caller graph for this function:

WINEXPORT void cryptcurve25519_set_encryption_method ( void  )

Function just to make setting the encryption method simpler from Python.

Just for python simplicity...

Definition at line 990 of file cryptcurve25519.c.

References cryptcurve25519_new_generic(), and cryptframe_set_encryption_method().

Referenced by cma.AssimCclasses.pyCryptCurve25519::initkeys().

Here is the call graph for this function:

Here is the caller graph for this function:

WINEXPORT Frame* cryptcurve25519_tlvconstructor ( gpointer  tlvstart,
gconstpointer  pktend,
gpointer *  ignorednewpkt,
gpointer *  ignoredpktend 
)

Given marshalled packet data corresponding to an CryptCurve25519 frame return the corresponding Frame In other words, un-marshall the data...

In our case, this means we decrypt it in-place into many other frames...

Parameters
[in,out]tlvstartStart of marshalled CStringFrame data
[in]pktendPointer to first invalid byte past 'tlvstart'
ignorednewpkt[ignored] replacement packet
ignoredpktend[ignored] end of replacement packet

Definition at line 605 of file cryptcurve25519.c.

References __FUNCTION__, _is_valid_curve25519_key_id(), _CryptCurve25519::baseclass, _CryptFrame::baseclass, cryptcurve25519_new(), cryptframe_private_key_by_id(), cryptframe_public_key_by_id(), DEBUGCKSUM4, DEBUGMSG4, FSTATIC, get_generic_tlv_len(), get_generic_tlv_nonconst_value(), get_generic_tlv_type(), CryptFramePrivateKey::private_key, PRIVATEKEY, CryptFramePublicKey::public_key, PUBLICKEY, and tlv_get_guint8().

Here is the call graph for this function:

WINEXPORT char* curve25519_key_id_to_filename ( const char *  key_id,
enum keytype  ktype 
)
Parameters
key_idkey_id to convert to a filename
ktypeWhich type of key?

Definition at line 121 of file cryptcurve25519.c.

References _cache_curve25519_key_id_to_dirname(), DIRDELIM, cma.query::dirname, FREE, FSTATIC, PRIVATEKEY, PRIVATEKEYSUFFIX, and PUBKEYSUFFIX.

Referenced by _cache_curve25519_keypair(), _cryptcurve25519_save_a_key(), cryptcurve25519_purge_keypair(), and cma.AssimCclasses.pyCryptCurve25519::key_id_to_filename().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void dump_memory ( const char *  label,
const guint8 *  start,
const guint8 *  end 
)

Definition at line 72 of file cryptcurve25519.c.

References g_info.