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