cryptlib  3.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros
ctx_generic.c
Go to the documentation of this file.
1 /****************************************************************************
2 * *
3 * cryptlib Generic-Secret Object Routines *
4 * Copyright Peter Gutmann 1995-2009 *
5 * *
6 ****************************************************************************/
7 
8 #if defined( INC_ALL )
9  #include "crypt.h"
10  #include "context.h"
11 #else
12  #include "crypt.h"
13  #include "context/context.h"
14 #endif /* Compiler-specific includes */
15 
16 /* This is a special-case context type that implements no actual
17  functionality but instead serves as a generic-secret container for use
18  with crypto mechanisms that employ intermediate cryptovariables, for
19  example ones that derive encryption keys, MAC keys, and IVs from a master
20  secret value */
21 
22 /****************************************************************************
23 * *
24 * Self-test Routines *
25 * *
26 ****************************************************************************/
27 
28 #ifndef CONFIG_NO_SELFTEST
29 
30 static int selfTest( void )
31  {
32  return( CRYPT_OK );
33  }
34 #else
35  #define selfTest NULL
36 #endif /* !CONFIG_NO_SELFTEST */
37 
38 /****************************************************************************
39 * *
40 * Key Management Routines *
41 * *
42 ****************************************************************************/
43 
44 /* Since this is a pure data-storage object, this is the only routine that
45  does anything */
46 
47 static int initKey( CONTEXT_INFO *contextInfoPtr, const void *key,
48  const int keyLength )
49  {
50  GENERIC_INFO *genericInfo = contextInfoPtr->ctxGeneric;
51 
52  /* Copy the key to internal storage */
53  if( genericInfo->genericSecret != key )
54  memcpy( genericInfo->genericSecret, key, keyLength );
55  genericInfo->genericSecretLength = keyLength;
56 
57  return( CRYPT_OK );
58  }
59 
60 /****************************************************************************
61 * *
62 * Capability Access Routines *
63 * *
64 ****************************************************************************/
65 
66 static const CAPABILITY_INFO FAR_BSS capabilityInfo = {
67  CRYPT_IALGO_GENERIC_SECRET, 0, "Generic Secret", 14,
68  bitsToBytes( 128 ), bitsToBytes( 128 ), bitsToBytes( 256 ),
69  selfTest, getDefaultInfo, NULL, initGenericParams, initKey, NULL,
70  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
71  };
72 
74  {
75  return( &capabilityInfo );
76  }