Trust uboot's device list only if it does not look suspicious.
[AROS.git] / compiler / alib / acrypt.c
blob62e39d8b349486403ba76a4f6dc8c62ce1c56ffc
1 /*
2 * $Id$
4 * :ts=4
6 * Portable ISO 'C' (1994) runtime library for the Amiga computer
7 * Copyright (c) 2002-2006 by Olaf Barthel <olsen (at) sourcery.han.de>
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
14 * - Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * - Neither the name of Olaf Barthel nor the names of contributors
18 * may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
34 #define ACrypt __ACrypt
36 #include <exec/types.h>
37 #include <string.h>
38 #include <clib/alib_protos.h>
40 #undef ACrypt
42 /****************************************************************************/
44 //#include "debug.h"
45 #include <aros/debug.h>
47 /****************************************************************************/
49 #define OSIZE 12
51 /****************************************************************************/
53 UBYTE * ACrypt(UBYTE * buffer, const UBYTE * password, const UBYTE * user);
55 /****************************************************************************/
57 UBYTE *
58 ACrypt(UBYTE * buffer, const UBYTE * password, const UBYTE * user)
60 UBYTE * result = NULL;
61 LONG buf[OSIZE];
62 LONG i,d,k;
64 //ENTER();
65 ALIVE
67 //assert( buffer != NULL && password != NULL && user != NULL );
69 //SHOWPOINTER(buffer);
70 //SHOWSTRING(password);
71 //SHOWSTRING(user);
72 D(bug("[ACrypt] buffer %p password %s user %s\n", buffer, password, user));
74 if(buffer == NULL || password == NULL || user == NULL)
76 //SHOWMSG("invalid parameters");
77 D(bug("[ACrypt] invalid parameters\n"));
78 goto out;
81 for(i = 0 ; i < OSIZE ; i++)
83 if((*password) != '\0')
84 d = (*password++);
85 else
86 d = i;
88 if((*user) != '\0')
89 d += (*user++);
90 else
91 d += i;
93 buf[i] = 'A' + d;
96 for(i = 0 ; i < OSIZE ; i++)
98 for(k = 0 ; k < OSIZE ; k++)
99 buf[i] = (buf[i] + buf[OSIZE - k - 1]) % 53;
101 buffer[i] = buf[i] + 'A';
104 buffer[OSIZE-1] = '\0';
106 //SHOWSTRING(buffer);
107 D(bug("[ACrypt] buffer %s\n", buffer));
109 result = buffer;
111 out:
113 //RETURN(result);
114 D(bug("[ACrypt] return value %s\n", result));
115 return(result);