xref: /illumos-gate/usr/src/lib/libsasl/include/saslutil.h (revision 581cede61ac9c14d8d4ea452562a567189eead78)
1 /*
2  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * saslutil.h -- various utility functions in SASL library
8  */
9 
10 #ifndef	_SASL_SASLUTIL_H
11 #define	_SASL_SASLUTIL_H
12 
13 #pragma ident	"%Z%%M%	%I%	%E% SMI"
14 
15 #ifndef	_SASL_SASL_H
16 #include <sasl/sasl.h>
17 #endif
18 
19 #ifdef	__cplusplus
20 extern "C" {
21 #endif
22 
23 /*
24  * base64 decode
25  *  in     -- input data
26  *  inlen  -- length of input data
27  *  out    -- output data (may be same as in, must have enough space)
28  *  outmax  -- max size of output buffer
29  * result:
30  *  outlen -- actual output length
31  *
32  * returns SASL_BADPROT on bad base64,
33  *  SASL_BUFOVER if result won't fit
34  *  SASL_OK on success
35  */
36 LIBSASL_API int sasl_decode64(const char *in, unsigned inlen,
37 			    char *out, unsigned outmax, unsigned *outlen);
38 
39 /*
40  * base64 encode
41  *  in      -- input data
42  *  inlen   -- input data length
43  *  out     -- output buffer (will be NUL terminated)
44  *  outmax  -- max size of output buffer
45  * result:
46  *  outlen  -- gets actual length of output buffer (optional)
47  *
48  * Returns SASL_OK on success, SASL_BUFOVER if result won't fit
49  */
50 LIBSASL_API int sasl_encode64(const char *in, unsigned inlen,
51 			    char *out, unsigned outmax, unsigned *outlen);
52 
53 #if 0
54 /*
55  * The following is not supported:
56  *
57  * make a challenge string (NUL terminated)
58  *  buf      -- buffer for result
59  *  maxlen   -- max length of result
60  *  hostflag -- 0 = don't include hostname, 1 = include hostname
61  * returns final length or 0 if not enough space
62  */
63 LIBSASL_API int sasl_mkchal(sasl_conn_t *conn, char *buf,
64 			    unsigned maxlen, unsigned hostflag);
65 #endif
66 
67 /*
68  * verify a string is valid UTF-8
69  * if len == 0, strlen(str) will be used.
70  * returns SASL_BADPROT on error, SASL_OK on success
71  */
72 LIBSASL_API int sasl_utf8verify(const char *str, unsigned len);
73 
74 #if 0
75 /* The following are not supported */
76 
77 /* create random pool seeded with OS-based params */
78 LIBSASL_API int sasl_randcreate(sasl_rand_t **rpool);
79 
80 /* free random pool from randcreate */
81 LIBSASL_API void sasl_randfree(sasl_rand_t **rpool);
82 
83 /* seed random number generator */
84 LIBSASL_API void sasl_randseed(sasl_rand_t *rpool, const char *seed,
85 				unsigned len);
86 
87 /* generate random octets */
88 LIBSASL_API void sasl_rand(sasl_rand_t *rpool, char *buf, unsigned len);
89 
90 /* churn data into random number generator */
91 LIBSASL_API void sasl_churn(sasl_rand_t *rpool, const char *data,
92 			    unsigned len);
93 #endif
94 
95 /*
96  * erase a security sensitive buffer or password.
97  *   Implementation may use recovery-resistant erase logic.
98  */
99 LIBSASL_API void sasl_erasebuffer(char *pass, unsigned len);
100 
101 #ifdef	__cplusplus
102 }
103 #endif
104 
105 #endif /* _SASL_SASLUTIL_H */
106