196196/*
197197 * Initialize Sosemanuk's state by providing a key. The key is an array of
198198 * 1 to 32 bytes.
199- * @param ss The Sosemanuk state
199+ * @param st The Sosemanuk state
200200 * @param key Key
201201 * @param keylen Length of key in bytes
202202 * @return CRYPT_OK on success
203203 */
204- int sosemanuk_setup (sosemanuk_state * ss , const unsigned char * key , unsigned long keylen )
204+ int sosemanuk_setup (sosemanuk_state * st , const unsigned char * key , unsigned long keylen )
205205{
206206 /*
207207 * This key schedule is actually a truncated Serpent key schedule.
@@ -216,10 +216,10 @@ int sosemanuk_setup(sosemanuk_state *ss, const unsigned char *key, unsigned long
216216 r2 = w ## o2; \
217217 r3 = w ## o3; \
218218 S(r0, r1, r2, r3, r4); \
219- ss ->kc[i ++] = r ## d0; \
220- ss ->kc[i ++] = r ## d1; \
221- ss ->kc[i ++] = r ## d2; \
222- ss ->kc[i ++] = r ## d3; \
219+ st ->kc[i ++] = r ## d0; \
220+ st ->kc[i ++] = r ## d1; \
221+ st ->kc[i ++] = r ## d2; \
222+ st ->kc[i ++] = r ## d3; \
223223 } while (0)
224224
225225#define SKS0 SKS(S0, 4, 5, 6, 7, 1, 4, 2, 0)
@@ -255,7 +255,7 @@ int sosemanuk_setup(sosemanuk_state *ss, const unsigned char *key, unsigned long
255255 ulong32 w0 , w1 , w2 , w3 , w4 , w5 , w6 , w7 ;
256256 int i = 0 ;
257257
258- LTC_ARGCHK (ss != NULL );
258+ LTC_ARGCHK (st != NULL );
259259 LTC_ARGCHK (key != NULL );
260260 LTC_ARGCHK (keylen > 0 && keylen <= 32 );
261261
@@ -329,22 +329,22 @@ int sosemanuk_setup(sosemanuk_state *ss, const unsigned char *key, unsigned long
329329 * encryptions/decryptions are to be performed with the same key and
330330 * sosemanuk_done() has not been called, only sosemanuk_setiv() need be called
331331 * to set the state.
332- * @param ss The Sosemanuk state
332+ * @param st The Sosemanuk state
333333 * @param iv Initialization vector
334334 * @param ivlen Length of iv in bytes
335335 * @return CRYPT_OK on success
336336 */
337- int sosemanuk_setiv (sosemanuk_state * ss , const unsigned char * iv , unsigned long ivlen )
337+ int sosemanuk_setiv (sosemanuk_state * st , const unsigned char * iv , unsigned long ivlen )
338338{
339339
340340 /*
341341 * The Serpent key addition step.
342342 */
343343#define KA (zc , x0 , x1 , x2 , x3 ) do { \
344- x0 ^= ss ->kc[(zc)]; \
345- x1 ^= ss ->kc[(zc) + 1]; \
346- x2 ^= ss ->kc[(zc) + 2]; \
347- x3 ^= ss ->kc[(zc) + 3]; \
344+ x0 ^= st ->kc[(zc)]; \
345+ x1 ^= st ->kc[(zc) + 1]; \
346+ x2 ^= st ->kc[(zc) + 2]; \
347+ x3 ^= st ->kc[(zc) + 3]; \
348348 } while (0)
349349
350350 /*
@@ -374,7 +374,7 @@ int sosemanuk_setiv(sosemanuk_state *ss, const unsigned char *iv, unsigned long
374374 ulong32 r0 , r1 , r2 , r3 , r4 ;
375375 unsigned char ivtmp [16 ] = {0 };
376376
377- LTC_ARGCHK (ss != NULL );
377+ LTC_ARGCHK (st != NULL );
378378 LTC_ARGCHK (ivlen <= 16 );
379379 LTC_ARGCHK (iv != NULL || ivlen == 0 );
380380
@@ -404,34 +404,34 @@ int sosemanuk_setiv(sosemanuk_state *ss, const unsigned char *iv, unsigned long
404404 FSS (36 , S1 , 1 , 3 , 2 , 4 , 0 , 2 , 1 , 4 , 3 );
405405 FSS (40 , S2 , 2 , 1 , 4 , 3 , 0 , 4 , 3 , 1 , 0 );
406406 FSS (44 , S3 , 4 , 3 , 1 , 0 , 2 , 3 , 1 , 0 , 2 );
407- ss -> s09 = r3 ;
408- ss -> s08 = r1 ;
409- ss -> s07 = r0 ;
410- ss -> s06 = r2 ;
407+ st -> s09 = r3 ;
408+ st -> s08 = r1 ;
409+ st -> s07 = r0 ;
410+ st -> s06 = r2 ;
411411
412412 FSS (48 , S4 , 3 , 1 , 0 , 2 , 4 , 1 , 4 , 3 , 2 );
413413 FSS (52 , S5 , 1 , 4 , 3 , 2 , 0 , 4 , 2 , 1 , 3 );
414414 FSS (56 , S6 , 4 , 2 , 1 , 3 , 0 , 4 , 2 , 0 , 1 );
415415 FSS (60 , S7 , 4 , 2 , 0 , 1 , 3 , 3 , 1 , 2 , 4 );
416416 FSS (64 , S0 , 3 , 1 , 2 , 4 , 0 , 1 , 0 , 2 , 3 );
417417 FSS (68 , S1 , 1 , 0 , 2 , 3 , 4 , 2 , 1 , 3 , 0 );
418- ss -> r1 = r2 ;
419- ss -> s04 = r1 ;
420- ss -> r2 = r3 ;
421- ss -> s05 = r0 ;
418+ st -> r1 = r2 ;
419+ st -> s04 = r1 ;
420+ st -> r2 = r3 ;
421+ st -> s05 = r0 ;
422422
423423 FSS (72 , S2 , 2 , 1 , 3 , 0 , 4 , 3 , 0 , 1 , 4 );
424424 FSS (76 , S3 , 3 , 0 , 1 , 4 , 2 , 0 , 1 , 4 , 2 );
425425 FSS (80 , S4 , 0 , 1 , 4 , 2 , 3 , 1 , 3 , 0 , 2 );
426426 FSS (84 , S5 , 1 , 3 , 0 , 2 , 4 , 3 , 2 , 1 , 0 );
427427 FSS (88 , S6 , 3 , 2 , 1 , 0 , 4 , 3 , 2 , 4 , 1 );
428428 FSF (92 , S7 , 3 , 2 , 4 , 1 , 0 , 0 , 1 , 2 , 3 );
429- ss -> s03 = r0 ;
430- ss -> s02 = r1 ;
431- ss -> s01 = r2 ;
432- ss -> s00 = r3 ;
429+ st -> s03 = r0 ;
430+ st -> s02 = r1 ;
431+ st -> s01 = r2 ;
432+ st -> s00 = r3 ;
433433
434- ss -> ptr = sizeof (ss -> buf );
434+ st -> ptr = sizeof (st -> buf );
435435
436436#undef KA
437437#undef FSS
@@ -585,7 +585,7 @@ static const ulong32 mul_ia[] = {
585585 * Compute the next block of bits of output stream. This is equivalent
586586 * to one full rotation of the shift register.
587587 */
588- static LTC_INLINE void _sosemanuk_internal (sosemanuk_state * ss )
588+ static LTC_INLINE void _sosemanuk_internal (sosemanuk_state * st )
589589{
590590 /*
591591 * MUL_A(x) computes alpha * x (in F_{2^32}).
@@ -656,24 +656,24 @@ static LTC_INLINE void _sosemanuk_internal(sosemanuk_state *ss)
656656 */
657657#define SRD (S , x0 , x1 , x2 , x3 , ooff ) do { \
658658 S(u0, u1, u2, u3, u4); \
659- STORE32L(u ## x0 ^ v0, ss ->buf + ooff); \
660- STORE32L(u ## x1 ^ v1, ss ->buf + ooff + 4); \
661- STORE32L(u ## x2 ^ v2, ss ->buf + ooff + 8); \
662- STORE32L(u ## x3 ^ v3, ss ->buf + ooff + 12); \
659+ STORE32L(u ## x0 ^ v0, st ->buf + ooff); \
660+ STORE32L(u ## x1 ^ v1, st ->buf + ooff + 4); \
661+ STORE32L(u ## x2 ^ v2, st ->buf + ooff + 8); \
662+ STORE32L(u ## x3 ^ v3, st ->buf + ooff + 12); \
663663 } while (0)
664664
665- ulong32 s00 = ss -> s00 ;
666- ulong32 s01 = ss -> s01 ;
667- ulong32 s02 = ss -> s02 ;
668- ulong32 s03 = ss -> s03 ;
669- ulong32 s04 = ss -> s04 ;
670- ulong32 s05 = ss -> s05 ;
671- ulong32 s06 = ss -> s06 ;
672- ulong32 s07 = ss -> s07 ;
673- ulong32 s08 = ss -> s08 ;
674- ulong32 s09 = ss -> s09 ;
675- ulong32 r1 = ss -> r1 ;
676- ulong32 r2 = ss -> r2 ;
665+ ulong32 s00 = st -> s00 ;
666+ ulong32 s01 = st -> s01 ;
667+ ulong32 s02 = st -> s02 ;
668+ ulong32 s03 = st -> s03 ;
669+ ulong32 s04 = st -> s04 ;
670+ ulong32 s05 = st -> s05 ;
671+ ulong32 s06 = st -> s06 ;
672+ ulong32 s07 = st -> s07 ;
673+ ulong32 s08 = st -> s08 ;
674+ ulong32 s09 = st -> s09 ;
675+ ulong32 r1 = st -> r1 ;
676+ ulong32 r2 = st -> r2 ;
677677 ulong32 u0 , u1 , u2 , u3 , u4 ;
678678 ulong32 v0 , v1 , v2 , v3 ;
679679
@@ -703,18 +703,18 @@ static LTC_INLINE void _sosemanuk_internal(sosemanuk_state *ss)
703703 STEP (09 , 00 , 01 , 02 , 03 , 04 , 05 , 06 , 07 , 08 , v3 , u3 );
704704 SRD (S2 , 2 , 3 , 1 , 4 , 64 );
705705
706- ss -> s00 = s00 ;
707- ss -> s01 = s01 ;
708- ss -> s02 = s02 ;
709- ss -> s03 = s03 ;
710- ss -> s04 = s04 ;
711- ss -> s05 = s05 ;
712- ss -> s06 = s06 ;
713- ss -> s07 = s07 ;
714- ss -> s08 = s08 ;
715- ss -> s09 = s09 ;
716- ss -> r1 = r1 ;
717- ss -> r2 = r2 ;
706+ st -> s00 = s00 ;
707+ st -> s01 = s01 ;
708+ st -> s02 = s02 ;
709+ st -> s03 = s03 ;
710+ st -> s04 = s04 ;
711+ st -> s05 = s05 ;
712+ st -> s06 = s06 ;
713+ st -> s07 = s07 ;
714+ st -> s08 = s08 ;
715+ st -> s09 = s09 ;
716+ st -> r1 = r1 ;
717+ st -> r2 = r2 ;
718718}
719719
720720/*
@@ -737,41 +737,41 @@ static LTC_INLINE void _xorbuf(const unsigned char *in1, const unsigned char *in
737737 * buffer, combined by XOR with the stream, and the result is written
738738 * in the "out" buffer. "in" and "out" must be either equal, or
739739 * reference distinct buffers (no partial overlap is allowed).
740- * @param ss The Sosemanuk state
740+ * @param st The Sosemanuk state
741741 * @param in Data in
742742 * @param inlen Length of data in bytes
743743 * @param out Data out
744744 * @return CRYPT_OK on success
745745 */
746- int sosemanuk_crypt (sosemanuk_state * ss ,
746+ int sosemanuk_crypt (sosemanuk_state * st ,
747747 const unsigned char * in , unsigned long inlen , unsigned char * out )
748748{
749- LTC_ARGCHK (ss != NULL );
749+ LTC_ARGCHK (st != NULL );
750750 LTC_ARGCHK (in != NULL );
751751 LTC_ARGCHK (out != NULL );
752752
753- if (ss -> ptr < (sizeof (ss -> buf ))) {
754- unsigned long rlen = (sizeof (ss -> buf )) - ss -> ptr ;
753+ if (st -> ptr < (sizeof (st -> buf ))) {
754+ unsigned long rlen = (sizeof (st -> buf )) - st -> ptr ;
755755
756756 if (rlen > inlen ) {
757757 rlen = inlen ;
758758 }
759- _xorbuf (ss -> buf + ss -> ptr , in , out , rlen );
759+ _xorbuf (st -> buf + st -> ptr , in , out , rlen );
760760 in += rlen ;
761761 out += rlen ;
762762 inlen -= rlen ;
763- ss -> ptr += rlen ;
763+ st -> ptr += rlen ;
764764 }
765765 while (inlen > 0 ) {
766- _sosemanuk_internal (ss );
767- if (inlen >= sizeof (ss -> buf )) {
768- _xorbuf (ss -> buf , in , out , sizeof (ss -> buf ));
769- in += sizeof (ss -> buf );
770- out += sizeof (ss -> buf );
771- inlen -= sizeof (ss -> buf );
766+ _sosemanuk_internal (st );
767+ if (inlen >= sizeof (st -> buf )) {
768+ _xorbuf (st -> buf , in , out , sizeof (st -> buf ));
769+ in += sizeof (st -> buf );
770+ out += sizeof (st -> buf );
771+ inlen -= sizeof (st -> buf );
772772 } else {
773- _xorbuf (ss -> buf , in , out , inlen );
774- ss -> ptr = inlen ;
773+ _xorbuf (st -> buf , in , out , inlen );
774+ st -> ptr = inlen ;
775775 inlen = 0 ;
776776 }
777777 }
@@ -783,29 +783,29 @@ int sosemanuk_crypt(sosemanuk_state *ss,
783783/*
784784 * Cipher operation, as a PRNG: the provided output buffer is filled with
785785 * pseudo-random bytes as output from the stream cipher.
786- * @param ss The Sosemanuk state
786+ * @param st The Sosemanuk state
787787 * @param out Data out
788788 * @param outlen Length of output in bytes
789789 * @return CRYPT_OK on success
790790 */
791- int sosemanuk_keystream (sosemanuk_state * ss , unsigned char * out , unsigned long outlen )
791+ int sosemanuk_keystream (sosemanuk_state * st , unsigned char * out , unsigned long outlen )
792792{
793793 if (outlen == 0 ) return CRYPT_OK ; /* nothing to do */
794794 LTC_ARGCHK (out != NULL );
795795 XMEMSET (out , 0 , outlen );
796- return sosemanuk_crypt (ss , out , outlen , out );
796+ return sosemanuk_crypt (st , out , outlen , out );
797797}
798798
799799
800800/*
801801 * Terminate and clear Sosemanuk key context
802- * @param ss The Sosemanuk state
802+ * @param st The Sosemanuk state
803803 * @return CRYPT_OK on success
804804 */
805- int sosemanuk_done (sosemanuk_state * ss )
805+ int sosemanuk_done (sosemanuk_state * st )
806806{
807- LTC_ARGCHK (ss != NULL );
808- XMEMSET (ss , 0 , sizeof (sosemanuk_state ));
807+ LTC_ARGCHK (st != NULL );
808+ XMEMSET (st , 0 , sizeof (sosemanuk_state ));
809809 return CRYPT_OK ;
810810}
811811
0 commit comments