Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed May 11, 2024
1 parent 63d930f commit f3e91d0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
13 changes: 6 additions & 7 deletions tunnels/client/reality/reality_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ static void upStream(tunnel_t *self, context_t *c)
}
// todo (research) about encapsulation order and safety, CMAC HMAC
shift_buffer_t *buf = c->payload;
c->payload = NULL;
c->payload = NULL;

const int chunk_size = ((1 << 16) - (kSignLen + (2*kEncryptionBlockSize) + kIVlen));
const int chunk_size = ((1 << 16) - (kSignLen + (2 * kEncryptionBlockSize) + kIVlen));

if (bufLen(buf) < chunk_size)
{
Expand All @@ -133,7 +133,7 @@ static void upStream(tunnel_t *self, context_t *c)
signMessage(buf, cstate->msg_digest, cstate->sign_context, cstate->sign_key);
appendTlsHeader(buf);
assert(bufLen(buf) % 16 == 5);
c->payload = buf;
c->payload = buf;

self->up->upStream(self->up, c);
}
Expand All @@ -152,7 +152,7 @@ static void upStream(tunnel_t *self, context_t *c)
assert(bufLen(chunk) % 16 == 5);
self->up->upStream(self->up, cout);
}
reuseBuffer(getContextBufferPool(c),buf);
reuseBuffer(getContextBufferPool(c), buf);
destroyContext(c);
}
}
Expand Down Expand Up @@ -271,9 +271,8 @@ static void downStream(tunnel_t *self, context_t *c)
goto failed;
}

buf = genericDecrypt(buf, cstate->decryption_context, state->context_password,
getContextBufferPool(c));

buf = genericDecrypt(buf, cstate->decryption_context, state->context_password,
getContextBufferPool(c));

context_t *plain_data_ctx = newContextFrom(c);
plain_data_ctx->payload = buf;
Expand Down
31 changes: 17 additions & 14 deletions tunnels/server/reality/reality_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ static void upStream(tunnel_t *self, context_t *c)
return;
}

buf = genericDecrypt(buf, cstate->decryption_context, state->context_password,
getContextBufferPool(c));
buf = genericDecrypt(buf, cstate->decryption_context, state->context_password,
getContextBufferPool(c));

context_t *plain_data_ctx = newContextFrom(c);
plain_data_ctx->payload = buf;
self->up->upStream(self->up, plain_data_ctx);
Expand Down Expand Up @@ -188,9 +188,8 @@ static void upStream(tunnel_t *self, context_t *c)
goto failed;
}

buf = genericDecrypt(buf, cstate->decryption_context, state->context_password,
getContextBufferPool(c));

buf = genericDecrypt(buf, cstate->decryption_context, state->context_password,
getContextBufferPool(c));

context_t *plain_data_ctx = newContextFrom(c);
plain_data_ctx->payload = buf;
Expand Down Expand Up @@ -269,17 +268,17 @@ static void downStream(tunnel_t *self, context_t *c)
self->dw->downStream(self->dw, c);
break;
case kConAuthorized:;
shift_buffer_t *buf = c->payload;
c->payload = NULL;
const int chunk_size = ((1 << 16) - (kSignLen + (2*kEncryptionBlockSize) + kIVlen));
shift_buffer_t *buf = c->payload;
c->payload = NULL;
const int chunk_size = ((1 << 16) - (kSignLen + (2 * kEncryptionBlockSize) + kIVlen));

if (bufLen(buf) < chunk_size)
{
buf = genericEncrypt(buf, cstate->encryption_context, state->context_password, getContextBufferPool(c));
signMessage(buf, cstate->msg_digest, cstate->sign_context, cstate->sign_key);
appendTlsHeader(buf);
assert(bufLen(buf) % 16 == 5);
c->payload = buf;
c->payload = buf;
self->dw->downStream(self->dw, c);
}
else
Expand All @@ -288,16 +287,16 @@ static void downStream(tunnel_t *self, context_t *c)
{
const uint16_t remain = (uint16_t) min(bufLen(buf), chunk_size);
shift_buffer_t *chunk = shallowSliceBuffer(buf, remain);
chunk = genericEncrypt(chunk, cstate->encryption_context, state->context_password,
getContextBufferPool(c));
chunk = genericEncrypt(chunk, cstate->encryption_context, state->context_password,
getContextBufferPool(c));
signMessage(chunk, cstate->msg_digest, cstate->sign_context, cstate->sign_key);
appendTlsHeader(chunk);
context_t *cout = newContextFrom(c);
cout->payload = chunk;
assert(bufLen(chunk) % 16 == 5);
self->dw->downStream(self->dw, cout);
}
reuseBuffer(getContextBufferPool(c),buf);
reuseBuffer(getContextBufferPool(c), buf);
destroyContext(c);
}

Expand All @@ -306,8 +305,12 @@ static void downStream(tunnel_t *self, context_t *c)
}
else
{
if (c->est)
if (c->est )
{
if(cstate->auth_state == kConAuthorized){
destroyContext(c);
return;
}
self->dw->downStream(self->dw, c);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion ww/shiftbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void unShallow(shift_buffer_t *self)
void expand(shift_buffer_t *self, unsigned int increase)
{
const bool keep = self->curpos != self->lenpos;
if (*(self->refc) > 1)
if (isShallow(self))
{
const unsigned int old_realcap = self->full_cap;
unsigned int new_realcap = (unsigned int) pow(2, ceil(log2((old_realcap * 2) + (increase * 2))));
Expand Down

0 comments on commit f3e91d0

Please sign in to comment.