151462Smarkm/* 251462Smarkm * Copyright (c) 1999 351462Smarkm * University of California. All rights reserved. 451462Smarkm * 551462Smarkm * Redistribution and use in source and binary forms, with or without 651462Smarkm * modification, are permitted provided that the following conditions 751462Smarkm * are met: 851462Smarkm * 1. Redistributions of source code must retain the above copyright 951462Smarkm * notice, this list of conditions and the following disclaimer. 1051462Smarkm * 2. Redistributions in binary form must reproduce the above copyright 1151462Smarkm * notice, this list of conditions and the following disclaimer in the 1251462Smarkm * documentation and/or other materials provided with the distribution. 1351462Smarkm * 3. Neither the name of the author nor the names of any co-contributors 1451462Smarkm * may be used to endorse or promote products derived from this software 1551462Smarkm * without specific prior written permission. 1651462Smarkm * 1751462Smarkm * THIS SOFTWARE IS PROVIDED BY CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 1851462Smarkm * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 1951462Smarkm * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2051462Smarkm * ARE DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY 2151462Smarkm * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2251462Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 2351462Smarkm * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2451462Smarkm * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 2551462Smarkm * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 2651462Smarkm * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 2751462Smarkm * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2851462Smarkm */ 2951462Smarkm 3083551Sdillon#include <sys/cdefs.h> 3183551Sdillon__FBSDID("$FreeBSD$"); 3283551Sdillon 3391754Smarkm#include <sys/types.h> 3491754Smarkm 3591754Smarkm#include "crypt.h" 3691754Smarkm 3791754Smarkmstatic char itoa64[] = /* 0 ... 63 => ascii - 64 */ 3851462Smarkm "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 3951462Smarkm 4051462Smarkmvoid 4191754Smarkm_crypt_to64(char *s, u_long v, int n) 4251462Smarkm{ 4351462Smarkm while (--n >= 0) { 4451462Smarkm *s++ = itoa64[v&0x3f]; 4551462Smarkm v >>= 6; 4651462Smarkm } 4751462Smarkm} 48220497Smarkm 49220497Smarkmvoid 50220497Smarkmb64_from_24bit(uint8_t B2, uint8_t B1, uint8_t B0, int n, int *buflen, char **cp) 51220497Smarkm{ 52220497Smarkm uint32_t w; 53220497Smarkm int i; 54220497Smarkm 55220497Smarkm w = (B2 << 16) | (B1 << 8) | B0; 56220497Smarkm for (i = 0; i < n; i++) { 57220497Smarkm **cp = itoa64[w&0x3f]; 58220497Smarkm (*cp)++; 59220497Smarkm if ((*buflen)-- < 0) 60220497Smarkm break; 61220497Smarkm w >>= 6; 62220497Smarkm } 63220497Smarkm} 64