(6)Other functions

以下内容源自PBC Library 的 英文manual(Chapter 6)。

本文摘要

六. Other functions

  • 6.1 Random bits
  • 6.2 Custom allocation
  • 6.3 Logging

一,Other functions

Random number generation, memory allocation, logging.

随机数生成,内存分配,日志记录。

6.1. Random bits

The first time PBC is asked to generate a random number, the library will try to open the file /dev/urandom as a source of random bits. If this fails, PBC falls back to a deterministic random number generator (which is of course completely useless for cryptography).

It is possible to change the file used for random bits. Also, explicitly selecting the deterministic random number generator will suppress the warning.

On Windows, by default, PBC uses the Microsoft Crypto API to generate random bits.

第一次要求PBC生成随机数时,库将尝试打开文件/ dev / urandom作为随机位的源。如果失败,PBC将退回到确定性随机数生成器(对于加密术,它当然完全没有用)。

可以更改用于随机位的文件。同样,显式选择确定性随机数生成器将抑制该警告。

在Windows上,默认情况下,PBC使用Microsoft Crypto API生成随机位。

void pbc_random_set_file(char *filename)

Sets filename as a source of random bytes. For example, on Linux one might use /dev/random.

将文件名设置为随机字节源。例如,在Linux上,一个人可能使用/dev/random作为文件名;

void pbc_random_set_deterministic(unsigned int seed)

Uses a determinstic random number generator, seeded with seed.

使用一个确定性的随机数,该生成器带有种子;

void pbc_random_set_function(void (*fun)(mpz_t, mpz_t, void *), void *data)

Uses given function as a random number generator.

使用给出的函数作为随机数生成器;

void pbc_mpz_random(mpz_t z, mpz_t limit)

Selects a random z that is less than limit.

z应当小于limit;

void pbc_mpz_randomb(mpz_t z, unsigned int bits)

Selects a random bits-bit integer z.

选择一个随机位位整数z;

6.2. Custom allocation

Like GMP , PBC can be instructed to use custom memory allocation functions. This must be done before any memory allocation is performed, usually at the beginning of a program before any other PBC functions have been called.

Also like GMP , the PBC wrappers around malloc and realloc will print a message on standard error and terminate program execution if the calls fail. Replacements for these functions should act similarly.

However, unlike GMP , PBC does not pass the number of bytes previously allocated along with the pointer in calls to realloc and free.

像GMP一样,可以指示PBC使用自定义内存分配功能。必须在执行任何内存分配之前完成此操作,通常是在调用任何其他PBC功能之前在程序开始时执行。

与GMP一样,围绕malloc和realloc的PBC包装器将在标准错误时显示一条消息,并在调用失败时终止程序执行。这些功能的替换应具有相似的作用。

但是,与GMP不同,PBC不会在调用realloc和free时,传递先前分配的字节数以及指针。

void pbc_set_memory_functions(void *(*malloc_fn)(size_t), void *(*realloc_fn)(void *, size_t), void(*free_fn)(void *))

Set custom allocation functions. The parameters must be function pointers to drop-in replacements for malloc,realloc and free, except that malloc and realloc should terminate the program on failure: they must not return in
this case.

设置自定义分配功能。参数必须是指向malloc,realloc和free的直接替换的函数指针,除了malloc和realloc应当在失败时终止程序:在这种情况下,它们不得返回。

6.3. Logging

int pbc_set_msg_to_stderr(int i)

By default error messages are printed to standard error. Call pbc_set_msg_to_stderr(0) to suppress messages.

默认情况下,错误消息会打印为标准错误。调用pbc_set_msg_to_stderr(0)禁止显示消息。

void pbc_die(const char *err, . . .)

Reports error message and exits with code 128.

报告错误消息,并且以代码128退出;

void pbc_info(const char *err, . . .)

Reports informational message.

报告参考消息;

void pbc_warn(const char *err, . . .)

Reports warning message.

报告警告消息;

void pbc_error(const char *err, . . .)

Reports error message.

报告错误消息;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章