3 * Common definitions for OCB and related modes
5 * (c) 2018 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
12 * Catacomb is free software: you can redistribute it and/or modify it
13 * under the terms of the GNU Library General Public License as published
14 * by the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * Catacomb is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb. If not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 /*----- Header files ------------------------------------------------------*/
34 /*----- Main code ---------------------------------------------------------*/
36 /* --- @ocb_ctz@, @ocb_ctzl@ --- *
38 * Arguments: @unsigned i@ or @unsigned long i@ = operand, assumed nonzero
40 * Returns: The number of trailing zero bits in @i@, or nonsense if
44 unsigned ocb_ctz(unsigned i
)
48 if (!(i
&0x00ff)) { n
+= 8; i
>>= 8; }
49 if (!(i
&0x000f)) { n
+= 4; i
>>= 4; }
50 if (!(i
&0x0003)) { n
+= 2; i
>>= 2; }
51 if (!(i
&0x0001)) { n
+= 1; i
>>= 1; }
55 unsigned ocb_ctzl(unsigned long i
)
60 while (!(i
&0xfffffffffffffffful
)) { n
+= 64; i
>>= 64; }
63 if (!(i
&0xffffffff)) { n
+= 32; i
>>= 32; }
65 if (!(i
&0xffff)) { n
+= 16; i
>>= 16; }
66 if (!(i
&0x00ff)) { n
+= 8; i
>>= 8; }
67 if (!(i
&0x000f)) { n
+= 4; i
>>= 4; }
68 if (!(i
&0x0003)) { n
+= 2; i
>>= 2; }
69 if (!(i
&0x0001)) { n
+= 1; i
>>= 1; }
73 /*----- That's all, folks -------------------------------------------------*/