]> git.ozlabs.org Git - ppp.git/blob - pppd/crypto.h
Makefile.am: Add explicit openssl directory to pppd include path
[ppp.git] / pppd / crypto.h
1 /* ppp-crypto.h - Generic API for access to crypto/digest functions.
2  *
3  * Copyright (c) 2022 Eivind Næss. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in
14  *    the documentation and/or other materials provided with the
15  *    distribution.
16  *
17  * 3. The name(s) of the authors of this software must not be used to
18  *    endorse or promote products derived from this software without
19  *    prior written permission.
20  *
21  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
22  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
23  * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
24  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
25  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
26  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
27  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28  */
29
30 #ifndef PPP_CRYPTO_H
31 #define PPP_CRYPTO_H
32
33 #ifndef MD5_DIGEST_LENGTH
34 #define MD5_DIGEST_LENGTH 16
35 #endif
36
37 #ifndef MD4_DIGEST_LENGTH
38 #define MD4_DIGEST_LENGTH 16
39 #endif
40
41 #ifndef SHA_DIGEST_LENGTH
42 #define SHA_DIGEST_LENGTH 20
43 #endif
44
45 struct _PPP_MD_CTX;
46 struct _PPP_MD;
47
48 typedef struct _PPP_MD_CTX PPP_MD_CTX;
49 typedef struct _PPP_MD PPP_MD;
50
51 /*
52  * Create a new Message Digest context object
53  */
54 PPP_MD_CTX *PPP_MD_CTX_new();
55
56 /*
57  * Free the Message Digest context
58  */
59 void PPP_MD_CTX_free(PPP_MD_CTX*);
60
61 /*
62  * Fetch the MD4 algorithm
63  */
64 const PPP_MD *PPP_md4(void);
65
66 /*
67  * Fetch the MD5 algorithm
68  */
69 const PPP_MD *PPP_md5(void);
70
71 /*
72  * Fetch the SHA1 algorithm
73  */
74 const PPP_MD *PPP_sha1(void);
75
76 /*
77  * Initializes a context object
78  */
79 int PPP_DigestInit(PPP_MD_CTX *ctx,
80         const PPP_MD *type);
81
82 /*
83  * For each iteration update the context with more input
84  */
85 int PPP_DigestUpdate(PPP_MD_CTX *ctx,
86         const void *data, size_t cnt);
87
88 /*
89  * Perform the final operation, and output the digest
90  */
91 int PPP_DigestFinal(PPP_MD_CTX *ctx,
92         unsigned char *out, unsigned int *outlen);
93
94
95 struct _PPP_CIPHER_CTX;
96 struct _PPP_CIPHER;
97
98 typedef struct _PPP_CIPHER_CTX PPP_CIPHER_CTX;
99 typedef struct _PPP_CIPHER PPP_CIPHER;
100
101
102 /*
103  * Create a new Cipher Context
104  */
105 PPP_CIPHER_CTX *PPP_CIPHER_CTX_new(void);
106
107 /*
108  * Release the Cipher Context
109  */
110 void PPP_CIPHER_CTX_free(PPP_CIPHER_CTX *ctx);
111
112 /*
113  * Fetch the DES in ECB mode cipher algorithm
114  */
115 const PPP_CIPHER *PPP_des_ecb(void);
116
117 /*
118  * Set the particular data directly
119  */
120 void PPP_CIPHER_CTX_set_cipher_data(PPP_CIPHER_CTX *ctx,
121         const unsigned char *key);
122
123 /*
124  * Initialize the crypto operation
125  */
126 int PPP_CipherInit(PPP_CIPHER_CTX *ctx,
127         const PPP_CIPHER *cipher,
128         const unsigned char *key,
129         const unsigned char *iv,
130         int encr);
131
132 /*
133  * Encrypt input data, and store it in the output buffer
134  */
135 int PPP_CipherUpdate(PPP_CIPHER_CTX *ctx,
136         unsigned char *out, int *outl,
137         const unsigned char *in, int inl);
138
139 /*
140  * Finish the crypto operation, and fetch any outstanding bytes
141  */
142 int PPP_CipherFinal(PPP_CIPHER_CTX *ctx,
143         unsigned char *out, int *outl);
144
145 /*
146  * Global initialization, must be called once per process
147  */
148 int PPP_crypto_init();
149
150 /*
151  * Global deinitialization
152  */
153 int PPP_crypto_deinit();
154
155 #endif