f275112b86d4 — pouya@nohup.io 6 months ago
remove unnecessary function
3 files changed, 6 insertions(+), 15 deletions(-)

M Makefile
M fns.h
M sha.c => hmac.c
M Makefile +1 -1
@@ 5,7 5,7 @@ CCFLAGS=-O
 LDFLAGS=-static
 
 TARG=hotp
-OFILES=main.o sha.o base32.o
+OFILES=main.o hmac.o base32.o
 
 all: ${TARG}
 

          
M fns.h +1 -2
@@ 4,8 4,7 @@ 
 #define nelem(a) (sizeof (a) / sizeof (*(a)))
 #define htonll(i) (htonl(1)==1 ? (i) : (uint64_t)htonl((i)&0xffffffff)<<32 | htonl((i)>>32))
 
-/* sha.c */
-void sha1(uint8_t *buf, uint8_t *data, int n);
+/* hmac.c */
 void hmac1(uint8_t *buf, uint8_t *k, int nk, uint8_t *m, int nm);
 int hotp(uint64_t c, int len, uint8_t *buf, int n);
 

          
M sha.c => hmac.c +4 -12
@@ 6,24 6,16 @@ 
 
 /* buf must be of length SHA1_DIGEST_LENGTH */
 void
-sha1(uint8_t *buf, uint8_t *data, int n) {
-	SHA1_CTX sha;
-
-	SHA1Init(&sha);
-	SHA1Update(&sha, data, n);
-	SHA1Final(buf, &sha);
-}
-
-/* buf must be of length SHA1_DIGEST_LENGTH */
-void
 hmac1(uint8_t *buf, uint8_t *k, int nk, uint8_t *m, int nm) {
 	uint8_t ibuf[SHA1_DIGEST_LENGTH], kbuf[SHA1_DIGEST_LENGTH];
 	uint8_t bbuf[SHA1_BLOCK_LENGTH], *bp, *kp;
 	int i;
-	SHA1_CTX isha, osha;
+	SHA1_CTX isha, osha, ksha;
 
 	if(nk>SHA1_BLOCK_LENGTH) {
-		sha1(kbuf, k, nk);
+		SHA1Init(&ksha);
+		SHA1Update(&ksha, k, nk);
+		SHA1Final(kbuf, &ksha);
 		k = kbuf;
 		nk = nelem(kbuf);
 	}