Clean compile

This commit is contained in:
Neale Pickett 2011-02-08 14:09:48 -07:00
parent cd723d922e
commit 3d3de7cb05
8 changed files with 75 additions and 27 deletions

View File

@ -52,19 +52,6 @@ arc4_crypt_buffer(const uint8_t *key, size_t keylen,
arc4_crypt(&ctx, buf, buf, buflen);
}
void
arc4_hash(uint8_t const *buf, size_t buflen,
uint8_t *hash)
{
struct arc4_ctx ctx;
int i;
arc4_init(&ctx, buf, buflen);
for (i = 0; i < ARC4_HASHLEN; i += 1) {
hash[i] = arc4_out(&ctx);
}
}
#ifdef ARC4_MAIN

View File

@ -4,8 +4,6 @@
#include <stdint.h>
#include <stdlib.h>
#define ARC4_HASHLEN 16
struct arc4_ctx {
uint8_t S[256];
uint8_t i;

View File

@ -12,6 +12,74 @@
#define CTF_BASE "/var/lib/ctf"
#endif
/*
*
* ARC-4 stuff
*
*/
struct arc4_ctx {
uint8_t S[256];
uint8_t i;
uint8_t j;
};
#define swap(a, b) do {int _swap=a; a=b, b=_swap;} while (0)
void
arc4_init(struct arc4_ctx *ctx, uint8_t const *key, size_t keylen)
{
int i;
int j = 0;
for (i = 0; i < 256; i += 1) {
ctx->S[i] = i;
}
for (i = 0; i < 256; i += 1) {
j = (j + ctx->S[i] + key[i % keylen]) % 256;
swap(ctx->S[i], ctx->S[j]);
}
ctx->i = 0;
ctx->j = 0;
}
uint8_t
arc4_out(struct arc4_ctx *ctx)
{
ctx->i = (ctx->i + 1) % 256;
ctx->j = (ctx->j + ctx->S[ctx->i]) % 256;
swap(ctx->S[ctx->i], ctx->S[ctx->j]);
return ctx->S[(ctx->S[ctx->i] + ctx->S[ctx->j]) % 256];
}
void
arc4_crypt(struct arc4_ctx *ctx,
uint8_t *obuf, const uint8_t *ibuf, size_t buflen)
{
size_t k;
for (k = 0; k < buflen; k += 1) {
obuf[k] = ibuf[k] ^ arc4_out(ctx);
}
}
void
arc4_crypt_buffer(const uint8_t *key, size_t keylen,
uint8_t *buf, size_t buflen)
{
struct arc4_ctx ctx;
arc4_init(&ctx, key, keylen);
arc4_crypt(&ctx, buf, buf, buflen);
}
/*
*
*/
ssize_t
read_token_fd(int fd,
uint8_t const *key, size_t keylen,

View File

@ -5,8 +5,6 @@ ctfbase-install: ctfbase-build
$(call COPYTREE, packages/ctfbase/service, $(CTFBASE_PKGDIR)/service)
cp packages/ctfbase/setup $(CTFBASE_PKGDIR)/
cp packages/ctfbase/src/tokencli $(CTFBASE_PKGDIR)/bin/
cp packages/ctfbase/src/arc4 $(CTFBASE_PKGDIR)/bin/

View File

@ -28,7 +28,6 @@
# define TOKEN_MAX 50
#else
# include "token.h"
# include "arc4.h"
#endif
#define PID_MAX 32768

View File

@ -6,9 +6,7 @@ mcp-install: mcp-build
$(call COPYTREE, packages/mcp/bin, $(MCP_PKGDIR)/bin)
cp packages/mcp/src/in.tokend $(MCP_PKGDIR)/bin/
cp packages/mcp/src/pointscli $(MCP_PKGDIR)/bin/
cp packages/mcp/src/tokencli $(MCP_PKGDIR)/bin/
cp packages/mcp/src/puzzles.cgi $(MCP_PKGDIR)/bin/
cp packages/mcp/src/arc4 $(MCP_PKGDIR)/bin/
$(call COPYTREE, packages/mcp/service, $(MCP_PKGDIR)/service)

View File

@ -195,12 +195,12 @@ struct bound_port {
int
bind_port(struct in_addr *addr, int fd, uint16_t port) {
struct sockaddr_in addr;
struct sockaddr_in saddr;
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = *addr;
return bind(fd, (struct sockaddr *)&addr, sizeof(addr));
saddr.sin_family = AF_INET;
saddr.sin_port = htons(port);
memcpy(&saddr.sin_addr.s_addr, addr, sizeof(struct in_addr));
return bind(fd, (struct sockaddr *)&saddr, sizeof(saddr));
}
int
@ -351,7 +351,7 @@ main(int argc, char *argv[])
return EX_IOERR;
}
} else {
addr = INADDR_ANY;
addr.s_addr = INADDR_ANY;
}
bound_ports[0].fd = socket(PF_INET, SOCK_DGRAM, 0);