Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/SoftEtherVPN/SoftEtherVPN_Stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordnobori <da.git@softether.co.jp>2015-10-06 14:18:00 +0300
committerdnobori <da.git@softether.co.jp>2015-10-06 14:18:00 +0300
commit4e862a7e40c095ac6ac8b1417890008fbd614ebb (patch)
tree06964105f04db7de0bac733a6c492a34ba24ce74 /src/Mayaqua/Memory.c
parent3c8abd60ed71d09dc09953712c8d5a807932efb9 (diff)
v4.19-9582-beta
Diffstat (limited to 'src/Mayaqua/Memory.c')
-rw-r--r--src/Mayaqua/Memory.c135
1 files changed, 135 insertions, 0 deletions
diff --git a/src/Mayaqua/Memory.c b/src/Mayaqua/Memory.c
index 6810884e..2d9bd9f5 100644
--- a/src/Mayaqua/Memory.c
+++ b/src/Mayaqua/Memory.c
@@ -134,6 +134,70 @@
static UINT fifo_current_realloc_mem_size = FIFO_REALLOC_MEM_SIZE;
+// New PRand
+PRAND *NewPRand(void *key, UINT key_size)
+{
+ PRAND *r;
+ UCHAR dummy[256];
+ if (key == NULL || key_size == 0)
+ {
+ key = "DUMMY";
+ key_size = 5;
+ }
+
+ r = ZeroMalloc(sizeof(PRAND));
+
+ HashSha1(r->Key, key, key_size);
+
+ r->Rc4 = NewCrypt(key, key_size);
+
+ Zero(dummy, sizeof(dummy));
+
+ Encrypt(r->Rc4, dummy, dummy, 256);
+
+ return r;
+}
+
+// Free PRand
+void FreePRand(PRAND *r)
+{
+ if (r == NULL)
+ {
+ return;
+ }
+
+ FreeCrypt(r->Rc4);
+
+ Free(r);
+}
+
+// Generate PRand
+void PRand(PRAND *p, void *data, UINT size)
+{
+ if (p == NULL)
+ {
+ return;
+ }
+
+ Zero(data, size);
+
+ Encrypt(p->Rc4, data, data, size);
+}
+
+// Generate UINT PRand
+UINT PRandInt(PRAND *p)
+{
+ UINT r;
+ if (p == NULL)
+ {
+ return 0;
+ }
+
+ PRand(p, &r, sizeof(UINT));
+
+ return r;
+}
+
// Check whether the specified key item is in the hash list
bool IsInHashListKey(HASH_LIST *h, UINT key)
{
@@ -2368,6 +2432,28 @@ UINT PeekFifo(FIFO *f, void *p, UINT size)
return read_size;
}
+// Read all data from FIFO
+BUF *ReadFifoAll(FIFO *f)
+{
+ BUF *buf;
+ UCHAR *tmp;
+ UINT size;
+ if (f == NULL)
+ {
+ return NewBuf();
+ }
+
+ size = FifoSize(f);
+ tmp = Malloc(size);
+ ReadFifo(f, tmp, size);
+
+ buf = MemToBuf(tmp, size);
+
+ Free(tmp);
+
+ return buf;
+}
+
// Read from the FIFO
UINT ReadFifo(FIFO *f, void *p, UINT size)
{
@@ -3128,6 +3214,21 @@ bool WriteBufInt(BUF *b, UINT value)
return true;
}
+// Write a short integer in the the buffer
+bool WriteBufShort(BUF *b, USHORT value)
+{
+ // Validate arguments
+ if (b == NULL)
+ {
+ return false;
+ }
+
+ value = Endian16(value);
+
+ WriteBuf(b, &value, sizeof(USHORT));
+ return true;
+}
+
// Write a UCHAR to the buffer
bool WriteBufChar(BUF *b, UCHAR uc)
{
@@ -3194,6 +3295,23 @@ UINT ReadBufInt(BUF *b)
return Endian32(value);
}
+// Read a short integer from the buffer
+USHORT ReadBufShort(BUF *b)
+{
+ USHORT value;
+ // Validate arguments
+ if (b == NULL)
+ {
+ return 0;
+ }
+
+ if (ReadBuf(b, &value, sizeof(USHORT)) != sizeof(USHORT))
+ {
+ return 0;
+ }
+ return Endian16(value);
+}
+
// Write the buffer to a buffer
void WriteBufBuf(BUF *b, BUF *bb)
{
@@ -3459,6 +3577,23 @@ BUF *ReadRemainBuf(BUF *b)
return ReadBufFromBuf(b, size);
}
+// Get the length of the rest
+UINT ReadBufRemainSize(BUF *b)
+{
+ // Validate arguments
+ if (b == NULL)
+ {
+ return 0;
+ }
+
+ if (b->Size < b->Current)
+ {
+ return 0;
+ }
+
+ return b->Size - b->Current;
+}
+
// Clone the buffer
BUF *CloneBuf(BUF *b)
{