chiark / gitweb /
a545edeae9f4cd949516d78dc09ef55034417724
[chiark-tcl.git] / base / chiark-tcl.h
1 /*
2  */
3 /*
4  *  hbytes raw2h BINARY                          => hex
5  *  hbytes h2raw HEX                             => binary
6  *
7  *  hbytes prefix VAR [VALUE ...]         = set VAR [concat VALUE ... $VAR]
8  *  hbytes append VAR [VALUE ...]         = set VAR [concat $VAR VALUE ...]
9  *  hbytes concat VAR [VALUE ...]         = set VAR [concat VALUE ...]
10  *  hbytes unprepend VAR PREFIXLENGTH            => prefix (removed from VAR)
11  *  hbytes unappend VAR SUFFIXLENGTH             => suffix (removed from VAR)
12  *  hbytes chopto VAR NEWVARLENGTH               => suffix (removed from VAR)
13  *                                                  (too short? error)
14  *
15  *  hbytes pkcs5 pa|ua VAR ALG                   => worked?  (always 1 for p)
16  *  hbytes pkcs5 pn|un VAR BLOCKSIZE             => worked?  (always 1 for p)
17  *  hbytes blockcipher d|e VAR ALG MODE [IV]     => IV
18  *
19  *  hbytes hash ALG MESSAGE                      => hash
20  *  hbytes hmac ALG MESSAGE KEY [MACLENGTH]      => mac
21  *
22  * Refs: HMAC: RFC2104
23  */
24
25 #ifndef HBYTES_H
26 #define HBYTES_H
27
28 #include <assert.h>
29 #include <stdlib.h>
30
31 #include <tcl.h>
32
33 typedef unsigned char Byte;
34
35 /* from hbytes.c */
36
37 typedef struct {
38   Byte *start, *end; /* always allocated dynamically */
39 } HBytes_Value; /* overlays internalRep */
40
41 extern Tcl_ObjType hbytes_type;
42
43 int staticerr(Tcl_Interp *ip, const char *m);
44 void objfreeir(Tcl_Obj *o);
45
46 void hbytes_set(HBytes_Value *upd, const Byte *array, int l);
47 Tcl_Obj *hbytes_set_obj(Tcl_Obj *overwrite, const Byte *array, int l);
48
49 /* from parse.c */
50
51 typedef struct {
52   HBytes_Value *hb;
53   Tcl_Obj *obj, *var;
54 } HBytes_Var;
55
56 void fini_hbv(Tcl_Interp *ip, int rc, HBytes_Var *agg);
57
58 /* from enum.c */
59
60 extern Tcl_ObjType enum_nearlytype;
61 extern Tcl_ObjType enum1_nearlytype;
62
63 const void *enum_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o,
64                                     const void *firstentry, size_t entrysize,
65                                     const char *what);
66 #define enum_lookup_cached(ip,o,table,what)                     \
67     (enum_lookup_cached_func((ip),(o),                          \
68                              sizeof((table)[0]),&(table)[0],    \
69                              (what)))
70   /* table should be a pointer to an array of structs of size
71    * entrysize, the first member of which should be a const char*.
72    * The table should finish with a null const char *.
73    * On error, 0 is returned and the ip->result will have been
74    * set to the error message.
75    */
76
77 int enum1_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o,
78                              const char *opts, const char *what);
79   /* -1 => error */
80
81 /* from crypto.c */
82
83 typedef struct {
84   int blocksize, hashsize;
85 } HashAlgInfo;
86
87 typedef struct {
88   int blocksize;
89 } BlockCipherAlgInfo;
90
91 typedef struct {
92   int dummy;
93 } BlockCipherModeInfo;
94
95 /* useful macros */
96
97 #define HBYTES(o) (*(HBytes_Value*)&(o)->internalRep.twoPtrValue)
98 #define HBYTES_LEN(hb) ((hb).end - (hb).start)
99
100 #define TALLOC(s) ((void*)Tcl_Alloc((s)))
101 #define TFREE(f) (Tcl_Free((void*)(f)))
102
103 #endif /*HBYTES_H*/