Blame lib/num.c

Packit 549fdc
/*
Packit 549fdc
 * Copyright (C) 2000-2012 Free Software Foundation, Inc.
Packit 549fdc
 *
Packit 549fdc
 * Author: Nikos Mavrogiannopoulos
Packit 549fdc
 *
Packit 549fdc
 * This file is part of GnuTLS.
Packit 549fdc
 *
Packit 549fdc
 * The GnuTLS is free software; you can redistribute it and/or
Packit 549fdc
 * modify it under the terms of the GNU Lesser General Public License
Packit 549fdc
 * as published by the Free Software Foundation; either version 2.1 of
Packit 549fdc
 * the License, or (at your option) any later version.
Packit 549fdc
 *
Packit 549fdc
 * This library is distributed in the hope that it will be useful, but
Packit 549fdc
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 549fdc
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 549fdc
 * Lesser General Public License for more details.
Packit 549fdc
 *
Packit 549fdc
 * You should have received a copy of the GNU Lesser General Public License
Packit 549fdc
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
Packit 549fdc
 *
Packit 549fdc
 */
Packit 549fdc
Packit 549fdc
/* This file contains the functions needed for 64 bit integer support in
Packit 549fdc
 * TLS, and functions which ease the access to TLS vectors (data of given size).
Packit 549fdc
 */
Packit 549fdc
Packit 549fdc
#include "gnutls_int.h"
Packit 549fdc
#include <num.h>
Packit 549fdc
#include "errors.h"
Packit 549fdc
Packit 549fdc
/* This function will add one to uint64 x.
Packit 549fdc
 * Returns 0 on success, or -1 if the uint64 max limit
Packit 549fdc
 * has been reached.
Packit 549fdc
 */
Packit 549fdc
int _gnutls_uint64pp(gnutls_uint64 * x)
Packit 549fdc
{
Packit 549fdc
	register int i, y = 0;
Packit 549fdc
Packit 549fdc
	for (i = 7; i >= 0; i--) {
Packit 549fdc
		y = 0;
Packit 549fdc
		if (x->i[i] == 0xff) {
Packit 549fdc
			x->i[i] = 0;
Packit 549fdc
			y = 1;
Packit 549fdc
		} else
Packit 549fdc
			x->i[i]++;
Packit 549fdc
Packit 549fdc
		if (y == 0)
Packit 549fdc
			break;
Packit 549fdc
	}
Packit 549fdc
	if (y != 0)
Packit 549fdc
		return -1;	/* over 64 bits! WOW */
Packit 549fdc
Packit 549fdc
	return 0;
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
/* This function will add one to uint48 x.
Packit 549fdc
 * Returns 0 on success, or -1 if the uint48 max limit
Packit 549fdc
 * has been reached.
Packit 549fdc
 */
Packit 549fdc
int _gnutls_uint48pp(gnutls_uint64 * x)
Packit 549fdc
{
Packit 549fdc
	register int i, y = 0;
Packit 549fdc
Packit 549fdc
	for (i = 7; i >= 3; i--) {
Packit 549fdc
		y = 0;
Packit 549fdc
		if (x->i[i] == 0xff) {
Packit 549fdc
			x->i[i] = 0;
Packit 549fdc
			y = 1;
Packit 549fdc
		} else
Packit 549fdc
			x->i[i]++;
Packit 549fdc
Packit 549fdc
		if (y == 0)
Packit 549fdc
			break;
Packit 549fdc
	}
Packit 549fdc
	if (y != 0)
Packit 549fdc
		return -1;	/* over 48 bits */
Packit 549fdc
Packit 549fdc
	return 0;
Packit 549fdc
}