mirror of https://github.com/dirtbags/moth.git
Clean compile
This commit is contained in:
parent
5a812c5068
commit
a8a1f1f3b2
|
@ -52,19 +52,6 @@ arc4_crypt_buffer(const uint8_t *key, size_t keylen,
|
||||||
arc4_crypt(&ctx, buf, buf, buflen);
|
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
|
#ifdef ARC4_MAIN
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define ARC4_HASHLEN 16
|
|
||||||
|
|
||||||
struct arc4_ctx {
|
struct arc4_ctx {
|
||||||
uint8_t S[256];
|
uint8_t S[256];
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
|
@ -12,6 +12,74 @@
|
||||||
#define CTF_BASE "/var/lib/ctf"
|
#define CTF_BASE "/var/lib/ctf"
|
||||||
#endif
|
#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
|
ssize_t
|
||||||
read_token_fd(int fd,
|
read_token_fd(int fd,
|
||||||
uint8_t const *key, size_t keylen,
|
uint8_t const *key, size_t keylen,
|
||||||
|
|
|
@ -5,8 +5,6 @@ ctfbase-install: ctfbase-build
|
||||||
|
|
||||||
$(call COPYTREE, packages/ctfbase/service, $(CTFBASE_PKGDIR)/service)
|
$(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/tokencli $(CTFBASE_PKGDIR)/bin/
|
||||||
cp packages/ctfbase/src/arc4 $(CTFBASE_PKGDIR)/bin/
|
cp packages/ctfbase/src/arc4 $(CTFBASE_PKGDIR)/bin/
|
||||||
|
|
||||||
|
|
|
@ -11,4 +11,4 @@ install: $(TARGETS)
|
||||||
install -m 0755 $(TARGETS) $(DESTDIR)/bin
|
install -m 0755 $(TARGETS) $(DESTDIR)/bin
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o $(TARGETS)
|
rm -f *.o $(TARGETS)
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
# define TOKEN_MAX 50
|
# define TOKEN_MAX 50
|
||||||
#else
|
#else
|
||||||
# include "token.h"
|
# include "token.h"
|
||||||
# include "arc4.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PID_MAX 32768
|
#define PID_MAX 32768
|
||||||
|
|
|
@ -6,9 +6,7 @@ mcp-install: mcp-build
|
||||||
$(call COPYTREE, packages/mcp/bin, $(MCP_PKGDIR)/bin)
|
$(call COPYTREE, packages/mcp/bin, $(MCP_PKGDIR)/bin)
|
||||||
cp packages/mcp/src/in.tokend $(MCP_PKGDIR)/bin/
|
cp packages/mcp/src/in.tokend $(MCP_PKGDIR)/bin/
|
||||||
cp packages/mcp/src/pointscli $(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/puzzles.cgi $(MCP_PKGDIR)/bin/
|
||||||
cp packages/mcp/src/arc4 $(MCP_PKGDIR)/bin/
|
|
||||||
|
|
||||||
$(call COPYTREE, packages/mcp/service, $(MCP_PKGDIR)/service)
|
$(call COPYTREE, packages/mcp/service, $(MCP_PKGDIR)/service)
|
||||||
|
|
||||||
|
|
|
@ -195,12 +195,12 @@ struct bound_port {
|
||||||
|
|
||||||
int
|
int
|
||||||
bind_port(struct in_addr *addr, int fd, uint16_t port) {
|
bind_port(struct in_addr *addr, int fd, uint16_t port) {
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in saddr;
|
||||||
|
|
||||||
addr.sin_family = AF_INET;
|
saddr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(port);
|
saddr.sin_port = htons(port);
|
||||||
addr.sin_addr.s_addr = *addr;
|
memcpy(&saddr.sin_addr.s_addr, addr, sizeof(struct in_addr));
|
||||||
return bind(fd, (struct sockaddr *)&addr, sizeof(addr));
|
return bind(fd, (struct sockaddr *)&saddr, sizeof(saddr));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -351,7 +351,7 @@ main(int argc, char *argv[])
|
||||||
return EX_IOERR;
|
return EX_IOERR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
addr = INADDR_ANY;
|
addr.s_addr = INADDR_ANY;
|
||||||
}
|
}
|
||||||
|
|
||||||
bound_ports[0].fd = socket(PF_INET, SOCK_DGRAM, 0);
|
bound_ports[0].fd = socket(PF_INET, SOCK_DGRAM, 0);
|
||||||
|
|
Loading…
Reference in New Issue