OLD | NEW |
1 /* | 1 /* |
2 * gf2_8.c | 2 * err.c |
3 * | 3 * |
4 * GF(256) finite field implementation, with the representation used | 4 * error status reporting functions |
5 * in the AES cipher. | 5 * |
6 * | |
7 * David A. McGrew | 6 * David A. McGrew |
8 * Cisco Systems, Inc. | 7 * Cisco Systems, Inc. |
9 */ | 8 */ |
10 | |
11 /* | 9 /* |
12 *» | 10 * |
13 * Copyright (c) 2001-2006, Cisco Systems, Inc. | 11 * Copyright(c) 2001-2006 Cisco Systems, Inc. |
14 * All rights reserved. | 12 * All rights reserved. |
15 * | 13 * |
16 * Redistribution and use in source and binary forms, with or without | 14 * Redistribution and use in source and binary forms, with or without |
17 * modification, are permitted provided that the following conditions | 15 * modification, are permitted provided that the following conditions |
18 * are met: | 16 * are met: |
19 * | 17 * |
20 * Redistributions of source code must retain the above copyright | 18 * Redistributions of source code must retain the above copyright |
21 * notice, this list of conditions and the following disclaimer. | 19 * notice, this list of conditions and the following disclaimer. |
22 * | 20 * |
23 * Redistributions in binary form must reproduce the above | 21 * Redistributions in binary form must reproduce the above |
24 * copyright notice, this list of conditions and the following | 22 * copyright notice, this list of conditions and the following |
25 * disclaimer in the documentation and/or other materials provided | 23 * disclaimer in the documentation and/or other materials provided |
26 * with the distribution. | 24 * with the distribution. |
27 * | 25 * |
28 * Neither the name of the Cisco Systems, Inc. nor the names of its | 26 * Neither the name of the Cisco Systems, Inc. nor the names of its |
29 * contributors may be used to endorse or promote products derived | 27 * contributors may be used to endorse or promote products derived |
30 * from this software without specific prior written permission. | 28 * from this software without specific prior written permission. |
31 * | 29 * |
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
35 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | 33 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
36 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | 34 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
37 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 35 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
38 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 36 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
39 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 37 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
40 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
41 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
42 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
43 * OF THE POSSIBILITY OF SUCH DAMAGE. | 41 * OF THE POSSIBILITY OF SUCH DAMAGE. |
44 * | 42 * |
45 */ | 43 */ |
46 | 44 |
47 | |
48 #ifdef HAVE_CONFIG_H | 45 #ifdef HAVE_CONFIG_H |
49 #include <config.h> | 46 #include <config.h> |
50 #endif | 47 #endif |
51 | 48 |
52 #include "datatypes.h" | 49 #include "err.h" |
53 #include "gf2_8.h" | |
54 | 50 |
55 /* gf2_8_shift() moved to gf2_8.h as an inline function */ | |
56 | 51 |
57 gf2_8 | 52 /* srtp_err_level reflects the level of errors that are reported */ |
58 gf2_8_multiply(gf2_8 x, gf2_8 y) { | |
59 gf2_8 z = 0; | |
60 | 53 |
61 if (y & 1) z ^= x; x = gf2_8_shift(x); | 54 srtp_err_reporting_level_t srtp_err_level = srtp_err_level_none; |
62 if (y & 2) z ^= x; x = gf2_8_shift(x); | 55 |
63 if (y & 4) z ^= x; x = gf2_8_shift(x); | 56 /* srtp_err_file is the FILE to which errors are reported */ |
64 if (y & 8) z ^= x; x = gf2_8_shift(x); | 57 |
65 if (y & 16) z ^= x; x = gf2_8_shift(x); | 58 static FILE *srtp_err_file = NULL; |
66 if (y & 32) z ^= x; x = gf2_8_shift(x); | 59 |
67 if (y & 64) z ^= x; x = gf2_8_shift(x); | 60 srtp_err_status_t srtp_err_reporting_init (const char *ident) |
68 if (y & 128) z ^= x; | 61 { |
69 | 62 |
70 return z; | 63 /* |
| 64 * Believe it or not, openlog doesn't return an error on failure. |
| 65 * But then, neither does the syslog() call... |
| 66 */ |
| 67 |
| 68 #ifdef ERR_REPORTING_STDOUT |
| 69 srtp_err_file = stdout; |
| 70 #elif defined(USE_ERR_REPORTING_FILE) |
| 71 /* open file for error reporting */ |
| 72 srtp_err_file = fopen(ERR_REPORTING_FILE, "w"); |
| 73 if (srtp_err_file == NULL) { |
| 74 return srtp_err_status_init_fail; |
| 75 } |
| 76 #endif |
| 77 |
| 78 return srtp_err_status_ok; |
71 } | 79 } |
72 | 80 |
| 81 void srtp_err_report (int priority, const char *format, ...) |
| 82 { |
| 83 va_list args; |
73 | 84 |
74 /* this should use the euclidean algorithm */ | 85 if (priority <= srtp_err_level) { |
75 | 86 |
76 gf2_8 | 87 va_start(args, format); |
77 gf2_8_compute_inverse(gf2_8 x) { | 88 if (srtp_err_file != NULL) { |
78 unsigned int i; | 89 vfprintf(srtp_err_file, format, args); |
79 | 90 /* fprintf(srtp_err_file, "\n"); */ |
80 if (x == 0) return 0; /* zero is a special case */ | 91 } |
81 for (i=0; i < 256; i++) | 92 va_end(args); |
82 if (gf2_8_multiply((gf2_8) i, x) == 1) | 93 } |
83 return (gf2_8) i; | |
84 | |
85 return 0; | |
86 } | 94 } |
87 | 95 |
| 96 void srtp_err_reporting_set_level (srtp_err_reporting_level_t lvl) |
| 97 { |
| 98 srtp_err_level = lvl; |
| 99 } |
OLD | NEW |