Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix gcc warnings #18

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
fa01fe0
libsec: add pbkdf2
adriangrigore Jun 23, 2024
22e00ef
libsec: add rfc5869 hmac-based key derivation function hkdf_x()
adriangrigore Jun 23, 2024
71e5454
libsec: add poly1305
adriangrigore Jun 24, 2024
658ac3f
libsec: add chacha20 poly1305 aead, allow 64 bit iv's for chacha,
adriangrigore Jun 24, 2024
0e8b580
kern/devip-win32.c: include winsock2.h before windows.h
adriangrigore Jul 9, 2024
e0cb8e4
kern/devmnt.c: free pointer in correct order
adriangrigore Jul 9, 2024
64b85ac
kern/win32.c: cast to Rune* and LPCWSTR
adriangrigore Jul 9, 2024
25190f4
libauthsrv/opasstokey.c: copy via memcpy instead of strncpy
adriangrigore Jul 9, 2024
a5deb45
libsec/aes.c: remove unused aes_setupDec
adriangrigore Jul 9, 2024
9682648
include/libsec.h, libsec/des.c: fix inconsistent prototypes for des
adriangrigore Jul 9, 2024
3d41c34
include/libsec.h: have 16 32-bit words in DigestState to avoid out of…
adriangrigore Jul 9, 2024
bb1860d
libmemdraw/draw.c: fix misleading indentation
adriangrigore Jul 9, 2024
9e72b1f
libmemlayer/draw.c: fix misleading indentation
adriangrigore Jul 9, 2024
17c6c70
gui-win32/screen.c: use char* for clipboard functions
adriangrigore Jul 9, 2024
7e290c0
gui-win32/screen.c: remove unused variable
adriangrigore Jul 9, 2024
bc5e0a2
gui-win32/screen.c: add parentheses in window style
adriangrigore Jul 9, 2024
99cc3c6
gui-win32/r16.c: add parentheses around assignment used as truth value
adriangrigore Jul 9, 2024
b7b127f
gui-win32/r16.h: define smalloc
adriangrigore Jul 9, 2024
4f896ab
libc/runevsmprint.c: don't use pointer after realloc
adriangrigore Jul 9, 2024
0122bbe
libc/strtod.c: include ctype.h
adriangrigore Jul 9, 2024
1ea3f71
libc/vsmprint.c: don't use pointer after realloc
adriangrigore Jul 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gui-win32/r16.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ runes16toutf(char *p, Rune16 *r, int nc)

