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 30e67f5b9fSMatthew Dillon #include <sys/cdefs.h> 31e67f5b9fSMatthew Dillon __FBSDID("$FreeBSD$"); 32e67f5b9fSMatthew Dillon 33f2ac424aSMark Murray #include <sys/types.h> 34f2ac424aSMark Murray 35f2ac424aSMark Murray #include "crypt.h" 36f2ac424aSMark Murray 37f2ac424aSMark Murray static char itoa64[] = /* 0 ... 63 => ascii - 64 */ 38e9a56ad5SMark Murray "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 39e9a56ad5SMark Murray 40e9a56ad5SMark Murray void 41f2ac424aSMark Murray _crypt_to64(char *s, u_long v, int n) 42e9a56ad5SMark Murray { 43e9a56ad5SMark Murray while (--n >= 0) { 44e9a56ad5SMark Murray *s++ = itoa64[v&0x3f]; 45e9a56ad5SMark Murray v >>= 6; 46e9a56ad5SMark Murray } 47e9a56ad5SMark Murray } 483d6f63c0SMark Murray 493d6f63c0SMark Murray void 50*5f521d7bSEd Schouten b64_from_24bit(uint8_t B2, uint8_t B1, uint8_t B0, int n, char **cp) 513d6f63c0SMark Murray { 523d6f63c0SMark Murray uint32_t w; 533d6f63c0SMark Murray int i; 543d6f63c0SMark Murray 553d6f63c0SMark Murray w = (B2 << 16) | (B1 << 8) | B0; 563d6f63c0SMark Murray for (i = 0; i < n; i++) { 573d6f63c0SMark Murray **cp = itoa64[w&0x3f]; 583d6f63c0SMark Murray (*cp)++; 593d6f63c0SMark Murray w >>= 6; 603d6f63c0SMark Murray } 613d6f63c0SMark Murray } 62