mirror of
https://github.com/isc-projects/bind9.git
synced 2026-02-25 10:59:35 -05:00
32 lines
1 KiB
C
32 lines
1 KiB
C
/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an
|
|
unpublished work protected as such under copyright law. This work
|
|
contains proprietary, confidential, and trade secret information of
|
|
RSA Data Security, Inc. Use, disclosure or reproduction without the
|
|
express written authorization of RSA Data Security, Inc. is
|
|
prohibited.
|
|
*/
|
|
|
|
#include "global.h"
|
|
#include "algae.h"
|
|
|
|
/* Return the number of bits in the canonical, positive integer.
|
|
IntgerBits (0) = 0.
|
|
*/
|
|
unsigned int A_IntegerBits (integer, integerLen)
|
|
unsigned char *integer;
|
|
unsigned int integerLen;
|
|
{
|
|
unsigned char mask, byte;
|
|
unsigned int bytes, bits;
|
|
|
|
for (bytes = 0; bytes < integerLen && integer[bytes] == 0; bytes++);
|
|
if (bytes == integerLen)
|
|
return (0);
|
|
|
|
/* Get byte to test and increment byte count for final calculation */
|
|
byte = integer[bytes++];
|
|
|
|
/* Get number of bits in most significant byte */
|
|
for (bits = 8, mask = 0x80; (byte & mask) == 0; bits--, mask >>= 1);
|
|
return (8 * (integerLen - bytes) + bits);
|
|
}
|