| 1 |
/* Microsoft Reference Implementation for TPM 2.0 |
| 2 |
* |
| 3 |
* The copyright in this software is being made available under the BSD License, |
| 4 |
* included below. This software may be subject to other third party and |
| 5 |
* contributor rights, including patent rights, and no such rights are granted |
| 6 |
* under this license. |
| 7 |
* |
| 8 |
* Copyright (c) Microsoft Corporation |
| 9 |
* |
| 10 |
* All rights reserved. |
| 11 |
* |
| 12 |
* BSD License |
| 13 |
* |
| 14 |
* Redistribution and use in source and binary forms, with or without modification, |
| 15 |
* are permitted provided that the following conditions are met: |
| 16 |
* |
| 17 |
* Redistributions of source code must retain the above copyright notice, this list |
| 18 |
* of conditions and the following disclaimer. |
| 19 |
* |
| 20 |
* Redistributions in binary form must reproduce the above copyright notice, this |
| 21 |
* list of conditions and the following disclaimer in the documentation and/or |
| 22 |
* other materials provided with the distribution. |
| 23 |
* |
| 24 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" |
| 25 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 26 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 27 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
| 28 |
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 29 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 30 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 31 |
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 32 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 33 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 34 |
*/ |
| 35 |
//** Introduction |
| 36 |
// This file contains bit manipulation routines. They operate on bit arrays. |
| 37 |
// |
| 38 |
// The 0th bit in the array is the right-most bit in the 0th octet in |
| 39 |
// the array. |
| 40 |
// |
| 41 |
// NOTE: If pAssert() is defined, the functions will assert if the indicated bit |
| 42 |
// number is outside of the range of 'bArray'. How the assert is handled is |
| 43 |
// implementation dependent. |
| 44 |
|
| 45 |
//** Includes |
| 46 |
|
| 47 |
#include "Tpm.h" |
| 48 |
|
| 49 |
//** Functions |
| 50 |
|
| 51 |
//*** TestBit() |
| 52 |
// This function is used to check the setting of a bit in an array of bits. |
| 53 |
// Return Type: BOOL |
| 54 |
// TRUE(1) bit is set |
| 55 |
// FALSE(0) bit is not set |
| 56 |
BOOL |
| 57 |
TestBit( |
| 58 |
unsigned int bitNum, // IN: number of the bit in 'bArray' |
| 59 |
BYTE *bArray, // IN: array containing the bits |
| 60 |
unsigned int bytesInArray // IN: size in bytes of 'bArray' |
| 61 |
) |
| 62 |
{ |
| 63 |
pAssert(bytesInArray > (bitNum >> 3)); |
| 64 |
return((bArray[bitNum >> 3] & (1 << (bitNum & 7))) != 0); |
| 65 |
} |
| 66 |
|
| 67 |
//*** SetBit() |
| 68 |
// This function will set the indicated bit in 'bArray'. |
| 69 |
void |
| 70 |
SetBit( |
| 71 |
unsigned int bitNum, // IN: number of the bit in 'bArray' |
| 72 |
BYTE *bArray, // IN: array containing the bits |
| 73 |
unsigned int bytesInArray // IN: size in bytes of 'bArray' |
| 74 |
) |
| 75 |
{ |
| 76 |
pAssert(bytesInArray > (bitNum >> 3)); |
| 77 |
bArray[bitNum >> 3] |= (1 << (bitNum & 7)); |
| 78 |
} |
| 79 |
|
| 80 |
//*** ClearBit() |
| 81 |
// This function will clear the indicated bit in 'bArray'. |
| 82 |
void |
| 83 |
ClearBit( |
| 84 |
unsigned int bitNum, // IN: number of the bit in 'bArray'. |
| 85 |
BYTE *bArray, // IN: array containing the bits |
| 86 |
unsigned int bytesInArray // IN: size in bytes of 'bArray' |
| 87 |
) |
| 88 |
{ |
| 89 |
pAssert(bytesInArray > (bitNum >> 3)); |
| 90 |
bArray[bitNum >> 3] &= ~(1 << (bitNum & 7)); |
| 91 |
} |
| 92 |
|