op = p;
ep = p + nc;
while(c = *r++) {
while((c = *r++)) {
n = 1;
if(c >= Runeself)
n = runelen(c);
Expand Down
1 change: 1 addition & 0 deletions gui-win32/r16.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Rune16* runes16dup(Rune16*);
Rune16* utftorunes16(Rune16*, char*, int);
char* runes16toutf(char*, Rune16*, int);
int runes16cmp(Rune16*, Rune16*);
void* smalloc(ulong);
14 changes: 7 additions & 7 deletions gui-win32/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static Rendez rend;
Point ZP;

uint windowStyle;
const uint BORDERLESS = WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_THICKFRAME | WS_SYSMENU | WS_DLGFRAME | WS_CLIPSIBLINGS | WS_VISIBLE | WS_POPUP ^ WS_MINIMIZE | WS_MAXIMIZE;
const uint BORDERLESS = (WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_THICKFRAME | WS_SYSMENU | WS_DLGFRAME | WS_CLIPSIBLINGS | WS_VISIBLE) | (WS_POPUP ^ WS_MINIMIZE) | WS_MAXIMIZE;

static int
isready(void*a)
Expand Down Expand Up @@ -570,12 +570,12 @@ setcolor(ulong index, ulong red, ulong green, ulong blue)
}


uchar*
char*
clipreadunicode(HANDLE h)
{
Rune16 *p;
int n;
uchar *q;
char *q;

p = GlobalLock(h);
n = rune16nlen(p, runes16len(p)+1);
Expand All @@ -586,10 +586,10 @@ clipreadunicode(HANDLE h)
return q;
}

uchar *
char *
clipreadutf(HANDLE h)
{
uchar *p;
char *p;

p = GlobalLock(h);
p = strdup(p);
Expand All @@ -602,7 +602,7 @@ char*
clipread(void)
{
HANDLE h;
uchar *p;
char *p;

if(!OpenClipboard(window)) {
oserror();
Expand All @@ -626,7 +626,7 @@ int
clipwrite(char *buf)
{
HANDLE h;
char *p, *e;
char *p;
Rune16 *rp;
int n = strlen(buf);

Expand Down
29 changes: 24 additions & 5 deletions include/libsec.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,18 @@ struct Chachastate
};
};
int rounds;
int ivwords;
};

void setupChachastate(Chachastate*, uchar*, usize, uchar*, int);
void chacha_setblock(Chachastate*, u32int);
void setupChachastate(Chachastate*, uchar*, usize, uchar*, ulong, int);
void chacha_setiv(Chachastate *, uchar*);
void chacha_setblock(Chachastate*, u64int);
void chacha_encrypt(uchar*, usize, Chachastate*);
void chacha_encrypt2(uchar*, uchar*, usize, Chachastate*);

void ccpoly_encrypt(uchar *dat, ulong ndat, uchar *aad, ulong naad, uchar tag[16], Chachastate *cs);
int ccpoly_decrypt(uchar *dat, ulong ndat, uchar *aad, ulong naad, uchar tag[16], Chachastate *cs);

/*
* DES definitions
*/
Expand All @@ -132,7 +137,7 @@ struct DESstate

void setupDESstate(DESstate *s, uchar key[8], uchar *ivec);
void des_key_setup(uchar[8], ulong[32]);
void block_cipher(ulong*, uchar*, int);
void block_cipher(ulong[32], uchar[8], int);
void desCBCencrypt(uchar*, int, DESstate*);
void desCBCdecrypt(uchar*, int, DESstate*);
void desECBencrypt(uchar*, int, DESstate*);
Expand Down Expand Up @@ -163,7 +168,7 @@ struct DES3state
};

void setupDES3state(DES3state *s, uchar key[3][8], uchar *ivec);
void triple_block_cipher(ulong keys[3][32], uchar*, int);
void triple_block_cipher(ulong keys[3][32], uchar[8], int);
void des3CBCencrypt(uchar*, int, DES3state*);
void des3CBCdecrypt(uchar*, int, DES3state*);
void des3ECBencrypt(uchar*, int, DES3state*);
Expand All @@ -183,6 +188,7 @@ enum
MD4dlen= 16, /* MD4 digest length */
MD5dlen= 16, /* MD5 digest length */
AESdlen= 16, /* TODO: see rfc */
Poly1305dlen= 16, /* Poly1305 digest length */

Hmacblksz = 64, /* in bytes; from rfc2104 */
};
Expand All @@ -192,7 +198,7 @@ struct DigestState
{
uvlong len;
union {
u32int state[8];
u32int state[16];
u64int bstate[8];
};
uchar buf[256];
Expand Down Expand Up @@ -234,6 +240,8 @@ MD5state* md5unpickle(char*);
char* sha1pickle(SHA1state*);
SHA1state* sha1unpickle(char*);

DigestState* poly1305(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);

/*
* random number generation
*/
Expand Down Expand Up @@ -440,3 +448,14 @@ int okThumbprint(uchar *sha1, Thumbprint *ok);
/* readcert.c */
uchar *readcert(char *filename, int *pcertlen);
PEMChain*readcertchain(char *filename);

/* password-based key derivation function 2 (rfc2898) */
void pbkdf2_x(uchar *p, ulong plen, uchar *s, ulong slen, ulong rounds, uchar *d, ulong dlen,
DigestState* (*x)(uchar*, ulong, uchar*, ulong, uchar*, DigestState*), int xlen);

/* hmac-based key derivation function (rfc5869) */
void hkdf_x(uchar *salt, ulong nsalt, uchar *info, ulong ninfo, uchar *key, ulong nkey, uchar *d, ulong dlen,
DigestState* (*x)(uchar*, ulong, uchar*, ulong, uchar*, DigestState*), int xlen);

/* timing safe memcmp() */
int tsmemcmp(void*, void*, ulong);
1 change: 1 addition & 0 deletions kern/devip-win32.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
#include "u.h"
Expand Down
2 changes: 1 addition & 1 deletion kern/devmnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1113,8 +1113,8 @@ mntfree(Mntrpc *r)
lock(&mntalloc.lk);
if(mntalloc.nrpcfree >= 10){
free(r->rpc);
free(r);
freetag(r->request.tag);
free(r);
}
else{
r->list = mntalloc.rpcfree;
Expand Down
4 changes: 2 additions & 2 deletions kern/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ WinMain(HINSTANCE x, HINSTANCE y, LPSTR z, int w)
Rune *warg;

if(0 && win_hasunicode()){
warg = GetCommandLineW();
warg = (Rune*)GetCommandLineW();
n = (wstrlen(warg)+1)*UTFmax;
arg = malloc(n);
wstrtoutf(arg, warg, n);
Expand Down Expand Up @@ -465,6 +465,6 @@ showfilewrite(char *a, int n)
action = Lopen;
arg = cmd;
}
ShellExecute(0, 0, action, arg, 0, SW_SHOWNORMAL);
ShellExecute(0, 0, (LPCWSTR)action, (LPCWSTR)arg, 0, SW_SHOWNORMAL);
return n;
}
2 changes: 1 addition & 1 deletion libauthsrv/opasstokey.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ opasstokey(char *key, char *p)
return 0;
if(n > 10)
n = 10;
strncpy((char*)t, p, n);
memcpy((char*)t, p, n);
if(n >= 9){
c = p[8] & 0xf;
if(n == 10)
Expand Down
13 changes: 7 additions & 6 deletions libc/runevsmprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@ static int
runeFmtStrFlush(Fmt *f)
{
Rune *s;
int n;
int n, d;

if(f->start == nil)
return 0;
n = (uintptr)f->farg;
n *= 2;
s = (Rune*)f->start;
f->start = realloc(s, sizeof(Rune)*n);
if(f->start == nil){
d = (Rune*)f->to - (Rune*)f->start;
s = realloc(f->start, sizeof(Rune)*n);
if(s == nil){
f->farg = nil;
f->to = nil;
f->stop = nil;
free(s);
free(f->start);
return 0;
}
f->start = s;
f->farg = (void*)(uintptr)n;
f->to = (Rune*)f->start + ((Rune*)f->to - s);
f->to = (Rune*)f->start + d;
f->stop = (Rune*)f->start + n - 1;
return 1;
}
Expand Down
1 change: 1 addition & 0 deletions libc/strtod.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <u.h>
#include <libc.h>
#include <ctype.h>
#include "fmtdef.h"

static ulong
Expand Down
13 changes: 7 additions & 6 deletions libc/vsmprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@ static int
fmtStrFlush(Fmt *f)
{
char *s;
int n;
int n, d;

if(f->start == nil)
return 0;
n = (uintptr)f->farg;
n *= 2;
s = (char*)f->start;
f->start = realloc(s, n);
if(f->start == nil){
d = (char*)f->to - (char*)f->start;
s = realloc(f->start, n);
if(s == nil){
f->farg = nil;
f->to = nil;
f->stop = nil;
free(s);
free(f->start);
return 0;
}
f->start = s;
f->farg = (void*)(uintptr)n;
f->to = (char*)f->start + ((char*)f->to - s);
f->to = (char*)f->start + d;
f->stop = (char*)f->start + n - 1;
return 1;
}
Expand Down
8 changes: 4 additions & 4 deletions libmemdraw/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ _memimagedrawsetup(Memimage *dst, Rectangle r, Memimage *src, Point p0, Memimage
if(mask == nil)
mask = memopaque;

DBG print("memimagedraw %p/%luX %R @ %p %p/%luX %P %p/%luX %P... ", dst, dst->chan, r, dst->data->bdata, src, src->chan, p0, mask, mask->chan, p1);
DBG print("memimagedraw %p/%luX %R @ %p %p/%luX %P %p/%luX %P... ", dst, dst->chan, r, dst->data->bdata, src, src->chan, p0, mask, mask->chan, p1);

if(drawclip(dst, &r, src, &p0, mask, &p1, &par.sr, &par.mr) == 0){
// if(drawdebug)
Expand Down Expand Up @@ -776,9 +776,9 @@ DBG print("[");
bmask = rdmask(&mpar, mpar.bufbase, masky);
DBG print("]\n");
bdst = rddst(&dpar, dpar.bufbase, dsty);
DBG dumpbuf("src", bsrc, dx);
DBG dumpbuf("mask", bmask, dx);
DBG dumpbuf("dst", bdst, dx);
DBG dumpbuf("src", bsrc, dx);
DBG dumpbuf("mask", bmask, dx);
DBG dumpbuf("dst", bdst, dx);
bdst = calc(bdst, bsrc, bmask, dx, isgrey, op);
wrdst(&dpar, dpar.bytermin+dsty*dpar.bwidth, bdst);
}
Expand Down
6 changes: 4 additions & 2 deletions libmemlayer/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ memdraw(Memimage *dst, Rectangle r, Memimage *src, Point p0, Memimage *mask, Poi
mask = memopaque;

if(mask->layer){
if(drawdebug) iprint("mask->layer != nil\n");
if(drawdebug)
iprint("mask->layer != nil\n");
return; /* too hard, at least for now */
}

Expand All @@ -75,7 +76,8 @@ if(drawdebug) iprint("mask->layer != nil\n");
}

if(drawclip(dst, &r, src, &p0, mask, &p1, &srcr, &mr) == 0){
if(drawdebug) iprint("drawclip dstcr %R srccr %R maskcr %R\n", dst->clipr, src->clipr, mask->clipr);
if(drawdebug)
iprint("drawclip dstcr %R srccr %R maskcr %R\n", dst->clipr, src->clipr, mask->clipr);
return;
}

Expand Down
5 changes: 5 additions & 0 deletions libsec/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ OFILES=\
sha2_128.$O\
sha2block128.$O\
smallprimes.$O\
pbkdf2.$O\
hkdf.$O\
poly1305.$O\
ccpoly.$O\
tsmemcmp.$O\

default: $(LIB)
$(LIB): $(OFILES)
Expand Down
52 changes: 0 additions & 52 deletions libsec/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ static uchar basekey[3][16] = {

static int aes_setupEnc(ulong rk[/*4*(Nr + 1)*/], const uchar cipherKey[],
int keyBits);
static int aes_setupDec(ulong rk[/*4*(Nr + 1)*/], const uchar cipherKey[],
int keyBits);
static int aes_setup(ulong erk[/*4*(Nr + 1)*/], ulong drk[/*4*(Nr + 1)*/],
const uchar cipherKey[], int keyBits);

Expand Down Expand Up @@ -1240,56 +1238,6 @@ aes_setupEnc(ulong rk[/*4*(Nr + 1)*/], const uchar cipherKey[], int keyBits)
return 0;
}

/**
* Expand the cipher key into the decryption key schedule.
*
* @return the number of rounds for the given cipher key size.
*/
static int
aes_setupDec(ulong rk[/* 4*(Nr + 1) */], const uchar cipherKey[], int keyBits)
{
int Nr, i, j;
ulong temp;

/* expand the cipher key: */
Nr = aes_setupEnc(rk, cipherKey, keyBits);
/* invert the order of the round keys: */
for (i = 0, j = 4*Nr; i < j; i += 4, j -= 4) {
temp = rk[i ]; rk[i ] = rk[j ]; rk[j ] = temp;
temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp;
temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp;
temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp;
}
/*
* apply the inverse MixColumn transform to all round keys
* but the first and the last:
*/
for (i = 1; i < Nr; i++) {
rk += 4;
rk[0] =
Td0[Te4[(rk[0] >> 24) ]] ^
Td1[Te4[(rk[0] >> 16) & 0xff]] ^
Td2[Te4[(rk[0] >> 8) & 0xff]] ^
Td3[Te4[(rk[0] ) & 0xff]];
rk[1] =
Td0[Te4[(rk[1] >> 24) ]] ^
Td1[Te4[(rk[1] >> 16) & 0xff]] ^
Td2[Te4[(rk[1] >> 8) & 0xff]] ^
Td3[Te4[(rk[1] ) & 0xff]];
rk[2] =
Td0[Te4[(rk[2] >> 24) ]] ^
Td1[Te4[(rk[2] >> 16) & 0xff]] ^
Td2[Te4[(rk[2] >> 8) & 0xff]] ^
Td3[Te4[(rk[2] ) & 0xff]];
rk[3] =
Td0[Te4[(rk[3] >> 24) ]] ^
Td1[Te4[(rk[3] >> 16) & 0xff]] ^
Td2[Te4[(rk[3] >> 8) & 0xff]] ^
Td3[Te4[(rk[3] ) & 0xff]];
}
return Nr;
}

/* using round keys in rk, perform Nr rounds of encrypting pt into ct */
void
aes_encrypt(const ulong rk[/* 4*(Nr + 1) */], int Nr, const uchar pt[16],
Expand Down
Loading
Loading