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