1 | /* |
2 | * Copyright (C) 2000-2012 Free Software Foundation, Inc. |
3 | * |
4 | * Author: Nikos Mavrogiannopoulos |
5 | * |
6 | * This file is part of GnuTLS. |
7 | * |
8 | * The GnuTLS is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU Lesser General Public License |
10 | * as published by the Free Software Foundation; either version 2.1 of |
11 | * the License, or (at your option) any later version. |
12 | * |
13 | * This library is distributed in the hope that it will be useful, but |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | * Lesser General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU Lesser General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
20 | * |
21 | */ |
22 | |
23 | /* This file contains the functions needed for 64 bit integer support in |
24 | * TLS, and functions which ease the access to TLS vectors (data of given size). |
25 | */ |
26 | |
27 | #include <gnutls_int.h> |
28 | #include <gnutls_num.h> |
29 | #include <gnutls_errors.h> |
30 | |
31 | /* This function will add one to uint64 x. |
32 | * Returns 0 on success, or -1 if the uint64 max limit |
33 | * has been reached. |
34 | */ |
35 | int |
36 | _gnutls_uint64pp (uint64 * x) |
37 | { |
38 | register int i, y = 0; |
39 | |
40 | for (i = 7; i >= 0; i--) |
41 | { |
42 | y = 0; |
43 | if (x->i[i] == 0xff) |
44 | { |
45 | x->i[i] = 0; |
46 | y = 1; |
47 | } |
48 | else |
49 | x->i[i]++; |
50 | |
51 | if (y == 0) |
52 | break; |
53 | } |
54 | if (y != 0) |
55 | return -1; /* over 64 bits! WOW */ |
56 | |
57 | return 0; |
58 | } |
59 | |
60 | /* This function will add one to uint48 x. |
61 | * Returns 0 on success, or -1 if the uint48 max limit |
62 | * has been reached. |
63 | */ |
64 | int |
65 | _gnutls_uint48pp (uint64 * x) |
66 | { |
67 | register int i, y = 0; |
68 | |
69 | for (i = 7; i >= 3; i--) |
70 | { |
71 | y = 0; |
72 | if (x->i[i] == 0xff) |
73 | { |
74 | x->i[i] = 0; |
75 | y = 1; |
76 | } |
77 | else |
78 | x->i[i]++; |
79 | |
80 | if (y == 0) |
81 | break; |
82 | } |
83 | if (y != 0) |
84 | return -1; /* over 48 bits */ |
85 | |
86 | return 0; |
87 | } |
88 | |