⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 misc.cpp

📁 伯克利做的SFTP安全文件传输协议
💻 CPP
字号:
// misc.cpp - written and placed in the public domain by Wei Dai//#include "pch.h"#include "misc.h"#include "words.h"void xorbuf(byte *buf, const byte *mask, unsigned int count){	if (((unsigned int)buf | (unsigned int)mask | count) % WORD_SIZE == 0)		XorWords((word *)buf, (const word *)mask, count/WORD_SIZE);	else	{		for (unsigned int i=0; i<count; i++)			buf[i] ^= mask[i];	}}void xorbuf(byte *output, const byte *input, const byte *mask, unsigned int count){	if (((unsigned int)output | (unsigned int)input | (unsigned int)mask | count) % WORD_SIZE == 0)		XorWords((word *)output, (const word *)input, (const word *)mask, count/WORD_SIZE);	else	{		for (unsigned int i=0; i<count; i++)			output[i] = input[i] ^ mask[i];	}}unsigned int Parity(unsigned long value){	for (unsigned int i=8*sizeof(value)/2; i>0; i/=2)		value ^= value >> i;	return (unsigned int)value&1;}// SM: needed by integer.ccunsigned int BytePrecision(unsigned long value){	unsigned int i;	for (i=sizeof(value); i; --i)		if (value >> (i-1)*8)			break;	return i;}// SM: needed by integer.cc unsigned int BitPrecision(unsigned long value){	if (!value)		return 0;	unsigned int l=0, h=8*sizeof(value);	while (h-l > 1)	{		unsigned int t = (l+h)/2;		if (value >> t)			l = t;		else			h = t;	}	return h;}// SM: needed by integer.ccunsigned long Crop(unsigned long value, int size){	if (size < (int)(8*sizeof(value)))    	return (value & ((1L << size) - 1));	else		return value;}// sm: checked allocation (though this isn't used..)static unsigned char const startPost[4] = { 0x87, 0x65, 0x43, 0x21 };static unsigned char const endPost[4] =   { 0xef, 0xcd, 0xab, 0x89 };void *allocCheckOverrun(int bytes){  unsigned char *ret = new unsigned char[bytes+8];    // extra 4 bytes on each side  memcpy(ret, startPost, 4);  memcpy(ret+4+bytes, endPost, 4);  return ret+4;}void freeCheckOverrun(void *ptr, int bytes){  unsigned char *p = ((unsigned char *)ptr) - 4;  if (0!=memcmp(p, startPost, 4) ||      0!=memcmp(p+4+bytes, endPost, 4)) {    xfailure("Overran dynamically allocated buffer!");  }  delete[] p;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -