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