import os
import re
common_words = set([
'about', 'after', 'all', 'also', 'an', 'and',
'any', 'are', 'as', 'at',
'be', 'because', 'but', 'by', 'can', 'come',
'could', 'day', 'do', 'even',
'first', 'for', 'get', 'give', 'go', 'has',
'have', 'he', 'her',
'him', 'his', 'how', 'I', 'in', 'into', 'it',
'its', 'just',
'know', 'like', 'look', 'make', 'man', 'many',
'me', 'more', 'my', 'new',
'no', 'not', 'now', 'of', 'one', 'only', 'or',
'other', 'our', 'out',
'over', 'people', 'say', 'see', 'she', 'so',
'some', 'take', 'tell', 'than',
'their', 'them', 'then', 'there', 'these',
'they', 'think',
'this', 'time', 'two', 'up', 'use', 'very',
'want', 'was', 'way',
'we', 'well', 'what', 'when', 'which', 'who',
'will', 'with', 'would',
'year', 'you', 'your'
])
valid_extensions = set([
'c', 'h', 'yaml', 'cmake', 'conf', 'txt', 'overlay',
'rst', 'dtsi',
'Kconfig', 'dts', 'defconfig', 'yml', 'ld', 'sh', 'py',
'soc', 'cfg'
])
def filter_repeated_words(text):
# Split the text into lines
lines = text.split('\n')
# Combine lines into a single string with unique separator
combined_text = '/*sep*/'.join(lines)
# Replace repeated words within a line
def replace_within_line(match):
return match.group(1)
# Regex for matching repeated words within a line
within_line_pattern =
re.compile(r'\b(' +
'|'.join(map(re.escape, common_words)) +
r')\b\s+\b\1\b')
combined_text = within_line_pattern.
sub(replace_within_line, combined_text)
# Replace repeated words across line boundaries
def replace_across_lines(match):
return match.group(1) + match.group(2)
# Regex for matching repeated words across line boundaries
across_lines_pattern = re.
compile(r'\b(' + '|'.join(
map(re.escape, common_words)) +
r')\b(\s*[*\/\n\s]*)\b\1\b')
combined_text = across_lines_pattern.
sub(replace_across_lines, combined_text)
# Split the text back into lines
filtered_text = combined_text.split('/*sep*/')
return '\n'.join(filtered_text)
def process_file(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
text = file.read()
new_text = filter_repeated_words(text)
with open(file_path, 'w', encoding='utf-8') as file:
file.write(new_text)
def process_directory(directory_path):
for root, dirs, files in os.walk(directory_path):
dirs[:] = [d for d in dirs if not d.startswith('.')]
for file in files:
# Filter out hidden files
if file.startswith('.'):
continue
file_extension = file.split('.')[-1]
if
file_extension in valid_extensions: # 只处理指定后缀的文件
file_path = os.path.join(root, file)
print(f"Processed file: {file_path}")
process_file(file_path)
directory_to_process = "/home/mi/works/github/zephyrproject/zephyr"
process_directory(directory_to_process)
Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
131 lines
4.5 KiB
Plaintext
131 lines
4.5 KiB
Plaintext
# Random configuration options
|
|
|
|
# Copyright (c) 2017 Intel Corporation
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
menu "Random Number Generators"
|
|
|
|
config TEST_RANDOM_GENERATOR
|
|
bool "Allow non-random number generator"
|
|
help
|
|
This option signifies that a non-random number generator is allowed to
|
|
be used and the kernel's random number APIs are permitted to return
|
|
values that are not truly random.
|
|
|
|
This capability is provided for testing purposes when a truly random
|
|
number generator is not available. The non-random number generator
|
|
should not be used in a production environment.
|
|
|
|
This option is intended to be selected only by application-level
|
|
configurations (e.g. in tests and samples) to indicate that the
|
|
application is allowed to run with a random number generator that is not
|
|
truly random. Board-level configurations must not select this option
|
|
unless the sole purpose of the board is testing (e.g. QEMU emulation
|
|
boards).
|
|
|
|
Note that this option does not imply that a non-random number generator
|
|
is selected -- that is indicated by RNG_GENERATOR_CHOICE. An entropy
|
|
device-backed random number generator, if available, will be selected by
|
|
default even when CONFIG_TEST_RANDOM_GENERATOR=y.
|
|
|
|
config TIMER_RANDOM_INITIAL_STATE
|
|
int "Initial state used by clock based number generator"
|
|
default 123456789
|
|
help
|
|
Initial state value used by TIMER_RANDOM_GENERATOR and
|
|
early random number genenator.
|
|
|
|
|
|
choice RNG_GENERATOR_CHOICE
|
|
prompt "Random generator"
|
|
default ENTROPY_DEVICE_RANDOM_GENERATOR if ENTROPY_HAS_DRIVER
|
|
default TIMER_RANDOM_GENERATOR if TEST_RANDOM_GENERATOR
|
|
depends on ENTROPY_HAS_DRIVER || TEST_RANDOM_GENERATOR
|
|
help
|
|
Platform dependent non-cryptographically secure random number support.
|
|
|
|
If the entropy support of the platform has sufficient performance
|
|
to support random request then select that. Otherwise, select the
|
|
XOSHIRO algorithm
|
|
|
|
config TIMER_RANDOM_GENERATOR
|
|
bool "System timer clock based number generator"
|
|
depends on TEST_RANDOM_GENERATOR
|
|
help
|
|
This options enables number generator based on system timer
|
|
clock. This number generator is not random and used for
|
|
testing only.
|
|
|
|
config ENTROPY_DEVICE_RANDOM_GENERATOR
|
|
bool "Use entropy driver to generate random numbers"
|
|
depends on ENTROPY_HAS_DRIVER
|
|
help
|
|
Enables a random number generator that uses the enabled hardware
|
|
entropy gathering driver to generate random numbers. Should only be
|
|
selected if hardware entropy driver is designed to be a random
|
|
number generator source.
|
|
|
|
config XOSHIRO_RANDOM_GENERATOR
|
|
bool "Use Xoshiro128++ as PRNG"
|
|
depends on ENTROPY_HAS_DRIVER
|
|
help
|
|
Enables the Xoshiro128++ pseudo-random number generator, that uses
|
|
the entropy driver as a seed source. This is a fast general-purpose
|
|
non-cryptographically secure random number generator.
|
|
|
|
endchoice # RNG_GENERATOR_CHOICE
|
|
|
|
#
|
|
# Implied dependency on a cryptographically secure entropy source when
|
|
# enabling CS generators. ENTROPY_HAS_DRIVER is the flag indicating the
|
|
# CS entropy source.
|
|
#
|
|
config CSPRNG_ENABLED
|
|
bool
|
|
default y
|
|
depends on ENTROPY_HAS_DRIVER
|
|
|
|
choice CSPRNG_GENERATOR_CHOICE
|
|
prompt "Cryptographically secure random generator"
|
|
default HARDWARE_DEVICE_CS_GENERATOR
|
|
help
|
|
Platform dependent cryptographically secure random number support.
|
|
|
|
If the hardware entropy support of the platform has sufficient
|
|
performance to support CSRNG then select that. Otherwise, select
|
|
CTR-DRBG CSPRNG as that is a FIPS140-2 recommended CSPRNG.
|
|
|
|
config HARDWARE_DEVICE_CS_GENERATOR
|
|
bool "Use hardware random driver for CS random numbers"
|
|
depends on ENTROPY_HAS_DRIVER
|
|
help
|
|
Enables a cryptographically secure random number generator that
|
|
uses the enabled hardware random number driver to generate
|
|
random numbers.
|
|
|
|
config CTR_DRBG_CSPRNG_GENERATOR
|
|
bool "Use CTR-DRBG CSPRNG"
|
|
depends on MBEDTLS || TINYCRYPT
|
|
depends on ENTROPY_HAS_DRIVER
|
|
select MBEDTLS_CIPHER_AES_ENABLED if MBEDTLS
|
|
select TINYCRYPT_CTR_PRNG if TINYCRYPT
|
|
select TINYCRYPT_AES if TINYCRYPT
|
|
help
|
|
Enables the CTR-DRBG pseudo-random number generator. This CSPRNG
|
|
shall use the entropy API for an initialization seed. The CTR-DRBG
|
|
is a FIPS140-2 recommended cryptographically secure random number
|
|
generator.
|
|
|
|
endchoice # CSPRNG_GENERATOR_CHOICE
|
|
|
|
config CS_CTR_DRBG_PERSONALIZATION
|
|
string "CTR-DRBG Personalization string"
|
|
default "zephyr ctr-drbg seed"
|
|
depends on CTR_DRBG_CSPRNG_GENERATOR
|
|
help
|
|
Personalization data can be provided in addition to the entropy
|
|
source to make the initialization of the CTR-DRBG as unique as
|
|
possible.
|
|
|
|
endmenu
|