Debian Codegraph @

runtime/libgcry.h

raw
1 /* libgcry.h - rsyslog's guardtime support library
2 *
3 * Copyright 2013 Adiscon GmbH.
4 *
5 * This file is part of rsyslog.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 * -or-
13 * see COPYING.ASL20 in the source distribution
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21 #ifndef INCLUDED_LIBGCRY_H
22 #define INCLUDED_LIBGCRY_H
23 #include <stdint.h>
24 #include <gcrypt.h>
25
26 struct gcryctx_s {
27 uchar *key;
28 size_t keyLen;
29 int algo;
30 int mode;
31 };
32 typedef struct gcryctx_s *gcryctx;
33 typedef struct gcryfile_s *gcryfile;
34
35 /* this describes a file, as far as libgcry is concerned */
36 struct gcryfile_s {
37 gcry_cipher_hd_t chd; /* cypher handle */
38 size_t blkLength; /* size of low-level crypto block */
39 uchar *eiName; /* name of .encinfo file */
40 int fd; /* descriptor of .encinfo file (-1 if not open) */
41 char openMode; /* 'r': read, 'w': write */
42 gcryctx ctx;
43 uchar *readBuf;
44 int16_t readBufIdx;
45 int16_t readBufMaxIdx;
46 int8_t bDeleteOnClose; /* for queue support, similar to stream subsys */
47 ssize_t bytesToBlkEnd; /* number of bytes remaining in current crypto block
48 -1 means -> no end (still being writen to, queue files),
49 0 means -> end of block, new one must be started. */
50 };
51
52 int rsgcryInit(void);
53 void rsgcryExit(void);
54 int rsgcrySetKey(gcryctx ctx, unsigned char *key, uint16_t keyLen);
55 rsRetVal rsgcrySetMode(gcryctx ctx, uchar *algoname);
56 rsRetVal rsgcrySetAlgo(gcryctx ctx, uchar *modename);
57 gcryctx gcryCtxNew(void);
58 void rsgcryCtxDel(gcryctx ctx);
59 int gcryfileDestruct(gcryfile gf, off64_t offsLogfile);
60 rsRetVal rsgcryInitCrypt(gcryctx ctx, gcryfile *pgf, uchar *fname, char openMode);
61 rsRetVal rsgcryEncrypt(gcryfile pF, uchar *buf, size_t *len);
62 rsRetVal rsgcryDecrypt(gcryfile pF, uchar *buf, size_t *len);
63 rsRetVal gcryfileDeleteState(uchar *fn);
64 rsRetVal gcryfileGetBytesLeftInBlock(gcryfile gf, ssize_t *left);
65 int rsgcryModename2Mode(char *const __restrict__ modename);
66 int rsgcryAlgoname2Algo(char *const __restrict__ algoname);
67
68 /* Note: gf may validly be NULL, e.g. if file has not yet been opened! */
69 static inline void __attribute__((unused)) gcryfileSetDeleteOnClose(gcryfile gf, const int val) {
70 if (gf != NULL) gf->bDeleteOnClose = val;
71 }
72
73 #endif /* #ifndef INCLUDED_LIBGCRY_H */