File: sks.h

package info (click to toggle)
sks-ecc 0.93-3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,820 kB
  • ctags: 4,050
  • sloc: ansic: 31,790; asm: 3,281; ada: 1,681; pascal: 1,089; cpp: 1,001; cs: 879; sh: 367; makefile: 340
file content (154 lines) | stat: -rw-r--r-- 4,338 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
 	sks.h
 
	Copyright (C) 2004-2007  Manuel Pancorbo Castro

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program 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 General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

	Manuel Pancorbo Castro <mpancorbo@gmail.com>
 
*/


#ifndef __SKS_H
#define __SKS_H

#define PROGRAM_NAME	"SKS"
#define COPYRIGHT \
 PROGRAM_NAME " v" VERSION " Copyright (C) 2004-2006  Manuel Pancorbo Castro\n"
 
#ifdef LINUX
#include <pwd.h>

#define HOME_VAR		"HOME"
#define KEYRING		"/.skspkr"
#define PRNGFILE	"/.sksprng"

#elif defined WIN32

#define HOME_VAR		"APPDATA"
#define KEY_DIR			"\\SKS"
#define KEYRING		"\\pubkeys.txt"
#define PRNGFILE	"\\prng.bin"

#else
#error "WIN32 or LINUX must be defined"
#endif /*? LINUX*/

#include "eccrypt.h"

#define HASH_SIZE 		GF_SIZE /* 32 */
#define BLOCK_SIZE		16
#define HMAC_SIZE		20 /* Less or equal than HASH_SIZE */
#define PASSWD_SIZE		0x100
#define KEY_SIZE		GF_SIZE

#define SMALL_BUF		0x100
#define MEDIUM_BUF		0x4000
#define LARGE_BUF		0x40000

#define MAX_ALLOC_SIZE  0x100000L /** 1 Mbyte **/

#define DEFAULT_COMP_LEVEL 9 /** From 1-9 **/

/** 
 **  Internal identifiers. No RCF, ISO, NIST recommendation at all
 **/
#define SHA256_CTR	(0x7F)		/** Actually not used **/
#define AES128_CTR  (0x71)
#define AES128_CTR2 (0x73)		/** As AES128_CTR but uses different keys
									for encrytion and HMAC **/
#define COMPRESS_FLAG (0x80)
#define BINARY_FLAG	(0x200)

#define PK_MODE			0
#define SYM_MODE		0x100


typedef struct {
	char lab[SMALL_BUF];
	PubKey val;
	unsigned long int id;
} keychain;

typedef struct{
	keychain *vector, *actual;
	int N;
} keyring;

typedef unsigned char hashout[HASH_SIZE];
typedef unsigned char byte;


/** Input functions **/
ERROR get_text(FILE *inp, char *frase, const char *msg);
ERROR get_privkey(FILE *inp, PrivKey p, const char *msg);

/** Hash functions **/
ERROR hash_binary(byte *buf, byte *bin, size_t len);
ERROR hash_binary_file( FILE *inp);
ERROR hash_password(char *, PrivKey);
ERROR hash_ascii_text( FILE * f_inp, FILE * f_out, int write);
ERROR hash_time (vlPoint c, time_t t);

/** Entropy function **/
int get_entropy(unsigned char *seed, size_t nbytes);

/** AES cipher functions **/
int aes_close(byte *, byte *, int);
ERROR aes_init(byte *, byte *, unsigned int, byte *);
ERROR aes_process(byte *, int, int);
ERROR sym_encrypt(FILE *, FILE *, PubKey, int);
ERROR sym_decrypt(FILE *, FILE *, PubKey, int);

/** Keyring functions **/
FILE * chkopen( char * s, char * mode );
void get_full_path(char * name, char * buf);
FILE * open_keyring(char * mode );
FILE * open_prngfile(void);
ERROR write_pubkey(FILE *, keychain *);
ERROR get_pubkey(FILE *, keychain *);
ERROR get_keyid(PubKey key, unsigned long *id);
ERROR new_key_chain(keyring *kr);
void close_keyring(keyring *kr);
ERROR add_to_keyring(keyring *kr, keychain *);
ERROR load_keyring(FILE *inp, keyring *kr);
ERROR write_keyring();
int search_pubkey(keyring *, int *, char **, FILE *, int);
ERROR import_keyring(FILE *inp);
ERROR delete_element(char *idstring);

/** Most utility functions **/
void write_longint(FILE *ptr, unsigned long int x, int binmode);
int read_longint(FILE *ptr, unsigned long int *x, int binmode);
#define write_timestamp(A, B) write_longint(A, (unsigned long int )B, 0)
#define read_timestamp(A, B) read_longint(A, (unsigned long int *)B, 0)
ERROR write_signature(FILE *ptr, sgPair *sig);
ERROR read_signature(FILE *ptr, sgPair *sig, int binmode);
int position(FILE  * ,/* FILE *,*/ const char *);
int str_match(char *s1, char *s2);
ERROR fputs_base36(PubKey a, FILE *out);
void burn_stack(unsigned long len);
void test_charset();
char * utf8_to_latin1( char *);
#define CHCONV(A) utf8_to_latin1(A)
#define zerokey(A)	memset(A, 0, KEY_SIZE)

enum {
	ES = 0,
	EN
};

#endif	/* ? _SKS_H */