| 1 |
#include <time.h> |
|---|
| 2 |
#include <openssl/bn.h> |
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
#define OPS_PTAG_ALWAYS_SET 0x80 |
|---|
| 7 |
#define OPS_PTAG_NEW_FORMAT 0x40 |
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
#define OPS_PTAG_OF_CONTENT_TAG_MASK 0x3c |
|---|
| 12 |
#define OPS_PTAG_OF_CONTENT_TAG_SHIFT 2 |
|---|
| 13 |
#define OPS_PTAG_OF_LENGTH_TYPE_MASK 0x03 |
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
typedef enum |
|---|
| 18 |
{ |
|---|
| 19 |
OPS_PTAG_OF_LT_ONE_BYTE =0x00, |
|---|
| 20 |
OPS_PTAG_OF_LT_TWO_BYTE =0x01, |
|---|
| 21 |
OPS_PTAG_OF_LT_FOUR_BYTE =0x02, |
|---|
| 22 |
OPS_PTAG_OF_LT_INDETERMINATE =0x03, |
|---|
| 23 |
} ops_ptag_of_lt; |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
#define OPS_PTAG_NF_CONTENT_TAG_MASK 0x3f |
|---|
| 28 |
#define OPS_PTAG_NF_CONTENT_TAG_SHIFT 0 |
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
typedef enum |
|---|
| 34 |
{ |
|---|
| 35 |
OPS_PTAG_CT_RESERVED =0x00, |
|---|
| 36 |
OPS_PTAG_CT_PK_SESSION_KEY =0x01, |
|---|
| 37 |
OPS_PTAG_CT_SIGNATURE =0x02, |
|---|
| 38 |
OPS_PTAG_CT_SK_SESSION_KEY =0x03, |
|---|
| 39 |
OPS_PTAG_CT_ONE_PASS_SIGNATURE =0x04, |
|---|
| 40 |
OPS_PTAG_CT_SECRET_KEY =0x05, |
|---|
| 41 |
OPS_PTAG_CT_PUBLIC_KEY =0x06, |
|---|
| 42 |
OPS_PTAG_CT_SECRET_SUBKEY =0x07, |
|---|
| 43 |
OPS_PTAG_CT_COMPRESSED =0x08, |
|---|
| 44 |
OPS_PTAG_CT_SK_DATA =0x09, |
|---|
| 45 |
OPS_PTAG_CT_MARKER =0x0a, |
|---|
| 46 |
OPS_PTAG_CT_LITERAL_DATA =0x0b, |
|---|
| 47 |
OPS_PTAG_CT_TRUST =0x0c, |
|---|
| 48 |
OPS_PTAG_CT_USER_ID =0x0d, |
|---|
| 49 |
OPS_PTAG_CT_PUBLIC_SUBKEY =0x0e, |
|---|
| 50 |
OPS_PTAG_CT_RESERVED2 =0x0f, |
|---|
| 51 |
OPS_PTAG_CT_RESERVED3 =0x10, |
|---|
| 52 |
OPS_PTAG_CT_USER_ATTRIBUTE =0x11, |
|---|
| 53 |
OPS_PTAG_CT_SK_IP_DATA =0x12, |
|---|
| 54 |
OPS_PTAG_CT_MDC =0x13, |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
OPS_PARSER_ERROR =0x100, |
|---|
| 58 |
OPS_PARSER_PTAG =0x101, |
|---|
| 59 |
} ops_content_tag; |
|---|
| 60 |
|
|---|
| 61 |
typedef struct |
|---|
| 62 |
{ |
|---|
| 63 |
const char *error; |
|---|
| 64 |
} ops_parser_error; |
|---|
| 65 |
|
|---|
| 66 |
typedef struct |
|---|
| 67 |
{ |
|---|
| 68 |
unsigned new_format; |
|---|
| 69 |
unsigned content_tag; |
|---|
| 70 |
ops_ptag_of_lt length_type; |
|---|
| 71 |
unsigned length; |
|---|
| 72 |
unsigned length_read; |
|---|
| 73 |
} ops_parser_ptag; |
|---|
| 74 |
|
|---|
| 75 |
typedef enum |
|---|
| 76 |
{ |
|---|
| 77 |
OPS_PKA_RSA =1, |
|---|
| 78 |
OPS_PKA_RSA_ENCRYPT_ONLY =2, |
|---|
| 79 |
OPS_PKA_RSA_SIGN_ONLY =3, |
|---|
| 80 |
OPS_PKA_ELGAMEL =16, |
|---|
| 81 |
OPS_PKA_DSA =17 |
|---|
| 82 |
} ops_public_key_algorithm; |
|---|
| 83 |
|
|---|
| 84 |
typedef struct |
|---|
| 85 |
{ |
|---|
| 86 |
BIGNUM *p; |
|---|
| 87 |
BIGNUM *q; |
|---|
| 88 |
BIGNUM *g; |
|---|
| 89 |
BIGNUM *y; |
|---|
| 90 |
} ops_dsa_public_key; |
|---|
| 91 |
|
|---|
| 92 |
typedef struct |
|---|
| 93 |
{ |
|---|
| 94 |
BIGNUM *n; |
|---|
| 95 |
BIGNUM *e; |
|---|
| 96 |
} ops_rsa_public_key; |
|---|
| 97 |
|
|---|
| 98 |
typedef union |
|---|
| 99 |
{ |
|---|
| 100 |
ops_dsa_public_key dsa; |
|---|
| 101 |
ops_rsa_public_key rsa; |
|---|
| 102 |
} ops_public_key; |
|---|
| 103 |
|
|---|
| 104 |
typedef struct |
|---|
| 105 |
{ |
|---|
| 106 |
unsigned version; |
|---|
| 107 |
time_t creation_time; |
|---|
| 108 |
ops_public_key_algorithm algorithm; |
|---|
| 109 |
ops_public_key key; |
|---|
| 110 |
} ops_parser_public_key; |
|---|
| 111 |
|
|---|
| 112 |
typedef union |
|---|
| 113 |
{ |
|---|
| 114 |
ops_parser_error error; |
|---|
| 115 |
ops_parser_ptag ptag; |
|---|
| 116 |
ops_parser_public_key public_key; |
|---|
| 117 |
} ops_parser_content; |
|---|