1 /* safe.c Shishi SAFE self tests.
2 * Copyright (C) 2002, 2003 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Shishi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Shishi; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 test (Shishi
* handle
)
36 res
= shishi_safe (handle
, &safe
);
38 printf ("shishi_safe () => `%p'.\n", safe
);
40 success ("shishi_safe() OK\n");
42 fail ("shishi_safe() failed\n");
45 key
= shishi_safe_key (safe
);
47 success ("shishi_safe_key() OK\n");
49 fail ("shishi_safe_key() failed\n");
51 /* shishi_safe_safe */
52 asn1safe
= shishi_safe_safe (safe
);
54 success ("shishi_safe_safe() OK\n");
56 fail ("shishi_safe_safe() failed\n");
58 /* shishi_safe_set_user_data */
59 res
= shishi_safe_set_user_data (handle
, asn1safe
, "foo", 3);
61 success ("shishi_safe_set_user_data() OK\n");
63 fail ("shishi_safe_set_user_data() failed (%d)\n", res
);
65 /* shishi_safe_user_data */
66 res
= shishi_safe_user_data (handle
, asn1safe
, &p
, &l
);
69 if (res
== SHISHI_OK
&& l
== 3 && memcmp (p
, "foo", 3) == 0)
70 success ("shishi_safe_user_data() OK\n");
72 fail ("shishi_safe_user_data() failed (%d)\n", res
);
75 /* shishi_safe_set_cksum */
76 res
= shishi_safe_set_cksum (handle
, asn1safe
, 42, "bar", 3);
78 success ("shishi_safe_set_cksum() OK\n");
80 fail ("shishi_safe_set_cksum() failed (%d)\n", res
);
82 /* shishi_safe_cksum */
83 res
= shishi_safe_cksum (handle
, asn1safe
, &t
, &q
, &m
);
86 printf ("type=%d\n", t
);
89 if (res
== SHISHI_OK
&& t
== 42 && m
== 3 && memcmp (q
, "bar", 3) == 0)
90 success ("shishi_safe_cksum() OK\n");
92 fail ("shishi_safe_cksum() failed (%d)\n", res
);
95 /* shishi_safe_verify */
96 res
= shishi_safe_verify (safe
, key
);
97 if (res
== SHISHI_CRYPTO_ERROR
) /* t==42 unsupported cksumtype */
98 success ("shishi_safe_verify() OK\n");
100 fail ("shishi_safe_verify() failed (%d)\n", res
);
103 /* shishi_safe_set_cksum */
104 res
= shishi_safe_set_cksum (handle
, asn1safe
, SHISHI_RSA_MD5_DES
,
106 if (res
== SHISHI_OK
)
107 success ("shishi_safe_set_cksum() OK\n");
109 fail ("shishi_safe_set_cksum() failed (%d)\n", res
);
111 /* shishi_safe_verify */
112 res
= shishi_safe_verify (safe
, key
);
113 if (res
== SHISHI_VERIFY_FAILED
)
114 success ("shishi_safe_verify() OK\n");
116 fail ("shishi_safe_verify() failed (%d)\n", res
);
119 /* shishi_safe_safe_der() */
120 res
= shishi_safe_safe_der (safe
, &p
, &l
);
121 if (res
== SHISHI_OK
)
122 success ("shishi_safe_safe_der() OK\n");
124 fail ("shishi_safe_safe_der() failed\n");
126 /* shishi_safe_to_file() */
127 res
= shishi_safe_to_file (handle
, asn1safe
, SHISHI_FILETYPE_TEXT
,
129 if (res
== SHISHI_OK
)
130 success ("shishi_safe_to_file() OK\n");
132 fail ("shishi_safe_to_file() failed\n");
134 /* shishi_safe_done() */
135 shishi_safe_done (safe
);
136 success ("shishi_safe_done() OK\n");
138 /* shishi_authenticator_from_file() */
139 res
= shishi_safe_from_file (handle
, &asn1safe
, SHISHI_FILETYPE_TEXT
,
141 if (res
== SHISHI_OK
)
142 success ("shishi_safe_from_file() OK\n");
144 fail ("shishi_safe_from_file() failed\n");
148 /* shishi_safe_print() */
149 res
= shishi_safe_print (handle
, stdout
, asn1safe
);
150 if (res
== SHISHI_OK
)
151 success ("shishi_safe_print() OK\n");
153 fail ("shishi_safe_print() failed\n");
156 /* shishi_asn1_to_der() */
157 res
= shishi_asn1_to_der (handle
, asn1safe
, &q
, &m
);
158 if (res
== SHISHI_OK
)
159 success ("shishi_asn1_to_der() OK\n");
161 fail ("shishi_asn1_to_der() failed\n");
163 /* Compare DER encodings of authenticators */
164 if (l
> 0 && m
> 0 && l
== m
&& memcmp (p
, q
, l
) == 0)
165 success ("DER comparison OK\n");
167 fail ("DER comparison failed\n");
169 shishi_asn1_done (handle
, asn1safe
);
174 res
= unlink ("safe.tmp");
176 success ("unlink() OK\n");
178 fail ("unlink() failed\n");