Cryptography series: memory-bound function

flydean
中文

Introduction

The memory-bound function can be called a memory-bound function, which means that the time to complete a given calculation problem mainly depends on the amount of memory required to save the work data. Corresponding to it is the function of calculating the restricted compute-bound. In the function of calculating the restricted, the calculation steps required for the calculation are the determining factors.

This article will introduce the memory-constrained function and its relationship with the memory function.

Memory function

The names of memory functions and memory-constrained functions seem to be very similar. In fact, their functions are different. Let's first look at the memory functions.

In the learning algorithm, there is a very simple and easy to use algorithm called recursive algorithm. Friends who are familiar with recursive algorithm may know that although recursive algorithm is easy to use, it has a disadvantage that it will repeatedly calculate the function in the recursive process, for example, during recursion. The most classic Fibonacci sequence:

 Recursive_Fibonacci (n)
 {
     if (n == 0)
         return 0
     if (n == 1)
         return 1

     return Recursive_Fibonacci (n-1) + Recursive_Fibonacci (n-2)
 }

It’s very simple, but let’s consider the calculation process, F(3)=F(2)+F(1), and F(4)=F(3)+F(2). In this process, two calculations are required. The value of F(2). If the calculated value of N is large enough, there will be more repeated calculations.

One solution is to store the previously calculated results in memory. This method is called a memory function:

 Fibonacci (n)
 {
     for i = 0 to n-1
         results[i] = -1  // -1 means undefined

     return Fibonacci_Results (results, n);
 }

 Fibonacci_Results (results, n)
 {
     if (results[n] != -1)  // If it has been solved before,
         return results[n]  // look it up.
     if (n == 0)
         val = 0
     else if (n == 1)
         val = 1
     else
         val = Fibonacci_Results(results, n-2 ) + Fibonacci_Results(results, n-1)
     results[n] = val  // Save this result for re-use.

     return val
 }

Although the logic of direct recursion is simple and convenient to write, its time complexity will be higher.

Memory limited functions

The memory-constrained function is mainly used to describe a function that uses XOR. It consists of a series of calculations, each of which depends on the previous calculation.

Because of this memory dependency, memory-limited functions are mainly used in cryptography to prevent brute force cracking of passwords.

Here is a memory-limited function used to prevent spam.

Use of memory-constrained functions

The use of memory-constrained functions to prevent spam mainly uses the principle of POW, that is, you can send me spam, but the premise is that you need to pay some price.

Of course, the original anti-spam principle was to use CPU-limited functions.

In 1992, IBM research scientists Cynthia Dwork and Moni Naor published a paper on CRYPTO titled "Stopping Spam Through Pricing". They proposed a feature that uses CPU-limited functions to prevent abusers from sending spam. Possibility of mail.

The principle of this scheme is: If the cost of spam is very low, then spam may be rampant. If you can add additional computational cost to sending mail in the form of expensive CPU calculations, you can reduce spam. Using the CPU limited function, each email needs to consume a certain amount of CPU resources, thereby preventing a large number of spam emails from being sent in a short period of time.

The CPU limited function is a breakthrough, but it also has its shortcomings.

Because the calculation speed of fast CPU is much faster than slow CPU. In addition, high-end computer systems also have complex pipelines and other optimization functions that are conducive to calculations. Therefore, spammers with high-end systems will hardly be affected by this CPU-constrained function.

This will result in very large differences in computing time due to the differences in the performance of different users' machines. For example, if an algorithm takes a few seconds on an advanced computer, it may take 1 minute on an old computer, and it may take several minutes on a phone with worse performance, then this algorithm is definitely not acceptable to mobile phone users.

Therefore, what researchers are concerned about is how to find a function that runs at roughly the same speed in most computer systems. Although it will be faster on advanced computers, it is only slightly faster, not geometrically. Fast, then it can be within tolerance.

This method is to use memory-constrained functions. A memory-constrained function is a function whose calculation time is dominated by the time to access the memory. Memory-constrained functions access the location of large memory areas in an unpredictable way, and thus cannot use the cache to improve performance.

There are also industrial reasons for using limited memory instead of limited CPU. In recent years, although the computing speed of the CPU has increased dramatically, there has been relatively little progress in the development of faster main memory. So it is foreseeable that in a certain period of time in the future, memory-constrained functions will have more and more application scenarios.

This article has been included in http://www.flydean.com/memory-bound/

The most popular interpretation, the most profound dry goods, the most concise tutorial, and many tips you don't know are waiting for you to discover!

阅读 325

程序那些事
Spring,区块链,密码学,分布式,多线程等教程 欢迎关注我的公众号:程序那些事,更多精彩等着您!

欢迎访问我的个人网站:www.flydean.com

747 声望
409 粉丝
0 条评论

欢迎访问我的个人网站:www.flydean.com

747 声望
409 粉丝
文章目录
宣传栏