X-Git-Url: https://git.distorted.org.uk/~mdw/secnet/blobdiff_plain/5ad34db2ccbbfbc936cd16121bed2110b70594ba..af43f0b77a10716921d13c047d1d3c39570cae17:/transform.c diff --git a/transform.c b/transform.c index 012f618..a0665ad 100644 --- a/transform.c +++ b/transform.c @@ -57,11 +57,11 @@ static bool_t transform_setkey(void *sst, uint8_t *key, int32_t keylen) } #endif /* 0 */ - serpent_makekey(&ti->cryptkey,256,key); - serpent_makekey(&ti->mackey,256,key+32); - ti->cryptiv=GET_32BIT_MSB_FIRST(key+64); - ti->maciv=GET_32BIT_MSB_FIRST(key+68); - ti->sendseq=GET_32BIT_MSB_FIRST(key+72); + serpentbe_makekey(&ti->cryptkey,256,key); + serpentbe_makekey(&ti->mackey,256,key+32); + ti->cryptiv=get_uint32(key+64); + ti->maciv=get_uint32(key+68); + ti->sendseq=get_uint32(key+72); ti->lastrecvseq=ti->sendseq; ti->keyed=True; @@ -121,8 +121,8 @@ static uint32_t transform_forward(void *sst, struct buffer_if *buf, it we've have to add 16 bytes to each message, not 4, so that the message stays a multiple of 16 bytes long.) */ memset(iv,0,16); - PUT_32BIT_MSB_FIRST(iv, ti->maciv); - serpent_encrypt(&ti->mackey,iv,macacc); + put_uint32(iv, ti->maciv); + serpentbe_encrypt(&ti->mackey,iv,macacc); /* CBCMAC: encrypt in CBC mode. The MAC is the last encrypted block encrypted once again. */ @@ -130,16 +130,16 @@ static uint32_t transform_forward(void *sst, struct buffer_if *buf, { for (i = 0; i < 16; i++) macplain[i] = macacc[i] ^ n[i]; - serpent_encrypt(&ti->mackey,macplain,macacc); + serpentbe_encrypt(&ti->mackey,macplain,macacc); } - serpent_encrypt(&ti->mackey,macacc,macacc); + serpentbe_encrypt(&ti->mackey,macacc,macacc); memcpy(buf_append(buf,16),macacc,16); /* Serpent-CBC. We expand the ID as for CBCMAC, do the encryption, and prepend the IV before increasing it. */ memset(iv,0,16); - PUT_32BIT_MSB_FIRST(iv, ti->cryptiv); - serpent_encrypt(&ti->cryptkey,iv,iv); + put_uint32(iv, ti->cryptiv); + serpentbe_encrypt(&ti->cryptkey,iv,iv); /* CBC: each block is XORed with the previous encrypted block (or the IV) before being encrypted. */ @@ -149,7 +149,7 @@ static uint32_t transform_forward(void *sst, struct buffer_if *buf, { for (i = 0; i < 16; i++) n[i] ^= p[i]; - serpent_encrypt(&ti->cryptkey,n,n); + serpentbe_encrypt(&ti->cryptkey,n,n); p=n; } @@ -187,19 +187,19 @@ static uint32_t transform_reverse(void *sst, struct buffer_if *buf, memset(iv,0,16); { uint32_t ivword = buf_unprepend_uint32(buf); - PUT_32BIT_MSB_FIRST(iv, ivword); + put_uint32(iv, ivword); } /* Assert bufsize is multiple of blocksize */ if (buf->size&0xf) { *errmsg="msg not multiple of cipher blocksize"; return 1; } - serpent_encrypt(&ti->cryptkey,iv,iv); + serpentbe_encrypt(&ti->cryptkey,iv,iv); for (n=buf->start; nstart+buf->size; n+=16) { for (i = 0; i < 16; i++) pct[i] = n[i]; - serpent_decrypt(&ti->cryptkey,n,n); + serpentbe_decrypt(&ti->cryptkey,n,n); for (i = 0; i < 16; i++) n[i] ^= iv[i]; memcpy(iv, pct, 16); @@ -208,8 +208,8 @@ static uint32_t transform_reverse(void *sst, struct buffer_if *buf, /* CBCMAC */ macexpected=buf_unappend(buf,16); memset(iv,0,16); - PUT_32BIT_MSB_FIRST(iv, ti->maciv); - serpent_encrypt(&ti->mackey,iv,macacc); + put_uint32(iv, ti->maciv); + serpentbe_encrypt(&ti->mackey,iv,macacc); /* CBCMAC: encrypt in CBC mode. The MAC is the last encrypted block encrypted once again. */ @@ -217,9 +217,9 @@ static uint32_t transform_reverse(void *sst, struct buffer_if *buf, { for (i = 0; i < 16; i++) macplain[i] = macacc[i] ^ n[i]; - serpent_encrypt(&ti->mackey,macplain,macacc); + serpentbe_encrypt(&ti->mackey,macplain,macacc); } - serpent_encrypt(&ti->mackey,macacc,macacc); + serpentbe_encrypt(&ti->mackey,macacc,macacc); if (!consttime_memeq(macexpected,macacc,16)!=0) { *errmsg="invalid MAC"; return 1; @@ -234,13 +234,7 @@ static uint32_t transform_reverse(void *sst, struct buffer_if *buf, return 1; } - padp=buf_unappend(buf,padlen-1); - for (i=0; i