xref: /freebsd/lib/libcrypt/misc.c (revision e9a56ad5ca9a9ce91608f6a0b6e1c0f9c71598db)
1e9a56ad5SMark Murray /*
2e9a56ad5SMark Murray  * Copyright (c) 1999
3e9a56ad5SMark Murray  *      University of California.  All rights reserved.
4e9a56ad5SMark Murray  *
5e9a56ad5SMark Murray  * Redistribution and use in source and binary forms, with or without
6e9a56ad5SMark Murray  * modification, are permitted provided that the following conditions
7e9a56ad5SMark Murray  * are met:
8e9a56ad5SMark Murray  * 1. Redistributions of source code must retain the above copyright
9e9a56ad5SMark Murray  *    notice, this list of conditions and the following disclaimer.
10e9a56ad5SMark Murray  * 2. Redistributions in binary form must reproduce the above copyright
11e9a56ad5SMark Murray  *    notice, this list of conditions and the following disclaimer in the
12e9a56ad5SMark Murray  *    documentation and/or other materials provided with the distribution.
13e9a56ad5SMark Murray  * 3. Neither the name of the author nor the names of any co-contributors
14e9a56ad5SMark Murray  *    may be used to endorse or promote products derived from this software
15e9a56ad5SMark Murray  *    without specific prior written permission.
16e9a56ad5SMark Murray  *
17e9a56ad5SMark Murray  * THIS SOFTWARE IS PROVIDED BY CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
18e9a56ad5SMark Murray  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19e9a56ad5SMark Murray  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20e9a56ad5SMark Murray  * ARE DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY
21e9a56ad5SMark Murray  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22e9a56ad5SMark Murray  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23e9a56ad5SMark Murray  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24e9a56ad5SMark Murray  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25e9a56ad5SMark Murray  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26e9a56ad5SMark Murray  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27e9a56ad5SMark Murray  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28e9a56ad5SMark Murray  *
29e9a56ad5SMark Murray  * $FreeBSD$
30e9a56ad5SMark Murray  *
31e9a56ad5SMark Murray  */
32e9a56ad5SMark Murray 
33e9a56ad5SMark Murray static unsigned char itoa64[] =		/* 0 ... 63 => ascii - 64 */
34e9a56ad5SMark Murray 	"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
35e9a56ad5SMark Murray 
36e9a56ad5SMark Murray void
37e9a56ad5SMark Murray _crypt_to64(s, v, n)
38e9a56ad5SMark Murray 	char *s;
39e9a56ad5SMark Murray 	unsigned long v;
40e9a56ad5SMark Murray 	int n;
41e9a56ad5SMark Murray {
42e9a56ad5SMark Murray 	while (--n >= 0) {
43e9a56ad5SMark Murray 		*s++ = itoa64[v&0x3f];
44e9a56ad5SMark Murray 		v >>= 6;
45e9a56ad5SMark Murray 	}
46e9a56ad5SMark Murray }
47