A semiconductor device comprising a memory, a random number generation circuit, and a control circuit and providing update data for an external terminal device, wherein the memory is configured to store key information (SG06), the random number generation circuit is configured to generate a first random number signal (SG11) and a second random number signal (SG12), and the control circuit is configured to generate a sixth random number signal (SG13) and a seventh random number signal (SG14), different from the first random number signal (SG11), from the first random number signal (SG11) and the key information (SG06), generate encrypted update data from the update data using the seventh random number signal (SG14), transmit the first random number signal (SG11) and the second random number signal (SG12) as request signals to the external terminal device, the second random number signal (SG12) being a challenge code for authenticating the external terminal device, receive a first response signal (SG15) and a second response signal (SG16) from the external terminal device as response signals in response to the request signals, the first response signal (SG15) being a challenge code that the external terminal device uses to authenticate the semiconductor device, and the second response signal (SG16) being a response code corresponding to the second random number signal (SG12), generate an eighth random number signal (SG18) using the first response signal (SG15), the second random number signal (SG12), and the sixth random number signal (SG13) as input signals, and provide the encrypted update data for the external terminal device when the second response signal (SG16) coincides with the eighth random number signal (SG18). the memory is configured to store key information (SG06), the random number generation circuit is configured to generate a first random number signal (SG11) and a second random number signal (SG12), and the control circuit is configured to generate a sixth random number signal (SG13) and a seventh random number signal (SG14), different from the first random number signal (SG11), from the first random number signal (SG11) and the key information (SG06), generate encrypted update data from the update data using the seventh random number signal (SG14), transmit the first random number signal (SG11) and the second random number signal (SG12) as request signals to the external terminal device, the second random number signal (SG12) being a challenge code for authenticating the external terminal device, receive a first response signal (SG15) and a second response signal (SG16) from the external terminal device as response signals in response to the request signals, the first response signal (SG15) being a challenge code that the external terminal device uses to authenticate the semiconductor device, and the second response signal (SG16) being a response code corresponding to the second random number signal (SG12), generate an eighth random number signal (SG18) using the first response signal (SG15), the second random number signal (SG12), and the sixth random number signal (SG13) as input signals, and provide the encrypted update data for the external terminal device when the second response signal (SG16) coincides with the eighth random number signal (SG18). <EOS>