Compare commits
3 commits
f0c2602a3e
...
0b8c024952
Author | SHA1 | Date | |
---|---|---|---|
0b8c024952 | |||
504c8662eb | |||
94dc4821ba |
3 changed files with 23 additions and 5 deletions
|
@ -126,6 +126,6 @@ void md2_second_loop(uint8_t* messageDigestBuf);
|
||||||
* @param messageDigestBuf the message digest buffer
|
* @param messageDigestBuf the message digest buffer
|
||||||
* @param i the index of the 16-byte message block
|
* @param i the index of the 16-byte message block
|
||||||
*/
|
*/
|
||||||
void md2_first_loop(const uint8_t* buf, uint8_t* messageDigestBuf, int i);
|
void md2_first_loop(const uint8_t* buf, uint8_t* messageDigestBuf, size_t i);
|
||||||
|
|
||||||
#endif // MD2_COMMON_H
|
#endif // MD2_COMMON_H
|
|
@ -24,6 +24,25 @@ bool open_file(const char* path, FILE** file, struct stat* file_stat) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long get_available_memory() {
|
||||||
|
FILE* f;
|
||||||
|
struct stat statOfFile;
|
||||||
|
if (!open_file("/proc/meminfo", &f, &statOfFile)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char line[100];
|
||||||
|
while (fgets(line, sizeof(line), f)) {
|
||||||
|
unsigned long available_memory;
|
||||||
|
if (sscanf(line, "MemAvailable: %ld kB", &available_memory) == 1) {
|
||||||
|
fclose(f);
|
||||||
|
return available_memory * 1000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t* read_file(const char* path, size_t* size) {
|
uint8_t* read_file(const char* path, size_t* size) {
|
||||||
// Read the contents of the file specified by path into a heap-allocated
|
// Read the contents of the file specified by path into a heap-allocated
|
||||||
// buffer and return a pointer to that buffer.
|
// buffer and return a pointer to that buffer.
|
||||||
|
@ -33,10 +52,9 @@ uint8_t* read_file(const char* path, size_t* size) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sysinfo info;
|
unsigned long available_memory = get_available_memory();
|
||||||
int r = sysinfo(&info);
|
|
||||||
|
|
||||||
if (r != 0 || info.freeram < (unsigned long)(statOfFile.st_size * 2)) {
|
if (available_memory < (unsigned long)(statOfFile.st_size * 2)) {
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ void md2_second_loop(uint8_t* messageDigestBuf) {
|
||||||
SECOND_LOOP_END_MARK
|
SECOND_LOOP_END_MARK
|
||||||
}
|
}
|
||||||
|
|
||||||
void md2_first_loop(const uint8_t* buf, uint8_t* messageDigestBuf, int i) {
|
void md2_first_loop(const uint8_t* buf, uint8_t* messageDigestBuf, size_t i) {
|
||||||
FIRST_LOOP_START_MARK
|
FIRST_LOOP_START_MARK
|
||||||
for (int j = 0; j < 16; j++) {
|
for (int j = 0; j < 16; j++) {
|
||||||
messageDigestBuf[16 + j] = buf[i * 16 + j];
|
messageDigestBuf[16 + j] = buf[i * 16 + j];
|
||||||
|
|
Loading…
Reference in a new issue