A method, apparatus and circuit for generating a MAC address
By controlling the charging and discharging of capacitors to obtain voltage values when network devices start up, and using these voltage values to determine random seeds to generate MAC addresses, the problem of duplicate MAC addresses in existing technologies is solved, ensuring the uniqueness of MAC addresses and guaranteeing the stability and security of local area network communication.
Patent Information
- Application Number
- CN202411033767.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-30
- Publication Date
- 2025-12-05
- Estimated Expiration
- 2044-07-30
AI Technical Summary
In existing technologies, the MAC addresses of micro-embedded system devices are prone to duplication during communication, leading to instability in local area network communication.
The voltage value of the capacitor is obtained by controlling the charging or discharging process. A random seed is determined based on the voltage value. The random seed is used to generate a MAC address. The uniqueness of the MAC address is ensured by combining the CPU bus bit width and hash algorithm.
It effectively reduces the probability of MAC address duplication, ensures the stability and security of local area network communication, and prevents MAC addresses from being predicted and forged.
Smart Images

Figure CN119030956B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer processing technology, specifically to a MAC address generation method, apparatus, and circuit. Background Technology
[0002] A Media Access Control (MAC) address is a unique identifier for a network interface controller. It is used for transmitting data frames within a local area network (LAN) and helps network devices locate and communicate within the network. In network communication, each network device needs a unique identifier for accurate identification and location; the MAC address is this identifier.
[0003] There are two main ways to generate MAC addresses: pre-assignment, where the manufacturer pre-assigns a globally unique MAC address to the device during the manufacturing process; and random generation, where the network device may randomly generate a MAC address, for example, some virtual machines or software-defined network devices may randomly generate a MAC address when they start up.
[0004] Typically, some small embedded system devices need to generate their own MAC addresses for communication within a local area network. Currently, the default method is to use the U-Boot boot time as a random seed. U-Boot is a bootloader used to start a computer's operating system. However, because U-Boot is single-threaded, the boot time varies little. Therefore, the random seed has a range, and the generated random numbers have a certain probability of repetition, resulting in duplicate MAC addresses. Summary of the Invention
[0005] In view of this, embodiments of this application provide a MAC address generation method, apparatus, and circuit to solve the problem of duplicate MAC addresses within a local area network.
[0006] To address the above problems, the technical solutions provided in this application are as follows:
[0007] In a first aspect of this application, a MAC address generation method is provided, the method being applied to a network device, comprising:
[0008] In response to the network device starting up,
[0009] The target circuit is used to determine a random seed by controlling the charging or discharging of a capacitor in the target circuit.
[0010] During the charging or discharging process of the capacitor, the voltage value of the capacitor is acquired;
[0011] A random seed is determined based on the target integer value corresponding to the voltage value. Different voltage values correspond to different integer values, and the range of the integer values is determined by the number of bus bits of the central processing unit (CPU) in the network device.
[0012] The MAC address of the network device is generated using the random seed.
[0013] In a second aspect of this application, a MAC address generation apparatus is provided, the apparatus comprising:
[0014] A control unit is configured to control the charging or discharging of a capacitor in a target circuit in response to the startup of the network device, the target circuit being configured to determine a random seed;
[0015] The acquisition unit is used to acquire the voltage value of the capacitor during the charging or discharging process of the capacitor;
[0016] The acquisition unit is further configured to determine a random seed based on the target integer value corresponding to the voltage value, wherein different voltage values correspond to different integer values, and the range of the integer values is determined by the number of bus bits of the central processing unit (CPU) in the network device.
[0017] A generation unit is used to generate the MAC address of the network device using the random seed.
[0018] In a third aspect of this application, a target circuit is provided, the target circuit comprising: a power supply, a resistor, a capacitor, and a MOSFET, wherein the MOSFET is used to control the capacitor to charge or discharge;
[0019] The first end of the resistor is connected to the power supply, the second end of the resistor is connected to the first end of the capacitor, and the second end of the capacitor is grounded. The first end of the MOSFET is connected to the second end of the resistor and the first end of the capacitor, and the second end of the MOSFET is grounded.
[0020] In a fourth aspect of this application, a network device is provided, including: a processor and a memory;
[0021] The memory is used to store computer-readable instructions or computer programs;
[0022] The processor is configured to read the computer-readable instructions or the computer program to cause the electronic device to implement the method described in the first aspect.
[0023] In a fifth aspect of this application, a computer-readable storage medium is provided, wherein instructions are stored therein, which, when executed on a device, cause the device to perform the method described in the first aspect.
[0024] In a sixth aspect of this application, a computer program product is provided that, when the computer program product is run on a computer, causes the computer to perform the method described in the first aspect.
[0025] Therefore, the embodiments of this application have the following beneficial effects:
[0026] In this application, when the network device starts up, the capacitor in the target circuit is charged or discharged. During the charging or discharging process, the voltage value of the capacitor is acquired, and the target integer value corresponding to the voltage value is obtained. Then, a random seed is obtained based on the target integer value, and the MAC address of the network device is generated using the random seed. Since the voltage value of the capacitor changes constantly during the charging or discharging process, and the range of the target integer value corresponding to the voltage value is large (for example, if the CPU bus bit width is 16, the range is 0-65535), the range of the random seed is also large, thereby reducing the probability of MAC address duplication. Attached Figure Description
[0027] Figure 1 This is a target circuit structure according to an embodiment of the present application;
[0028] Figure 2 A flowchart of a MAC address generation method provided in this application embodiment;
[0029] Figure 3 This is a structural diagram of a MAC address generation device provided in an embodiment of this application. Detailed Implementation
[0030] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, the embodiments of this application will be further described in detail below with reference to the accompanying drawings and specific implementation methods.
[0031] Research has revealed that because current network devices default to using the U-Boot startup time as the seed for the srand function, and since U-Boot is single-threaded with minimal startup time variation, the seed has a limited range, resulting in a certain probability of repetition in the generated random numbers. Furthermore, because the srand function is also random, although the pseudo-random number sequence appears random, it is theoretically possible to reproduce the entire random number sequence using a known algorithm and seed, since it is generated through a deterministic process.
[0032] Based on this, this application provides a MAC address generation method. After the network device starts up, a random seed is generated using a target circuit, and then a MAC address is generated based on the random seed. Specifically, the charging / discharging of a capacitor in the target circuit is controlled. During the charging / discharging process, the voltage value of the capacitor is acquired and converted into a corresponding integer value. Since this integer value is determined by the number of bits of the CPU bus, which is typically no less than 16 bits, the integer value ranges from 0 to 65535. This large range allows for a larger variation range of the random seed, thereby reducing the probability of duplicate MAC addresses.
[0033] This application involves two functions: the `srand` function and the `rand` function. Before generating random numbers, the `rand` function requires a seed provided by the system to generate a pseudo-random number sequence. `rand` generates a series of random numbers based on this seed value. If the seed provided by the system does not change, the pseudo-random number sequence generated by each call to the `rand` function will be the same. `srand(unsigned seed)` changes the seed value provided by the system through the `seed` parameter, thus ensuring that the pseudo-random number sequence generated by each call to the `rand` function is different, thereby achieving true "randomness".
[0034] To facilitate understanding of the technical solutions provided in the embodiments of this application, the target circuits included in the network device of this application will be described below.
[0035] See Figure 1 This figure is a target circuit structure diagram provided in an embodiment of this application, such as... Figure 1 As shown, the target circuit 100 includes: a power supply 101, a resistor 102, a capacitor 103, and a MOSFET 104.
[0036] Among them, resistor 102 (e.g.) Figure 1 The first terminal of resistor 102 is connected to power supply 101, and the second terminal of resistor 102 is connected to capacitor 103 (e.g., ...). Figure 1 The first end of C1) is connected to the ground, the second end of capacitor 103 is grounded, the first end of MOSFET 104 is connected to the second end of resistor 102 and the first end of capacitor 103 respectively, and the second end of MOSFET 104 is grounded.
[0037] The second end of resistor 102 is also connected to the CPU's PINx pin, and the gate of MOSFET 104 is connected to the CPU's PINy pin. When the CPU is powered on, the PINy pin is at a high level, causing capacitor 103 to discharge. After discharging, the PINy pin is configured to a low level, controlling capacitor 103 to begin charging.
[0038] During the charging or discharging process of capacitor 103, the CPU obtains the voltage value of capacitor 103, determines a random seed based on the voltage value, and then determines the MAC address of the network device based on the random seed.
[0039] It should be noted that the values of the power supply, resistor, and capacitor are determined based on the actual application. Figure 1 This is merely an example and does not constitute a limitation of this application.
[0040] Based on the target circuit described above, the process of generating a MAC address will be explained below with reference to the accompanying drawings.
[0041] See Figure 2 The figure is a flowchart of a MAC address generation method provided in an embodiment of this application, as shown below. Figure 2 As shown, the method includes:
[0042] S201: In response to the startup of a network device, control the charging or discharging of a capacitor in the target circuit.
[0043] S202: Obtain the voltage value of the capacitor during the charging or discharging process.
[0044] Once the network device is started, the CPU can control the charging or discharging of the capacitors in the target circuit and read the voltage value of the capacitors during the charging or discharging process.
[0045] The structure of the target circuit is as follows: Figure 1 As shown, when the network device is powered on, if the gate of the configured MOS transistor is at a high level, the capacitor is controlled to discharge; if the gate of the configured MOS transistor is at a low level, the capacitor is controlled to discharge.
[0046] S203: Determine the random seed based on the target integer value corresponding to the voltage value.
[0047] S204: Use this random seed to generate the MAC address of the network device.
[0048] After reading the capacitor's voltage value, a random seed can be determined based on the target integer value corresponding to that voltage value. This seed, along with the `rand` function, is then used to generate random numbers. Once the random numbers are obtained, they are converted to hexadecimal numbers. These hexadecimal numbers are grouped into sets of two, arranged in ascending order, and one byte of the MAC address is extracted from each set, padding with zeros if necessary. Finally, six groups of hexadecimal numbers form a new MAC address.
[0049] Typically, the random seed is an integer not less than 0. Therefore, a correspondence between voltage values and integers can be established within a preset numerical range. After obtaining the voltage value, the integer value corresponding to the current voltage value is determined based on this correspondence, and this integer value is used as the random seed. The preset numerical range can be determined according to the actual application. For example, it can be determined based on the CPU's bus bit width. Assuming the CPU's bus bit width is 16 bits, the value range is 0-65535. Therefore, the random seed's value range is 0-65535. In this case, the obtained voltage value is mapped to the range 0-65535, and the mapped value corresponding to the current voltage value is used as the random seed. For example, if the capacitor voltage has a maximum value of 3.3V and a minimum of 0V, then 3.3V corresponds to 65535, and 0V corresponds to -0.
[0050] Considering that the CPU's bus width is relatively easy to obtain, a correspondence will be established between voltage values and values determined by the CPU's bus width. After establishing this correspondence, the target integer value corresponding to the voltage value will be determined based on the voltage value and the above correspondence. This correspondence includes the relationship between different voltage values and integer values; different voltage values correspond to different integer values, and the range of these integer values is determined by the CPU's bus width in the network device.
[0051] To further increase the randomness of the seed, voltage values can be randomly read at two moments during the capacitor's charging or discharging process. For each voltage value, an integer value corresponding to that voltage value is determined based on the aforementioned correspondence. The product of the two integer values is then used as the random seed. For example, if an integer value ranges from 0 to 65536, the product of the two integer values would range from 0 to 65536 * 65536 = 0 to 4294967296. Randomly selecting a number from 4.2 billion as the random seed makes it very difficult to repeat.
[0052] Specifically, during the charging or discharging process of the capacitor, a first voltage value corresponding to the capacitor at a first moment and a second voltage value corresponding to the capacitor at a second moment are obtained; a random seed is obtained based on the first voltage value and the second voltage value.
[0053] The process of obtaining a random seed based on a first voltage value and a second voltage value includes: determining a first target integer value based on the first voltage value and its corresponding relationship; determining a second target integer value based on the second voltage value and its corresponding relationship; and using the product of the first target integer value and the second target integer value as the random seed.
[0054] To enhance the security of the random seed, hash algorithm encryption technology can be introduced to ensure that the generated MAC address is not only random but also difficult to predict and forge. Specifically, the random seed is hashed to obtain a hash value; the hash value is then used to generate the MAC address of the network device. That is, the hash value is used as the final random seed to generate a random number, and then the MAC address of the network device is determined based on this random number.
[0055] To further increase the randomness of the seed, the measured value of the analog-to-digital converter (ADC) in the network device can be read when the network device starts up. This ADC measurement value is then integrated with the voltage value, and a random seed is obtained based on the integration result. Specifically, the product of the target integer value corresponding to the voltage value and the third target integer value corresponding to the ADC measurement value is used as the random seed. The range of the third target integer value is determined by the resolution of the ADC.
[0056] It's important to note that network devices begin reading ADC values upon power-up. Ideally, the ADC is zero, but due to the influence of external environmental factors such as electromagnetic radiation, coupling noise, power supply noise, temperature, and humidity, the ADC itself has conversion errors. Therefore, each ADC measurement may differ, thus increasing randomness. The ADC resolution indicates how many bits the ADC uses to represent the digital value of the analog signal; this value determines the range of the quantization result. For example, a 12-bit ADC can quantize an analog signal into a range of 0 to 2^12-1, or 0 to 4095. This conversion allows the ADC to map analog voltages from 0 to 3V to a digital value range of 0 to 4095. When the CPU's bus width is 16, the product of the target integer value corresponding to the capacitor voltage and the third target integer value corresponding to the ADC measurement ranges from 0 to 65535*4095, increasing the range of selectable random seeds and reducing the probability of repetition.
[0057] Alternatively, the ADC measurement value and the voltage value can be added first, and then the sum can be converted into a fourth target integer value, which can be used as a random seed. The fourth target integer value is determined by the CPU's bus bit width. In other words, the sum is mapped to 0-2. x-1 Within.
[0058] In this implementation, a hash algorithm can also be introduced to perform hash calculations on a random seed obtained based on the ADC measurement value and the capacitor voltage value, and use the calculated hash value as the final random seed.
[0059] In some scenarios, given the uniqueness of the CPU ID, it can be used as part of the random seed generation to increase the randomness of the seed. Specifically, the CPU identifier in the network device is obtained; the voltage value is integrated with the CPU identifier to obtain the random seed.
[0060] Specifically, a correspondence between the CPU identifier and a preset integer value is established in advance. After obtaining the CPU identifier, the corresponding fifth target integer value is obtained through the above correspondence. The voltage value of the capacitor is converted into the target integer value according to its corresponding correspondence. The sum of the target integer value and the fifth target integer value is used as a random seed.
[0061] In this implementation, a hash algorithm can also be introduced to perform a hash calculation on the random seed obtained through the CPU identifier and the voltage value of the capacitor, and use the calculated hash value as the final random seed.
[0062] To maximize the randomness of the seed, the voltage value, the ADC measurement value, and the CPU identifier can be used simultaneously as factors in generating the random seed. Based on this, in response to network device startup, the ADC measurement value and the CPU identifier in the network device are obtained; the voltage value, ADC measurement value, and CPU identifier are integrated, and a random seed is obtained based on the integrated result.
[0063] Specifically, the sum of the product of the target integer value corresponding to the capacitor's voltage value and the third target integer value corresponding to the ADC's measurement value, and the fifth target integer value corresponding to the CPU's identifier, is used as the final random seed to generate random numbers.
[0064] Alternatively, the sum of the ADC measurement and the capacitor voltage can be calculated, and the sum of the fourth target integer corresponding to this sum and the fifth target integer corresponding to the CPU identifier can be used as the final random seed, which can then be used to generate random numbers.
[0065] In this implementation, a hash algorithm can also be introduced to perform hash calculations on the random seed obtained through the ADC measurement value, voltage value, and CPU identifier, and use the calculated hash value as the final random seed.
[0066] After obtaining the random seed, random numbers can be generated using the following method: The mixed congruential method is used to generate random numbers recursively, and the calculation formula is as follows:
[0067] X0 = seed (random seed)
[0068] Xn+1 = (A*Xn+C) mod M (n>=0)
[0069] In the above formula, considering that the applicable scenario of this application is a local area network of a limited size, M = 65536, and correspondingly, A and C are both prime numbers, A = 3373, C = 1; n-1 random numbers are generated from R1 to Rn-1.
[0070] Furthermore, to increase randomness, a roulette wheel selection method can be used to randomly select from n-1 random numbers. Specifically:
[0071] (1) Calculate the probability p(xi) of each random number being selected, using the following formula:
[0072]
[0073] In the above formula, each random number has an equal probability of being selected, and i is from 1 to n-1.
[0074] (2) Calculate the cumulative probability q(xi) for each part, as shown in the following formula:
[0075]
[0076] In this application, each random number has an equal probability of being selected, and the calculation results are shown in the table below:
[0077] Table 1 Random Number Roulette Selection Method
[0078] individual 1 2 3 … n-1 Choose probability 1 / (n-1) 1 / (n-1) 1 / (n-1) … 1 / (n-1) Cumulative probability 1 / (n-1) 2 / (n-1) 3 / (n-1) … 1
[0079] (3) Generate a random array k in the interval [0,1] and sort array k in ascending order; if the cumulative probability q(xi) is greater than the element k[i] in the array, select individual x(i); if it is less than k[i], jump to the next individual x(i+1) for comparison, and loop until an individual is selected. The pseudocode flow is as follows:
[0080] (a) k = random(0,1), k(xi), q(xi), i = 1, i ∈ [1, n-1], k(xi) is the xi-th random number, and q(xi) is the cumulative probability;
[0081] (b) If q(xi) >= k(xi), go to (e);
[0082] (c)q(xi+1)=q(xi)+P(xi);
[0083] (d)i = i + 1, then go to (b);
[0084] (e)xi is the selected individual. Output i and then end.
[0085] Based on the above method, a random number can be selected from multiple generated random numbers, and then the random number can be converted into a hexadecimal number. The two hexadecimal numbers are grouped together in ascending order. One byte of the MAC address is extracted, and zeros are added if necessary. Finally, six groups of hexadecimal numbers form a new MAC address.
[0086] As can be seen, the technical solution provided in this application solves the problem of ensuring the uniqueness of MAC addresses for communication in micro-embedded system devices within a local area network, thus guaranteeing communication security and the stability of field device communication. Furthermore, by introducing hash algorithm encryption technology, it ensures that the generated MAC addresses are not only random but also difficult to predict and forge.
[0087] Based on the above method examples, this application provides a MAC address generation device, which will be described below with reference to the accompanying drawings.
[0088] See Figure 3 This figure is a structural diagram of a MAC address generation device provided in an embodiment of this application, as shown below. Figure 3 As shown, the device 300 may include: a control unit 301, an acquisition unit 302, and a generation unit 303.
[0089] Control unit 301 is configured to control the charging or discharging of a capacitor in a target circuit in response to the startup of the network device, the target circuit being configured to determine a random seed;
[0090] The acquisition unit 302 is used to acquire the voltage value of the capacitor during the charging or discharging process of the capacitor;
[0091] The acquisition unit 302 is further configured to determine a random seed based on the target integer value corresponding to the voltage value, wherein different voltage values correspond to different integer values, and the range of the integer value is determined by the number of bus bits of the central processing unit (CPU) in the network device.
[0092] The generation unit 303 is used to obtain a random seed based on the voltage value and use the random seed to generate the MAC address of the network device.
[0093] In some embodiments, the target circuit includes a power supply, a resistor, a capacitor, and a MOSFET, wherein the MOSFET is used to control the capacitor to charge or discharge.
[0094] The first end of the resistor is connected to the power supply, the second end of the resistor is connected to the first end of the capacitor, and the second end of the capacitor is grounded. The first end of the MOSFET is connected to the second end of the resistor and the first end of the capacitor, and the second end of the MOSFET is grounded.
[0095] In some embodiments, the control unit 301 is specifically configured to configure the gate of the MOS transistor to a high level to control the capacitor to discharge; or, configure the gate of the MOS transistor to a low level to control the capacitor to discharge.
[0096] In some embodiments, the acquisition unit 302 is specifically configured to, during the charging or discharging process of the capacitor, acquire a first voltage value corresponding to the capacitor at a first time moment and a second voltage value corresponding to the capacitor at a second time moment; acquire a first target integer value corresponding to the first voltage value and a second target integer value corresponding to the second voltage value; and use the product of the first target integer value and the second target integer value as a random seed.
[0097] In some embodiments, the generation unit 303 is specifically used to perform hash calculation on the random seed to obtain a hash value; and use the hash value to generate the MAC address of the network device.
[0098] In some embodiments, the acquisition unit 302 is configured to, in response to the startup of the network device, acquire the measured value of the analog-to-digital converter (ADC) in the network device; use the product of the target integer value corresponding to the voltage value and the third target integer value corresponding to the measured value of the ADC as a random seed, wherein the range of the third target integer value is determined by the resolution of the ADC; or, calculate the sum of the voltage value and the measured value of the ADC to obtain a sum value; use the fourth target integer value corresponding to the sum value as a random seed, wherein the fourth target integer value is determined by the bus bit width of the CPU.
[0099] In some embodiments, the acquisition unit 302 is specifically used to acquire the identifier of the CPU; and to use the sum of the target integer value corresponding to the voltage value and the fifth target integer value corresponding to the identifier of the CPU as a random seed.
[0100] In some embodiments, the acquisition unit 302 is specifically configured to, in response to the startup of the network device, acquire the measured value of the analog-to-digital converter (ADC) in the network device and the identifier of the CPU; use the sum of the product of the target integer value corresponding to the voltage value and the third target integer value corresponding to the measured value of the ADC and the fifth target integer value corresponding to the identifier of the CPU as a random seed; or, calculate the sum of the voltage value and the measured value of the ADC, and acquire the sum value; use the sum of the fourth target integer value corresponding to the sum value and the fifth target integer value corresponding to the identifier of the CPU as a random seed.
[0101] It should be noted that the information execution process of each unit in the above-mentioned device can be found in the description of the method embodiment shown in the foregoing of this application, and will not be repeated here.
[0102] Additionally, embodiments of this application provide a network device, including: a processor and a memory;
[0103] The memory is used to store computer-readable instructions or computer programs;
[0104] The processor is configured to read the computer-readable instructions or the computer program so that the network device implements the MAC address generation method.
[0105] This application provides a computer-readable storage medium, including instructions or a computer program, which, when run on a computer, causes the computer to execute the MAC address generation method described above.
[0106] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the systems or apparatus disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and relevant parts can be referred to the method section.
[0107] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0108] It should also be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0109] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0110] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method of generating a MAC address, the method comprising: The method is applied to a network device, and comprises: in response to the network device starting, controlling a capacitor in a target circuit to charge or discharge, the target circuit being used to determine a random seed; during the charging or discharging of the capacitor, obtaining a first voltage value corresponding to the capacitor at a first time and a second voltage value corresponding to the capacitor at a second time; obtaining a first target integer value corresponding to the first voltage value and a second target integer value corresponding to the second voltage value, different voltage values corresponding to different integer values, the range of the integer values being determined by the number of bus bits of a central processing unit (CPU) in the network device; obtaining a random seed based on the first target integer value and the second target integer value; generating a MAC address of the network device by using the random seed.
2. The method of claim 1, wherein, The target circuit comprises a power supply, a resistor, a capacitor and a MOS tube, the MOS tube being used to control the capacitor to charge or discharge; a first end of the resistor is connected to the power supply, a second end of the resistor is connected to a first end of the capacitor, a second end of the capacitor is grounded, a first end of the MOS tube is connected to the second end of the resistor and the first end of the capacitor, and a second end of the MOS tube is grounded.
3. The method of claim 2, wherein, The control of the capacitor in the target circuit to charge or discharge comprises: configuring a gate of the MOS tube to be high, and controlling the capacitor to discharge; or, configuring the gate of the MOS tube to be low, and controlling the capacitor to charge.
4. The method according to any one of claims 1 to 3, characterized in that, The obtaining of the random seed based on the first target integer value and the second target integer value comprises: taking a product of the first target integer value and the second target integer value as the random seed.
5. The method of claim 4, wherein, The generation of the MAC address of the network device by using the random seed comprises: performing hash calculation on the random seed to obtain a hash value; generating the MAC address of the network device by using the hash value.
6. The method according to any one of claims 1 to 3, characterized in that, The obtaining of the random seed based on the first target integer value and the second target integer value comprises: in response to the network device starting, obtaining a measurement value of an analog-to-digital converter (ADC) in the network device; taking a product of the first target integer value, the second target integer value and a third target integer value corresponding to the measurement value of the ADC as the random seed, the range of the third target integer value being determined by a resolution of the ADC.
7. The method according to any one of claims 1 to 3, characterized in that, The obtaining of the random seed based on the first target integer value and the second target integer value comprises: obtaining an identifier of the CPU; taking a sum of a product of the first target integer value and the second target integer value and a fifth target integer value corresponding to the identifier of the CPU as the random seed.
8. The method according to any one of claims 1 to 3, characterized in that, The obtaining of the random seed based on the first target integer value and the second target integer value comprises: in response to the network device starting, obtaining a measurement value of an analog-to-digital converter (ADC) in the network device and an identifier of the CPU; taking a sum of a product of the first target integer value, the second target integer value and a third target integer value corresponding to the measurement value of the ADC and a fifth target integer value corresponding to the identifier of the CPU as the random seed.
9. A MAC address generating apparatus, characterized by comprising: The device is applied to a network device, and comprises: A control unit is configured to control charging or discharging of a capacitor in a target circuit in response to starting of the network device, the target circuit being configured to determine a random seed; An acquisition unit is configured to acquire a first voltage value corresponding to a first time and a second voltage value corresponding to a second time during the charging or discharging of the capacitor; The acquisition unit is further configured to acquire a first target integer value corresponding to the first voltage value and a second target integer value corresponding to the second voltage value, different voltage values corresponding to different integer values, the range of the integer values being determined by the bus bit number of a central processing unit (CPU) in the network device; and acquire a random seed based on the first target integer value and the second target integer value; A generation unit is configured to generate a MAC address of the network device by using the random seed.
10. A target circuit, comprising: The target circuit includes a power supply, a resistor, a capacitor and a MOS tube, the MOS tube being configured to control the capacitor to charge or discharge; A first end of the resistor is connected to the power supply, a second end of the resistor is connected to a first end of the capacitor, a second end of the capacitor is grounded, a first end of the MOS tube is connected to the second end of the resistor and the first end of the capacitor, and a second end of the MOS tube is grounded; The target circuit is deployed in a network device, and the network device is configured to perform the method of any one of claims 1-8 by controlling the target circuit.
Citation Information
Patent Citations
Methods and apparatuses for prime number generation and storage
CN105493437A
Laser phase fluctuation-based quantum random number generator and quantum random number generation method
CN106354476A