JP2018147345A - Electronic device - Google Patents

Electronic device Download PDF

Info

Publication number
JP2018147345A
JP2018147345A JP2017043649A JP2017043649A JP2018147345A JP 2018147345 A JP2018147345 A JP 2018147345A JP 2017043649 A JP2017043649 A JP 2017043649A JP 2017043649 A JP2017043649 A JP 2017043649A JP 2018147345 A JP2018147345 A JP 2018147345A
Authority
JP
Japan
Prior art keywords
data
cpu
area
card
mirror
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
JP2017043649A
Other languages
Japanese (ja)
Inventor
大輔 丹下
Daisuke Tange
大輔 丹下
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Toshiba Corp
Toshiba Infrastructure Systems and Solutions Corp
Original Assignee
Toshiba Corp
Toshiba Infrastructure Systems and Solutions Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Toshiba Corp, Toshiba Infrastructure Systems and Solutions Corp filed Critical Toshiba Corp
Priority to JP2017043649A priority Critical patent/JP2018147345A/en
Publication of JP2018147345A publication Critical patent/JP2018147345A/en
Pending legal-status Critical Current

Links

Abstract

PROBLEM TO BE SOLVED: To provide an electronic device excellent in prevention of deterioration of data reliability.SOLUTION: An electronic device of an embodiment includes storage means, receiving means, and control means. The storage means includes a plurality of regions. The receiving means receives a command that instructs writing of data. In accordance with reception of the command and properties of the data, processing means selectively executes a first mode of writing the data into first and second regions among the plurality of regions and a second mode of writing the data into the first region.SELECTED DRAWING: Figure 11

Description

本発明の実施形態は、電子装置に関する。   Embodiments described herein relate generally to an electronic device.

IC(integrated circuit)チップを備えたICカードなど、データの書き込み及び書き換えが可能な電子装置がある。このような電子装置においては、データの書き換え回数が多くなるにつれ、データの書き込みエラーなどが発生しやすくなる。このため、書き換え可能な回数の目安として、保障回数が定められている電子装置もある。   There is an electronic device capable of writing and rewriting data, such as an IC card having an IC (integrated circuit) chip. In such an electronic device, as the number of data rewrites increases, a data write error or the like easily occurs. For this reason, some electronic devices have a guaranteed number of times as a guide for the number of times they can be rewritten.

特開2012−164121号公報JP 2012-164121 A

データの書き換え回数が保証回数を超えると、書き換えられたデータの信頼性が低下するおそれがある。一般的に、ICカードの使用期間が長期にわたると書き換え回数は増加し、データの信頼性が低下する。つまり、書き換え回数の多いデータについては保証期間が短くなる傾向にある。このようなデータの信頼性低下の防止、言い換えれば保証期間を長期化する技術が望まれている。
本発明の実施形態が解決しようとする課題は、データの信頼性低下の防止に優れた電子装置を提供することである。
If the number of data rewrites exceeds the guaranteed number, the reliability of the rewritten data may be reduced. Generally, when the IC card is used for a long period, the number of rewrites increases, and the reliability of data decreases. That is, the guarantee period tends to be short for data with a large number of rewrites. There is a demand for a technique for preventing such a decrease in data reliability, in other words, extending the guarantee period.
The problem to be solved by the embodiments of the present invention is to provide an electronic device that is excellent in preventing deterioration of data reliability.

実施形態の電子装置は、記憶手段、受信手段及び制御手段を含む。記憶手段は、複数の領域を備える。受信手段は、データの書き込みを命じるコマンドを受信する。処理手段は、前記コマンドの受信及び前記データの特性に応じて、前記複数の領域のうちの第1及び第2の領域に前記データを書き込む第1のモード、及び前記第1の領域に前記データを書き込む第2のモードを選択的に実行する。   The electronic apparatus according to the embodiment includes a storage unit, a reception unit, and a control unit. The storage means includes a plurality of areas. The receiving means receives a command for instructing data writing. The processing means includes a first mode in which the data is written in the first and second areas of the plurality of areas according to the reception of the command and the characteristics of the data, and the data in the first area. Is selectively executed in the second mode.

実施形態に係るICカードシステム及び当該ICカードシステムに含まれる通信装置の要部回路構成を示すブロック図。The block diagram which shows the principal part circuit structure of the IC card system which concerns on embodiment, and the communication apparatus contained in the said IC card system. 実施形態に係るICカードの要部回路構成を示すブロック図。The block diagram which shows the principal circuit structure of the IC card which concerns on embodiment. 図2中の不揮発性メモリに記憶されるファイルのファイル構造の一例を示す図。The figure which shows an example of the file structure of the file memorize | stored in the non-volatile memory in FIG. 図2中の不揮発性メモリの領域分割について示す図。The figure shown about the area | region division of the non-volatile memory in FIG. 図2中の不揮発性メモリに記憶されるデータを示す図。The figure which shows the data memorize | stored in the non-volatile memory in FIG. 図1中のICカードシステムで用いられるコマンドフォーマットの一例を示す図。The figure which shows an example of the command format used with the IC card system in FIG. 図1中のICカードシステムにおける情報の流れを示すシーケンス図。The sequence diagram which shows the flow of the information in the IC card system in FIG. 図1中の通信装置のCPUによる制御処理のフローチャート。The flowchart of the control processing by CPU of the communication apparatus in FIG. 図2中のICカードのCPUによる制御処理のフローチャート。The flowchart of the control processing by CPU of the IC card in FIG. 図2中のICカードのCPUによる制御処理のフローチャート。The flowchart of the control processing by CPU of the IC card in FIG. 図2中のICカードのCPUによる制御処理のフローチャート。The flowchart of the control processing by CPU of the IC card in FIG. 図2中の不揮発性メモリに記憶されるデータを示す図。The figure which shows the data memorize | stored in the non-volatile memory in FIG. 図2中のICカードのCPUによる制御処理のフローチャート。The flowchart of the control processing by CPU of the IC card in FIG. 図2中のICカードのCPUによる制御処理のフローチャート。The flowchart of the control processing by CPU of the IC card in FIG.

以下、実施形態に係るICカードシステムについて図面を用いて説明する
図1は、実施形態に係るICカードシステム1に含まれる装置のそれぞれの要部回路構成を示すブロック図である。ICカードシステム1は、通信装置10及びICカード20を含む。
DESCRIPTION OF EMBODIMENTS Hereinafter, an IC card system according to an embodiment will be described with reference to the drawings. FIG. 1 is a block diagram showing a main circuit configuration of each device included in the IC card system 1 according to the embodiment. The IC card system 1 includes a communication device 10 and an IC card 20.

通信装置10は、ICカード20にコマンドを送信し、ICカード20から送信されたレスポンスを受信する機能を有する。通信装置10は、CPU(central processing unit)11、ROM(read-only memory)12、RAM(random-access memory)13、不揮発性メモリ14、リーダーライター15、表示デバイス16、入力デバイス17、通信インターフェース18及びバス19を含む。   The communication device 10 has a function of transmitting a command to the IC card 20 and receiving a response transmitted from the IC card 20. The communication device 10 includes a central processing unit (CPU) 11, a read-only memory (ROM) 12, a random-access memory (RAM) 13, a nonvolatile memory 14, a reader / writer 15, a display device 16, an input device 17, and a communication interface. 18 and bus 19 are included.

CPU11は、通信装置10の動作に必要な処理及び制御を行うコンピューターの中枢部分に相当する。CPU11は、ROM12又は不揮発性メモリ14に記憶されたOS(operating system)又はアプリケーションソフトウェアなどのプログラムに基づいて、通信装置10の各種の機能を実現するべく各部を制御する。   The CPU 11 corresponds to a central part of a computer that performs processing and control necessary for the operation of the communication device 10. The CPU 11 controls each unit to implement various functions of the communication device 10 based on a program such as an OS (operating system) or application software stored in the ROM 12 or the nonvolatile memory 14.

ROM12は、上記コンピューターの主記憶部分に相当する読み出し専用の不揮発性メモリである。ROM12は、オペレーティングシステム又はアプリケーションソフトウェアなどのプログラムを記憶する。また、ROM12は、CPU11が各種の処理を行う上で使用するデータなどを記憶する。   The ROM 12 is a read-only nonvolatile memory corresponding to the main storage portion of the computer. The ROM 12 stores a program such as an operating system or application software. The ROM 12 stores data used when the CPU 11 performs various processes.

RAM13は、上記コンピューターの主記憶部分に相当する揮発性のメモリである。RAM13は、CPU11が各種の処理を行う上で一時的に使用するデータを記憶しておく、いわゆるワークエリアとして利用される。   The RAM 13 is a volatile memory corresponding to the main storage portion of the computer. The RAM 13 is used as a so-called work area that stores data temporarily used when the CPU 11 performs various processes.

不揮発性メモリ14は、上記コンピューターの補助記憶部分に相当する。不揮発性メモリ14は、例えばEEPROM(electric erasable programmable read-only memory)、HDD(hard disk drive)又はSSD(solid state drive)などである。不揮発性メモリ14は、上記のオペレーティングシステム又はアプリケーションソフトウェアなどのプログラムを記憶する場合がある。また、不揮発性メモリ14は、CPU11が各種の処理を行う上で使用するデータ又はCPU11での処理によって生成されたデータなどを保存する。なお、通信装置10は、不揮発性メモリ14に代えて、あるいは不揮発性メモリ14に加えて、メモリカードなどの記憶媒体を挿入可能なカードスロットなどのインターフェースを備えてもよい。当該メモリカードは、上記コンピューターの補助記憶部分に相当する。   The nonvolatile memory 14 corresponds to an auxiliary storage part of the computer. The nonvolatile memory 14 is, for example, an EEPROM (electrically erasable programmable read-only memory), an HDD (hard disk drive), or an SSD (solid state drive). The nonvolatile memory 14 may store a program such as the above operating system or application software. Further, the nonvolatile memory 14 stores data used when the CPU 11 performs various processes, data generated by the processes in the CPU 11, and the like. Note that the communication device 10 may include an interface such as a card slot into which a storage medium such as a memory card can be inserted instead of or in addition to the nonvolatile memory 14. The memory card corresponds to an auxiliary storage part of the computer.

ROM12又は不揮発性メモリ14に記憶されるプログラムは、後述する制御処理に関して記述した制御プログラムを含む。一例として、通信装置10は、制御プログラムがROM12又は不揮発性メモリ14に記憶された状態で利用者などへと譲渡される。しかしながら、通信装置10は、後述する制御処理に関して記述した制御プログラムがROM12又は不揮発性メモリ14に記憶されない状態で利用者などに譲渡されても良い。また、通信装置10は、別の制御プログラムがROM12又は不揮発性メモリ14に記憶された状態で利用者などに譲渡されても良い。そして、後述する制御処理に関して記述した制御プログラムが別途に利用者などへと譲渡され、利用者又はサービスマンなどによる操作の下に不揮発性メモリ14へと書き込まれても良い。このときの制御プログラムの譲渡は、例えば、磁気ディスク、光磁気ディスク、光ディスク、半導体メモリなどのようなリムーバブルな記録媒体に記録して、あるいはネットワークを介したダウンロードにより実現できる。   The program stored in the ROM 12 or the non-volatile memory 14 includes a control program described regarding control processing described later. As an example, the communication device 10 is transferred to a user or the like with the control program stored in the ROM 12 or the nonvolatile memory 14. However, the communication device 10 may be transferred to a user or the like in a state where a control program described regarding control processing described later is not stored in the ROM 12 or the nonvolatile memory 14. The communication device 10 may be transferred to a user or the like with another control program stored in the ROM 12 or the nonvolatile memory 14. Then, a control program described regarding control processing described later may be separately transferred to a user or the like and written into the nonvolatile memory 14 under the operation of the user or a serviceman. The transfer of the control program at this time can be realized, for example, by recording on a removable recording medium such as a magnetic disk, a magneto-optical disk, an optical disk, a semiconductor memory, or by downloading via a network.

リーダーライター15は、磁気カード(磁気ストライプカード)、接触型ICカード又は非接触型ICカードなどと通信を行う。また、リーダーライター15は、電子装置(例えば携帯電話、スマートフォン又はタブレットPC(personal computer)などの携帯可能な電子装置)に搭載された非接触型ICチップと通信を行う。リーダーライター15は、上記通信を用いてICカード20にコマンドを送信する。また、リーダーライター15は、上記通信を用いてICカード20から送信されたレスポンスを受信する。   The reader / writer 15 communicates with a magnetic card (magnetic stripe card), a contact IC card or a non-contact IC card. The reader / writer 15 communicates with a non-contact type IC chip mounted on an electronic device (for example, a portable electronic device such as a mobile phone, a smartphone, or a tablet PC (personal computer)). The reader / writer 15 transmits a command to the IC card 20 using the communication. Further, the reader / writer 15 receives a response transmitted from the IC card 20 using the communication.

表示デバイス16は、通信装置10の操作者に各種情報を通知するための画面を表示する。表示デバイス16は、例えば、液晶ディスプレイ又は有機EL(electro-luminescence)ディスプレイなどのディスプレイである。
入力デバイス17は、通信装置10の操作者による操作を受け付ける。入力デバイス17は、例えば、キーボード、キーパッド、タッチパッド又はマウスなどである。また、入力デバイス17としては、表示デバイス16の表示パネルに重ねて配置されたタッチパッドを用いることもできる。すなわち、タッチパネルが備える表示パネルを表示デバイス16として、タッチパネルが備えるタッチパッドを入力デバイス17として用いることができる。
The display device 16 displays a screen for notifying the operator of the communication device 10 of various information. The display device 16 is, for example, a display such as a liquid crystal display or an organic EL (electro-luminescence) display.
The input device 17 receives an operation by an operator of the communication device 10. The input device 17 is, for example, a keyboard, a keypad, a touch pad, or a mouse. In addition, as the input device 17, a touch pad disposed on the display panel of the display device 16 can be used. That is, the display panel included in the touch panel can be used as the display device 16, and the touch pad included in the touch panel can be used as the input device 17.

通信インターフェース18は、通信装置10が他の機器と通信するためのインターフェースである。通信インターフェース18は、例えば、図示しないネットワークに接続可能に構成される。通信インターフェース18は、ネットワークを介して図示しない他の機器と通信する。   The communication interface 18 is an interface for the communication device 10 to communicate with other devices. The communication interface 18 is configured to be connectable to a network (not shown), for example. The communication interface 18 communicates with other devices (not shown) via a network.

バス19は、アドレスバス及びデータバスなどを含み、通信装置10の各部で授受される信号を伝送する。   The bus 19 includes an address bus, a data bus, and the like, and transmits signals transmitted and received by each unit of the communication device 10.

図2は、ICカード20の要部回路構成を示すブロック図である。ICカード20は、磁気カード、接触型ICカード又は非接触型ICカードなどである。ICカード20は、携帯可能である。ICカード20は、例えば、カード状などの本体21と、本体21に内蔵されたICモジュール22とを備える。ICモジュール22は、ICチップ23と、ICチップ23に接続された図示しない通信用の回路とを備える。通信用の回路は、例えば、アンテナ又は接触端子(コンタクトパターン)として構成される。通信用の回路は、通信装置10のリーダーライター15と電気的又は磁気的に接続される。ICカード20は、可能な電子装置の一例である。
ICチップ23は、CPU231、ROM232、RAM233、不揮発性メモリ234、通信部235、電源部236、Co−Pro237及びバス238を含む。ICチップ23は、電子装置の一例である。
FIG. 2 is a block diagram showing a main circuit configuration of the IC card 20. The IC card 20 is a magnetic card, a contact IC card, a non-contact IC card, or the like. The IC card 20 is portable. The IC card 20 includes, for example, a card-like main body 21 and an IC module 22 built in the main body 21. The IC module 22 includes an IC chip 23 and a communication circuit (not shown) connected to the IC chip 23. The communication circuit is configured as an antenna or a contact terminal (contact pattern), for example. The communication circuit is electrically or magnetically connected to the reader / writer 15 of the communication device 10. The IC card 20 is an example of a possible electronic device.
The IC chip 23 includes a CPU 231, ROM 232, RAM 233, nonvolatile memory 234, communication unit 235, power supply unit 236, Co-Pro 237, and bus 238. The IC chip 23 is an example of an electronic device.

CPU231は、ICカード20の動作に必要な処理及び制御を行うコンピューターの中枢部分に相当する。CPU231は、ROM232又は不揮発性メモリ234に記憶されたオペレーティングシステム又はアプリケーションソフトウェアなどのプログラムに基づいて、ICカード20の各種の機能を実現するべく各部を制御する。   The CPU 231 corresponds to a central part of a computer that performs processing and control necessary for the operation of the IC card 20. The CPU 231 controls each unit to realize various functions of the IC card 20 based on a program such as an operating system or application software stored in the ROM 232 or the nonvolatile memory 234.

ROM232は、上記コンピューターの主記憶部分に相当する読み出し専用の不揮発性メモリである。ROM232は、オペレーティングシステム又はアプリケーションソフトウェアなどのプログラムを記憶する。また、ROM232は、CPU231が各種の処理を行う上で使用するデータなどを記憶する。   The ROM 232 is a read-only nonvolatile memory corresponding to the main storage portion of the computer. The ROM 232 stores a program such as an operating system or application software. The ROM 232 stores data used when the CPU 231 performs various processes.

RAM233は、上記コンピューターの主記憶部分に相当する揮発性のメモリである。RAM233は、CPU231が各種の処理を行う上で一時的に使用するデータを記憶しておく、いわゆるワークエリアとして利用される。   The RAM 233 is a volatile memory corresponding to the main storage portion of the computer. The RAM 233 is used as a so-called work area that stores data temporarily used when the CPU 231 performs various processes.

不揮発性メモリ234は、上記コンピューターの補助記憶部分に相当する。不揮発性メモリ234は、例えばEEPROMなどである。不揮発性メモリ234は、上記のオペレーティングシステム又はアプリケーションソフトウェアなどのプログラムを記憶する場合がある。また、不揮発性メモリ234は、CPU231が各種の処理を行う上で使用するデータ又はCPU231での処理によって生成されたデータなどを保存する。また、ROM232又は不揮発性メモリ234は、値Limitを記憶する。値Limitは、一例として、ICカード20の販売者、設計者又は管理者などによって予め定められる。   The nonvolatile memory 234 corresponds to an auxiliary storage part of the computer. The nonvolatile memory 234 is, for example, an EEPROM. The non-volatile memory 234 may store programs such as the above operating system or application software. The non-volatile memory 234 stores data used when the CPU 231 performs various processes, data generated by the processes in the CPU 231, and the like. Further, the ROM 232 or the nonvolatile memory 234 stores the value Limit. As an example, the value Limit is determined in advance by a seller, a designer, or an administrator of the IC card 20.

ROM232又は不揮発性メモリ234に記憶されるプログラムは、後述する制御処理に関して記述した制御プログラムを含む。一例として、ICカード20は、制御プログラムがROM232又は不揮発性メモリ234に記憶された状態で利用者などへと譲渡される。しかしながら、ICカード20は、後述する制御処理に関して記述した制御プログラムがROM232又は不揮発性メモリ234に記憶されない状態で利用者などに譲渡されても良い。また、ICカード20は、別の制御プログラムがROM232又は不揮発性メモリ234に記憶された状態で利用者などに譲渡されても良い。そして、後述する制御処理に関して記述した制御プログラムが別途に利用者などへと譲渡され、利用者又はサービスマンなどによる操作の下に不揮発性メモリ234へと書き込まれても良い。このときの制御プログラムの譲渡は、例えば、磁気ディスク、光磁気ディスク、光ディスク、半導体メモリなどのようなリムーバブルな記録媒体に記録して、あるいはネットワークを介したダウンロードにより実現できる。   The program stored in the ROM 232 or the non-volatile memory 234 includes a control program described regarding control processing described later. As an example, the IC card 20 is transferred to a user or the like with the control program stored in the ROM 232 or the nonvolatile memory 234. However, the IC card 20 may be transferred to a user or the like in a state where a control program described regarding control processing described later is not stored in the ROM 232 or the nonvolatile memory 234. The IC card 20 may be transferred to a user or the like in a state where another control program is stored in the ROM 232 or the nonvolatile memory 234. Then, a control program described regarding control processing described later may be separately transferred to a user or the like and written into the nonvolatile memory 234 under the operation of the user or a serviceman. The transfer of the control program at this time can be realized, for example, by recording on a removable recording medium such as a magnetic disk, a magneto-optical disk, an optical disk, a semiconductor memory, or by downloading via a network.

通信部235は、ICカード20が通信装置10と通信する為の回路である。通信部235は、前述の通信用の回路を介して接触通信又は非接触通信により通信装置10とデータの送受信を行う。例えば、通信部235は、通信装置10から送信された信号に対して信号処理を施すことにより、通信装置10が送信したコマンドなどのデータを取得する。通信部235は、取得したデータをCPU231に渡す。また、通信部235は、CPU231から渡されたレスポンスなどのデータに基づいて信号を生成し、生成した信号を通信装置10に送信する。通信部235は、一例として、UART(Universal Asynchronous Receiver Transmitter)を含む。   The communication unit 235 is a circuit for the IC card 20 to communicate with the communication device 10. The communication unit 235 transmits / receives data to / from the communication device 10 by contact communication or non-contact communication via the communication circuit described above. For example, the communication unit 235 obtains data such as a command transmitted by the communication device 10 by performing signal processing on the signal transmitted from the communication device 10. The communication unit 235 passes the acquired data to the CPU 231. The communication unit 235 generates a signal based on data such as a response passed from the CPU 231 and transmits the generated signal to the communication device 10. As an example, the communication unit 235 includes a UART (Universal Asynchronous Receiver Transmitter).

電源部236は、ICカード20の各部に電力を供給する。電源部236は、上記の通信用の回路を介して通信装置10から供給される電力を各部の定格電圧に変換して各部に供給する。なお、電源部236は、バッテリーを備え、バッテリーの電力を各部に供給する構成であっても良い。   The power supply unit 236 supplies power to each unit of the IC card 20. The power supply unit 236 converts the power supplied from the communication device 10 through the communication circuit described above into the rated voltage of each unit and supplies it to each unit. Note that the power supply unit 236 may include a battery and supply the power of the battery to each unit.

Co−Pro237は、CPU231の補助などを行うプロセッサーである。Co−Proは、例えば、公開鍵暗号処理専用処理機構であり、データの暗号化及び復号化などに係る処理を行う。   The Co-Pro 237 is a processor that assists the CPU 231 and the like. Co-Pro is, for example, a processing mechanism dedicated to public key encryption processing, and performs processing related to data encryption and decryption.

バス238は、アドレスバス及びデータバスなどを含み、ICカード20の各部で授受される信号を伝送する。   The bus 238 includes an address bus, a data bus, and the like, and transmits signals transmitted and received by each unit of the IC card 20.

次に、不揮発性メモリ234が記憶するファイルについてのファイル構造について説明する。図3は、不揮発性メモリ234に記憶されるファイルのファイル構造の一例を示す図である。不揮発性メモリ234は、一例として、ISO(International Organization for Standardization)/IEC(International Electrotechnical Commission) 7816−4で規定されるMF(master file)、DF(dedicated file)及びEF(elementary file)を含む。MF、DF及びEFは、ツリー形の階層構造を形成する。MFは、ルートに位置する。DFは、MFの配下に位置する。EFは、MF又はDFの配下に位置する。DFは、それぞれが異なるアプリケーションと対応する。DFは、対応するアプリケーションを識別可能とするために、ユニークなDF nameとしてAPLが関連付けられている。各DF配下のEFは、当該DFに対応したアプリケーションで使用されるデータが格納される。図3では、不揮発性メモリ234は、MF、MF配下のEF及びMF配下のDF1〜DF4、DF1配下のEF1−1〜EF1−2、DF2配下のEF2−1〜EF2−2、DF3配下のEF3−1〜EF3−2並びにDF4配下のEF4−1〜EF4−2を含む。DF1〜DF4にはそれぞれAPL1〜APL4が付与されている。   Next, the file structure of the file stored in the nonvolatile memory 234 will be described. FIG. 3 is a diagram illustrating an example of a file structure of a file stored in the nonvolatile memory 234. As an example, the nonvolatile memory 234 includes an MF (master file), a DF (dedicated file), and an EF (elementary file) defined by ISO (International Organization for Standardization) / IEC (International Electrotechnical Commission) 7816-4. MF, DF, and EF form a tree-shaped hierarchical structure. The MF is located at the root. DF is located under MF. EF is located under MF or DF. Each DF corresponds to a different application. The DF is associated with an APL as a unique DF name so that the corresponding application can be identified. The EF under each DF stores data used by an application corresponding to the DF. In FIG. 3, the nonvolatile memory 234 includes MF, EF under MF, DF1 to DF4 under MF, EF1-1 to EF1-2 under DF1, EF2-1 to EF2-2 under DF2, and EF3 under DF3. -1 to EF3-2 and EF4-1 to EF4-2 under DF4. APL1 to APL4 are assigned to DF1 to DF4, respectively.

図4は、不揮発性メモリ234の領域分割について示す図である。不揮発性メモリ234は、システム領域及びアプリケーション領域を含む。システム領域に記憶されるデータは、ICカード20に登録されたアプリケーションのDF NameとそのDFの位置を示すポインタとで構成されたテーブル(登録アプリケーションテーブル)を含む。アプリケーション領域に記憶されるデータは、各アプリケーションが使用するファイルなどを含む。ICカード20は、例えば、アプリケーションのフォルダに相当するDF、および、データファイルに相当するEFを前述のように階層構造で管理する。   FIG. 4 is a diagram showing area division of the nonvolatile memory 234. The nonvolatile memory 234 includes a system area and an application area. The data stored in the system area includes a table (registered application table) configured by a DF Name of an application registered in the IC card 20 and a pointer indicating the position of the DF. The data stored in the application area includes files used by each application. For example, the IC card 20 manages a DF corresponding to an application folder and an EF corresponding to a data file in a hierarchical structure as described above.

図5は、アプリケーション領域に書き込まれるデータについて示す図である。アプリケーション領域は、アドレス「App Start addr」から開始し、アドレス「App End addr」で終了する。アドレス「App Start addr」側が低位側のアドレスであり、アドレス「App End addr」側が高位側のアドレスである。アプリケーション領域は、オリジナル領域とミラー領域とを含む。アプリケーション領域に書き込まれるデータは、一例として、オリジナル領域に記憶される。あるいは、アプリケーション領域に書き込まれるデータは、一例として、オリジナル領域とミラー領域との2箇所に同一のデータが記憶される。オリジナル領域は、一例として、アプリケーション領域への書き込み対象のデータを記憶するための領域として設けられる。ミラー領域は、一例として、アプリケーション領域への多重書き対象のデータを記憶するために設けられる。ミラー領域は、一例として、オリジナル領域に書き込まれたデータと同一のデータが書き込まれる。なお、オリジナル領域に書き込まれたデータをオリジナルデータ、ミラー領域に書き込まれたデータをミラーデータと称するものとする。オリジナル領域は、アドレス低位からデータが書き込まれる。ミラー領域が開始するアドレスを「Mirror Start addr」と称するものとする。そして、ミラー領域は、アドレス「Mirror Start addr」からアドレス「App End addr」までの領域である。また、ミラー領域のうちのデータ書き込み済みの領域の最後のアドレスを「Mirror End addr」と称するものとする。すなわち、アドレス「Mirror End addr」からアドレス「App End addr」までは空き領域であり、ミラー領域におけるメモリ残量である。アプリケーション領域に書き込まれたデータは、オリジナルデータ及びミラーデータに拘わらず、「Object Header」及び「Data部」を含む。「Object Header」は、データのヘッダー部であり、「ID」、「Data Len」、「TYPE」、「Count」及び「Reserve」を含む。「ID」は、データごとに関連付けられたユニークなIDナンバー(IDN(identifier number))を示す。「Data Len」は、「Data部」の長さを示す。「TYPE」は、書き込み保障の短長を示す。このために、「TYPE」は、一例として、「TYPE_NORMAL」又は「TYPE_LONG」のいずれかを示す値をとる。「TYPE_NORMAL」は、更新頻度の低いデータに用いられる。「TYPE_LONG」は、更新頻度の高いデータに用いられる。したがって、「TYPE」の値は、書き込まれるデータの特性を示す。「Count」は、データの書き込み又は書き換えが行われた回数、すなわち更新回数を示す。「Count」の初期値は、一例として0である。あるいは例えば、初期値は、工場出荷時の値である。なお、「Count」は、データの削除が行われた場合でもリセットされない。そして、新たにデータが書き込まれた場合には、回数を継続する。また、「Count」の値の大きさによって、書き込まれるデータの更新頻度を推定することができる。したがって、「Count」の値は、書き込まれるデータの特性を示す。「Reserve」は、メモリの予約状況を示す。「Data部」は、データの本体である。
以上より、不揮発性メモリ234は、複数の領域を備える記憶手段の一例である。
FIG. 5 is a diagram showing data written in the application area. The application area starts with the address “App Start addr” and ends with the address “App End addr”. The address “App Start addr” is a lower address, and the address “App End addr” is a higher address. The application area includes an original area and a mirror area. The data written in the application area is stored in the original area as an example. Alternatively, the data written in the application area, for example, stores the same data in two places, the original area and the mirror area. As an example, the original area is provided as an area for storing data to be written to the application area. As an example, the mirror area is provided for storing data to be multiplexed to the application area. In the mirror area, for example, the same data as the data written in the original area is written. The data written in the original area is called original data, and the data written in the mirror area is called mirror data. In the original area, data is written from the lowest address. The address where the mirror area starts is referred to as “Mirror Start addr”. The mirror area is an area from the address “Mirror Start addr” to the address “App End addr”. In addition, the last address in the mirror area in which data has been written is referred to as “Mirror End addr”. That is, the area from the address “Mirror End addr” to the address “App End addr” is an empty area, which is the remaining memory capacity in the mirror area. The data written in the application area includes “Object Header” and “Data section” regardless of the original data and the mirror data. “Object Header” is a header portion of data, and includes “ID”, “Data Len”, “TYPE”, “Count”, and “Reserve”. “ID” indicates a unique ID number (IDN (identifier number)) associated with each data. “Data Len” indicates the length of the “Data portion”. “TYPE” indicates a short length of write guarantee. For this reason, “TYPE” takes a value indicating either “TYPE_NORMAL” or “TYPE_LONG” as an example. “TYPE_NORMAL” is used for data with low update frequency. “TYPE_LONG” is used for data with a high update frequency. Therefore, the value of “TYPE” indicates the characteristics of data to be written. “Count” indicates the number of times data has been written or rewritten, that is, the number of updates. The initial value of “Count” is 0 as an example. Alternatively, for example, the initial value is a value at the time of factory shipment. Note that “Count” is not reset even when data is deleted. When data is newly written, the number of times is continued. In addition, the update frequency of the written data can be estimated based on the value of “Count”. Therefore, the value of “Count” indicates the characteristics of data to be written. “Reserve” indicates the reservation status of the memory. The “Data part” is the data body.
As described above, the nonvolatile memory 234 is an example of a storage unit including a plurality of areas.

図6は、ICカードシステム1で用いられるコマンドフォーマットの一例を示す図である。当該コマンドは、一例として、ISO/IEC 7816−4で規定された、「CLA(class byte)」、「INS(instruction byte)」、「P1(parameter byte 1)」、「P2(parameter byte 2」)、「Lc(length field for coding the number Nc)フィールド」、「データフィールド」及び「Le(length field for coding the number Ne)フィールド」により構成される。「CLA」は、コマンドのクラスを示す。「INS」は、コマンドの種類を示す。「P1」及び「P2」を連結した「P1―P2」は、パラメーターバイトを構成する。「Lcフィールド」は、コマンドデータフィールドの長さNcを示す。「コマンドデータフィールド」は、追記用レコードである。「Lcフィールド」及び「コマンドデータフィールド」は、Nc=0のとき存在しない。「Leフィールド」は、コマンドへの応答として返されるレスポンスデータの最大長Neを示す。「Leフィールド」は、Ne=0のとき存在しない。   FIG. 6 is a diagram illustrating an example of a command format used in the IC card system 1. The command is, for example, “CLA (class byte)”, “INS (instruction byte)”, “P1 (parameter byte 1)”, “P2 (parameter byte 2”) defined by ISO / IEC 7816-4. ), “Lc (length field for coding the number Nc) field”, “data field”, and “Le (length field for coding the number Ne) field”. “CLA” indicates a command class. “INS” indicates the type of command. “P1-P2” obtained by connecting “P1” and “P2” constitutes a parameter byte. The “Lc field” indicates the length Nc of the command data field. The “command data field” is an additional record. The “Lc field” and the “command data field” do not exist when Nc = 0. The “Le field” indicates the maximum length Ne of response data returned as a response to the command. The “Le field” does not exist when Ne = 0.

以下、実施形態に係るICカードシステム1の動作を図7〜14に基づいて説明する。なお、以下の動作説明における処理の内容は一例であって、同様な結果を得ることが可能な様々な処理を適宜に利用できる。図7は、ICカードシステム1の情報の流れを示すシーケンス図である。なお、図7は、ICカードシステム1における情報の流れを網羅するものではなく、図示しない情報の流れが存在しても良い。図8は、通信装置10のCPU11による制御処理のフローチャートである。CPU11は、ROM12又は不揮発性メモリ14に記憶された制御プログラムに基づいてこの制御処理を実行する。図9〜図11、図13及び図14は、ICカード20のCPU231による制御処理のフローチャートである。CPU231は、ROM232又は不揮発性メモリ234に記憶された制御プログラムに基づいてこの制御処理を実行する。
なお、以下の動作説明は、AES(Advanced Encryption Standard)における暗号鍵の生成を行う場合を例にとって、実施形態に係るICカードシステム1の動作を説明する。
Hereinafter, the operation of the IC card system 1 according to the embodiment will be described with reference to FIGS. Note that the content of the processing in the following description of the operation is an example, and various processing that can obtain the same result can be used as appropriate. FIG. 7 is a sequence diagram showing the information flow of the IC card system 1. Note that FIG. 7 does not cover the information flow in the IC card system 1, and an information flow (not shown) may exist. FIG. 8 is a flowchart of control processing by the CPU 11 of the communication apparatus 10. The CPU 11 executes this control process based on a control program stored in the ROM 12 or the nonvolatile memory 14. 9 to 11, 13 and 14 are flowcharts of control processing by the CPU 231 of the IC card 20. The CPU 231 executes this control process based on a control program stored in the ROM 232 or the nonvolatile memory 234.
In the following description of the operation, the operation of the IC card system 1 according to the embodiment will be described taking as an example the case of generating an encryption key in AES (Advanced Encryption Standard).

図8のステップST1において通信装置10のCPU11は、ICカード20に対して行う処理を決定する。一例として、通信装置10は、通信装置10の操作者による操作に基づいて、当該処理の内容を決定する。あるいは、通信装置10は、当該処理についての内容が記憶されたデータをROM12又は不揮発性メモリ14などから読み出すことによって当該決定を行う。当該読み出されるデータは、通信装置10の操作者又は管理者などによって予め定められる。あるいは、当該読み出されるデータは、通信装置10の設計者などによってデフォルトの内容が定められていても良い。そして、通信装置10の操作者又は管理者などによって当該読み出されるデータが定められていない場合、ICカード20に対して行う処理は、当該デフォルトの内容が用いられる。以上のように決定された処理には、ICカード20に対して送信するコマンドの種類及び当該コマンドに含めるパラメーターなどが含まれる。ここでは、CPU11は、「STORE DATA」コマンドをICカード20に送信する処理を行うことを決定する。「STORE DATA」コマンドは、ICカード20に対してデータの書き込みを命じるためのコマンドである。CPU11は、ステップST1の処理の後、ステップST2へと進む。   In step ST <b> 1 of FIG. 8, the CPU 11 of the communication device 10 determines a process to be performed on the IC card 20. As an example, the communication device 10 determines the content of the processing based on an operation by an operator of the communication device 10. Or the communication apparatus 10 performs the said determination by reading the data in which the content about the said process was memorize | stored from ROM12 or the non-volatile memory 14. The read data is predetermined by an operator or administrator of the communication device 10. Alternatively, the default content of the read data may be determined by the designer of the communication device 10 or the like. Then, when the read data is not defined by the operator or administrator of the communication device 10, the default content is used for the processing performed on the IC card 20. The processing determined as described above includes the type of command to be transmitted to the IC card 20 and parameters included in the command. Here, the CPU 11 determines to perform processing for transmitting a “STORE DATA” command to the IC card 20. The “STORE DATA” command is a command for instructing the IC card 20 to write data. After the process of step ST1, the CPU 11 proceeds to step ST2.

通信装置10からICカード20に対してコマンドを送信させるために、ICカード20の所有者などは、ICカード20が非接触ICカードである場合を例にすると、通信装置10にICカード20を近付ける。あるいは、通信装置10の操作者は、ICカード20の所有者などからICカード20を受け取って、通信装置10にICカード20を近付ける。
ステップST2においてCPU11は、ICカード20が近接するのを待ち受けている。CPU11は、ICカード20が近接したならば、ステップST2においてYesと判定してステップST3へと進む。
In order to transmit a command from the communication device 10 to the IC card 20, the owner of the IC card 20 and the like takes the IC card 20 to the communication device 10 when the IC card 20 is a non-contact IC card. Get closer. Alternatively, the operator of the communication device 10 receives the IC card 20 from the owner of the IC card 20 or the like, and brings the IC card 20 close to the communication device 10.
In step ST2, the CPU 11 waits for the IC card 20 to approach. If the IC card 20 comes close, the CPU 11 determines Yes in step ST2 and proceeds to step ST3.

ステップST3においてCPU11は、リーダーライター15を介してICカード20に電力を供給することによって、ICカード20を活性化する活性化処理を行う。活性化処理については、周知の処理を適用することができるので、詳細な説明は省略する。活性化処理により、ICカード20は、コマンド処理を実行可能な状態になる。このとき、ICカード20のCPU231は、図9に示す制御処理を開始する。CPU11は、図8のステップST3の処理の後、ステップST4へと進む。   In step ST <b> 3, the CPU 11 performs an activation process for activating the IC card 20 by supplying power to the IC card 20 via the reader / writer 15. Since the well-known process can be applied to the activation process, a detailed description is omitted. By the activation process, the IC card 20 becomes ready to execute the command process. At this time, the CPU 231 of the IC card 20 starts the control process shown in FIG. After the process of step ST3 in FIG. 8, the CPU 11 proceeds to step ST4.

ステップST4においてCPU11は、ICカード20に対して行う処理が、「STORE DATA」コマンドを送信することであるか否かを確認する。CPU11は、ICカード20に対して行う処理が、「STORE DATA」コマンドを送信することでないならば、ステップST4においてNoと判定して、当該処理内容に応じた処理を行う。そして、CPU11は、ICカード20に対して行う処理が、「STORE DATA」コマンドを送信することであるならば、ステップST4においてYesと判定して、ステップST5へと進む。   In step ST <b> 4, the CPU 11 confirms whether or not the process to be performed on the IC card 20 is to transmit a “STORE DATA” command. If the process performed on the IC card 20 is not to transmit a “STORE DATA” command, the CPU 11 determines No in step ST4 and performs a process according to the process content. If the process performed on the IC card 20 is to transmit a “STORE DATA” command, the CPU 11 determines Yes in step ST4 and proceeds to step ST5.

ステップST5においてCPU11は、アプリケーションソフトウェアを指定するためのコマンドである「SELECT」コマンドを生成する。「SELECT」コマンドは、一例として、指定したいアプリケーションソフトウェアに関連付けられたAPLを含む。ここでは、「STORE DATA」コマンドを処理するアプリケーションソフトウェアを指定するため、CPU11は、当該アプリケーションソフトウェアに関連付けられたAPLを含むものとして「SELECT」コマンドを生成する。そして、CPU11は、生成した当該「SELECT」コマンドをICカード20に送信するように通信インターフェース18に対して指示する。この指示を受けて通信インターフェース18は、当該「SELECT」コマンドをICカード20に送信する。送信された当該「SELECT」コマンドは、ICカード20の通信部235によって受信される。ICカード20に送信される当該「SELECT」コマンドは、図7ではステップS1で示す。CPU11は、図8のステップST5の処理の後、ステップST6へと進む。   In step ST5, the CPU 11 generates a “SELECT” command that is a command for designating application software. As an example, the “SELECT” command includes an APL associated with application software to be designated. Here, in order to designate application software for processing the “STORE DATA” command, the CPU 11 generates a “SELECT” command as including the APL associated with the application software. Then, the CPU 11 instructs the communication interface 18 to transmit the generated “SELECT” command to the IC card 20. Upon receiving this instruction, the communication interface 18 transmits the “SELECT” command to the IC card 20. The transmitted “SELECT” command is received by the communication unit 235 of the IC card 20. The “SELECT” command transmitted to the IC card 20 is shown in step S1 in FIG. The CPU 11 proceeds to step ST6 after the processing of step ST5 in FIG.

一方、図9のステップST21においてICカード20のCPU231は、通信部235によってコマンドが受信されるのを待ち受けている。CPU231は、「SELECT」コマンドなどのコマンドが受信されたならば、ステップST21においてYesと判定してステップST22へと進む。   On the other hand, in step ST <b> 21 of FIG. 9, the CPU 231 of the IC card 20 waits for a command to be received by the communication unit 235. If a command such as a “SELECT” command is received, the CPU 231 determines Yes in step ST21 and proceeds to step ST22.

ステップST22においてCPU231は、ステップST21において受信を確認したコマンドが「SELECT」コマンドであるか否かを確認する。CPU231は、当該コマンドが「SELECT」コマンドでないならば、当該コマンドに応じた処理をおこなう。そして、CPU231は、当該コマンドが「SELECT」コマンドであるならば、ステップST22においてYesと判定してステップST23へと進む。   In step ST22, the CPU 231 confirms whether or not the command confirmed to be received in step ST21 is a “SELECT” command. If the command is not a “SELECT” command, the CPU 231 performs processing according to the command. If the command is a “SELECT” command, the CPU 231 determines Yes in step ST22 and proceeds to step ST23.

ステップST23においてCPU231は、ステップST21において受信を確認した「SELECT」コマンドを、当該「SELECT」コマンドに含まれるIDで特定されるアプリケーションソフトウェアに入力する。CPU231は、ステップST23の処理の後、ステップST24へと進む。当該アプリケーションソフトウェアに入力される当該「SELECT」コマンドは、図7ではステップS2で示す。   In step ST23, the CPU 231 inputs the “SELECT” command confirmed to be received in step ST21 to the application software specified by the ID included in the “SELECT” command. After the process of step ST23, the CPU 231 proceeds to step ST24. The “SELECT” command input to the application software is shown in step S2 in FIG.

図9のステップST24においてCPU231は、ステップST23の処理を正常に行ったならば、正常終了を示すSW(status word)を含むレスポンスを生成する。正常終了を示すSWは、一例として9000である。なお、CPU231は、ステップST23の処理を正常に行う事が出来なかった場合にはエラーが発生したことを示すSWを含むレスポンスを生成する。その後、CPU231は、生成したレスポンスを、アプリケーションソフトウェアからOSに入力する。CPU231は、ステップST24の処理の後、ステップST25へと進む。アプリケーションソフトウェアからOSに入力される当該レスポンスは、図7ではステップS3で示す。   In step ST24 of FIG. 9, if the process of step ST23 is normally performed, the CPU 231 generates a response including SW (status word) indicating normal termination. The SW indicating normal termination is 9000 as an example. In addition, CPU231 produces | generates the response containing SW which shows that the error generate | occur | produced, when the process of step ST23 cannot be performed normally. Thereafter, the CPU 231 inputs the generated response from the application software to the OS. After the process of step ST24, the CPU 231 proceeds to step ST25. The response input from the application software to the OS is shown in step S3 in FIG.

図9のステップST25においてCPU231は、ステップST24においてOSに入力したレスポンスを通信装置10に送信するように通信部235に対して指示する。この指示を受けて通信部235は、当該レスポンスを通信装置10に送信する。送信された当該レスポンスは、通信装置10の通信インターフェース18によって受信される。当該レスポンスは、図7ではステップS4で示す。CPU231は、図9のステップST25の処理の後、ステップST26へと進む。   In step ST25 of FIG. 9, the CPU 231 instructs the communication unit 235 to transmit the response input to the OS in step ST24 to the communication device 10. Upon receiving this instruction, the communication unit 235 transmits the response to the communication device 10. The transmitted response is received by the communication interface 18 of the communication device 10. The response is shown in step S4 in FIG. After the process of step ST25 in FIG. 9, the CPU 231 proceeds to step ST26.

一方、図8のステップST6において通信装置10のCPU11は、通信インターフェース18によってレスポンスが受信されるのを待ち受けている。CPU11は、レスポンスが受信されたならば、ステップST6においてYesと判定してステップST7へと進む。   On the other hand, in step ST <b> 6 of FIG. 8, the CPU 11 of the communication device 10 waits for a response to be received by the communication interface 18. If a response is received, CPU11 will determine Yes in step ST6, and will progress to step ST7.

ステップST7においてCPU11は、ステップST6において受信を確認したレスポンスが正常終了を示すものであるか否かを確認する。CPU11は、当該レスポンスが正常終了を示すものでないならば、レスポンスの内容に応じたエラー処理を行う。エラー処理についての詳細な説明は省略する。一方、CPU11は、当該レスポンスが正常終了を示すものであるならば、ステップST7においてYesと判定してステップST8へと進む。   In step ST7, the CPU 11 confirms whether or not the response confirmed to be received in step ST6 indicates normal termination. If the response does not indicate normal end, the CPU 11 performs error processing according to the content of the response. A detailed description of error processing is omitted. On the other hand, if the response indicates normal termination, the CPU 11 determines Yes in step ST7 and proceeds to step ST8.

ステップST8においてCPU11は、「STORE DATA」コマンドを生成する。このとき、CPU11は、書き込むデータの特性を示す値として「TYPE_NORMAL」又は「TYPE_LONG」のいずれかを含むものとして「STORE DATA」コマンドを生成する。さらに、CPU11は、データを書き込む位置を示すIDNを含むものとして「STORE DATA」コマンド。なお、図7のシーケンス図は、「STORE DATA」コマンドに「TYPE_LONG」を示す値が含まれる場合の情報の流れを示している。その後、CPU11は、生成した当該「STORE DATA」コマンドをICカード20に送信するように通信インターフェース18に対して指示する。この指示を受けて通信インターフェース18は、当該書き込みコマンドをICカード20に送信する。送信された当該「STORE DATA」コマンドは、ICカード20の通信部235によって受信される。当該「STORE DATA」コマンドは、図7ではステップS5で示す。CPU11は、図8のステップST8の処理の後、ステップST9へと進む。   In step ST8, the CPU 11 generates a “STORE DATA” command. At this time, the CPU 11 generates a “STORE DATA” command that includes either “TYPE_NORMAL” or “TYPE_LONG” as a value indicating the characteristics of the data to be written. Further, the CPU 11 has a “STORE DATA” command as including IDN indicating a position to write data. Note that the sequence diagram of FIG. 7 illustrates the flow of information when the “STORE DATA” command includes a value indicating “TYPE_LONG”. Thereafter, the CPU 11 instructs the communication interface 18 to transmit the generated “STORE DATA” command to the IC card 20. Upon receiving this instruction, the communication interface 18 transmits the write command to the IC card 20. The transmitted “STORE DATA” command is received by the communication unit 235 of the IC card 20. The “STORE DATA” command is shown in step S5 in FIG. After proceeding to step ST8 in FIG. 8, the CPU 11 proceeds to step ST9.

一方、図9のステップST26においてICカード20のCPU231は、通信部235によってコマンドが受信されるのを待ち受けている。CPU231は、「STORE DATA」コマンドなどのコマンドが受信されたならば、ステップST26においてYesと判定してステップST27へと進む。   On the other hand, in step ST <b> 26 of FIG. 9, the CPU 231 of the IC card 20 waits for a command to be received by the communication unit 235. If a command such as a “STORE DATA” command is received, the CPU 231 determines Yes in step ST26 and proceeds to step ST27.

ステップST27においてCPU231は、ステップST26で受信を確認したコマンドが、「STORE DATA」コマンドであるか否かを確認する。CPU231は、ステップST26で受信を確認したコマンドが「STORE DATA」コマンドでないならば、当該コマンドに応じた処理をおこなう。そして、CPU231は、ステップST26で受信を確認したコマンドが「STORE DATA」コマンドであるならば、ステップST27においてYesと判定してステップST28へと進む。   In step ST27, the CPU 231 checks whether or not the command confirmed to be received in step ST26 is a “STORE DATA” command. If the command whose reception is confirmed in step ST26 is not the “STORE DATA” command, the CPU 231 performs processing according to the command. If the command confirmed to be received in step ST26 is the “STORE DATA” command, the CPU 231 determines Yes in step ST27 and proceeds to step ST28.

ステップST28においてCPU231は、ステップST26で受信を確認した「STORE DATA」コマンドを、ステップST21で受信を確認した「SELECT」コマンドに含まれるAPLによって指定されたアプリケーションソフトウェアに入力する。CPU231は、ステップST28の処理の後、ステップST29へと進む。   In step ST28, the CPU 231 inputs the “STORE DATA” command confirmed in step ST26 to the application software designated by the APL included in the “SELECT” command confirmed in step ST21. After the process of step ST28, the CPU 231 proceeds to step ST29.

ステップST29においてCPU231は、暗号鍵を生成するように命令するコマンドを、アプリケーションソフトウェアからOSに対して入力する。当該コマンドは、図7ではステップS7で示す。CPU231は、図9のステップST29の処理の後、ステップST30へと進む。ステップS7に示すように、一例としてCPU231は、KeyBuilder.buildKeyの引数として、TYPE_AES、LENGTH_128及びTYPE_LONGをOSに渡す。なお、これら引数は、「STORE DATA」コマンドがTYPE_LONGを含んでいる場合のものである。「STORE DATA」コマンドがTYPE_NORMALを含む場合には、KeyBuilder.buildKeyの引数は、TYPE_LONGに代えてTYPE_NORMALを含む。   In step ST29, the CPU 231 inputs a command for instructing to generate an encryption key from the application software to the OS. The command is shown in step S7 in FIG. After the process of step ST29 in FIG. 9, the CPU 231 proceeds to step ST30. As shown in step S7, as an example, the CPU 231 passes TYPE_AES, LENGTH_128, and TYPE_LONG to the OS as arguments of KeyBuilder.buildKey. These arguments are for the case where the “STORE DATA” command includes TYPE_LONG. When the “STORE DATA” command includes TYPE_NORMAL, the argument of KeyBuilder.buildKey includes TYPE_NORMAL instead of TYPE_LONG.

ステップST30においてCPU231は、OSと協働してKeyBuilder.buildKeyを実行する。CPU231は、ステップST30の処理の後、図10のステップST31へと進む。   In step ST30, the CPU 231 executes KeyBuilder.buildKey in cooperation with the OS. After the process of step ST30, the CPU 231 proceeds to step ST31 in FIG.

ステップST31においてCPU231は、生成した暗号鍵を不揮発性メモリ234に書き込むために図11に示す書き込み処理を行う。なお、CPU231は、「STORE DATA」コマンドに含まれる、暗号鍵を書き込む位置を示すIDN(以下「IDN_AES」という。)を引数として書き込み処理を開始する。また、CPU231は、図11に示す書き込み処理を開始するとき、変数F1を、一例としてRAM233に割り当てる。
図11のステップST51においてCPU231は、変数F1の値をTrueにする。
In step ST31, the CPU 231 performs a writing process shown in FIG. 11 in order to write the generated encryption key into the nonvolatile memory 234. The CPU 231 starts the writing process with an IDN (hereinafter, referred to as “IDN_AES”) indicating the position to write the encryption key included in the “STORE DATA” command as an argument. Further, when starting the writing process shown in FIG. 11, the CPU 231 assigns the variable F1 to the RAM 233 as an example.
In step ST51 of FIG. 11, the CPU 231 sets the value of the variable F1 to True.

ステップST52においてCPU231は、KeyBuilder.buildKeyの引数にTYPE_LONGが含まれているか否かを確認する。CPU231は、引数にTYPE_LONGが含まれないならば、すなわち引数にTYPE_NORMALが含まれるならばステップST52においてNoと判定してステップST53へと進む。   In step ST <b> 52, the CPU 231 confirms whether or not TYPE_LONG is included in the argument of KeyBuilder.buildKey. If TYPE_LONG is not included in the argument, that is, if TYPE_NORMAL is included in the argument, CPU 231 determines No in step ST52 and proceeds to step ST53.

ステップST53においてCPU231は、生成した暗号鍵を、オリジナル領域のうちIDN_AESで示される領域へと書き込む。なお、IDN_AESで示される領域が存在しない場合は、オリジナル領域の空き領域に書き込む。そして、当該領域のIDNをIDN_AESとする。CPU231は、ステップST53の処理の後、ステップST67へと進む。なお、ここで、オリジナル領域のうちIDN_AESで示される領域は、第1の領域の一例である。   In step ST53, the CPU 231 writes the generated encryption key into the area indicated by IDN_AES in the original area. If the area indicated by IDN_AES does not exist, it is written in the empty area of the original area. Then, IDN of the area is IDN_AES. After the process in step ST53, the CPU 231 proceeds to step ST67. Here, the area indicated by IDN_AES in the original area is an example of the first area.

一方、CPU231は、KeyBuilder.buildKeyの引数にTYPE_LONGが含まれる場合、ステップST52においてYesと判定してステップST54へと進む。
ステップST54においてCPU231は、オリジナル領域のうちIDN_AESで示される領域のヘッダー部の「Count」が値Limitを超えているか否かを確認する。CPU231は、「Count」が値Limitを超えていないならば、ステップST54においてNoと判定してステップST55へと進む。
On the other hand, if the argument of KeyBuilder.buildKey includes TYPE_LONG, the CPU 231 determines Yes in step ST52 and proceeds to step ST54.
In step ST54, the CPU 231 checks whether or not “Count” in the header portion of the area indicated by IDN_AES in the original area exceeds the value Limit. If “Count” does not exceed the value Limit, the CPU 231 determines No in step ST54 and proceeds to step ST55.

ステップST55においてCPU231は、生成した暗号鍵をオリジナル領域のうちIDN_AESで示される領域へと書き込む。なお、IDN_AESで示される領域が存在しない場合は、オリジナル領域の空き領域に書き込む。そして、当該領域のIDNをIDN_AESとする。CPU231は、ステップST55の処理の後、ステップST56へと進む。   In step ST55, the CPU 231 writes the generated encryption key into the area indicated by IDN_AES in the original area. If the area indicated by IDN_AES does not exist, it is written in the empty area of the original area. Then, IDN of the area is IDN_AES. After the process of step ST55, the CPU 231 proceeds to step ST56.

ステップST56においてCPU231は、「Count」の値が初期値であるか否かを確認する。CPU231は、「Count」の値が初期値であるならば、ステップST56においてYesと判定してステップST57へと進む。   In step ST56, the CPU 231 checks whether or not the value of “Count” is an initial value. If the value of “Count” is the initial value, the CPU 231 determines Yes in step ST56 and proceeds to step ST57.

ステップST57においてCPU231は、生成した暗号鍵を含むデータを書き込むために必要な空き領域がミラー領域にあるか否かを確認する。CPU231は、必要な空き領域がミラー領域にあるならば、ステップST57においてYesと判定してステップST58へと進む。   In step ST57, the CPU 231 confirms whether or not a free area necessary for writing data including the generated encryption key exists in the mirror area. If the necessary free area is in the mirror area, the CPU 231 determines Yes in step ST57 and proceeds to step ST58.

ステップST58においてCPU231は、オリジナル領域のうちIDN_AESで示される領域のヘッダー部の「Reserve」に、ミラー領域内にミラー用の領域を確保済みであることを示す値を書き込む。   In step ST58, the CPU 231 writes a value indicating that a mirror area has been reserved in the mirror area in “Reserve” of the header portion of the area indicated by IDN_AES in the original area.

ステップST59においてCPU231は、生成した暗号鍵をミラー領域の空き領域へと書き込む。このとき、CPU231は、当該領域のIDNを、オリジナル領域と同一のIDNであるIDN_AESとする。なお、ここで、当該領域は、第2の領域の一例である。さらに、CPU231は、「Mirror End addr」を更新する。CPU231は、ステップST59の処理の後、ステップST60へと進む。また、CPU231は、「Count」の値が初期値でないならば、ステップST56においてNoと判定してステップST60へと進む。   In step ST59, the CPU 231 writes the generated encryption key in the free area of the mirror area. At this time, the CPU 231 sets IDN of the area as IDN_AES which is the same IDN as the original area. Here, the region is an example of a second region. Further, the CPU 231 updates “Mirror End addr”. After the process of step ST59, CPU 231 proceeds to step ST60. If the value of “Count” is not the initial value, the CPU 231 determines No in step ST56 and proceeds to step ST60.

ステップST60においてCPU231は、オリジナル領域のうちIDN_AESで示される領域のヘッダー部の「Count」の値に1を加える。さらに、CPU231は、ステップST59又はステップST65の処理をした後にステップST60の処理をする場合には、ミラー領域のうちIDN_AESで示される領域のヘッダー部の「Count」の値にも1を加える。   In step ST60, the CPU 231 adds 1 to the value of “Count” in the header portion of the area indicated by IDN_AES in the original area. Furthermore, when performing the process of step ST60 after performing the process of step ST59 or step ST65, the CPU 231 also adds 1 to the value of “Count” in the header portion of the area indicated by IDN_AES in the mirror area.

一方、CPU231は、必要な空き領域がミラー領域にないならば、ステップST57においてNoと判定してステップST61へと進む。
ステップST61においてCPU231は、Reserveにミラー領域の記憶領域に空きができることを待つための優先順位を書き込むことで予約を行う。そして、CPU231は、ミラー領域に必要な空き領域ができたならば、オリジナル領域に書き込まれたデータのうち、Reserveに書き込まれた優先順位が高いものから順にステップST58及びステップST59と同様の処理を行う。なお、アプリケーションソフトウェアがアプリケーション領域から削除された場合などにおいてミラー領域の空き領域が増える。CPU231は、ステップST61の処理の後、ステップST62へと進む。
図12を用いて、上記の予約についてさらに説明する。今、図12の左側に示すようにオリジナル領域には、データ1〜データNが書き込まれ、ミラー領域にはデータMまでのデータが書き込まれているとする。そして、ミラー領域はデータMまでで残量がなくなっている。この場合、CPU231は、データNのTYPEがTYPE_LONGであっても、データNのミラーデータをミラー領域に書き込むことができない。この場合、CPU231は、オリジナル領域のデータNのヘッダー部のReserveに優先順位を書き込む。ここで、データMが削除された場合、ミラー領域には空き領域が生まれる。そして、ミラー領域に空き領域が生まれたタイミングで、CPU231は、データNをミラー領域に書き込む。データNをミラー領域に書き込んだ後の状態を図12の右側に示す。
On the other hand, if the necessary free area is not in the mirror area, the CPU 231 determines No in step ST57 and proceeds to step ST61.
In step ST <b> 61, the CPU 231 makes a reservation by writing a priority order for waiting for the storage area of the mirror area to be freed in the reserve area. When the CPU 231 has a free area necessary for the mirror area, the CPU 231 performs the same processing as step ST58 and step ST59 in order from the data written in the original area in the descending order of priority. Do. In addition, when the application software is deleted from the application area, the free area of the mirror area increases. After the process of step ST61, the CPU 231 proceeds to step ST62.
The above reservation will be further described with reference to FIG. Assume that data 1 to data N are written in the original area and data up to data M is written in the mirror area as shown on the left side of FIG. The remaining mirror area is up to data M and no remaining amount is left. In this case, the CPU 231 cannot write the mirror data of the data N in the mirror area even if the TYPE of the data N is TYPE_LONG. In this case, the CPU 231 writes the priority in the Reserve of the header portion of the data N in the original area. Here, when the data M is deleted, an empty area is created in the mirror area. Then, the CPU 231 writes the data N to the mirror area at the timing when an empty area is created in the mirror area. The state after the data N is written in the mirror area is shown on the right side of FIG.

ステップST62においてCPU231は、変数F1の値をFalseにする。つまり、変数F1は、値がFalseのときミラー領域に必要な空き領域が無かったことを示す。   In step ST62, the CPU 231 sets the value of the variable F1 to False. That is, the variable F1 indicates that there is no free space necessary for the mirror area when the value is False.

一方、CPU231は、「Count」の値が値Limitを超えているならばステップST54においてYesと判定してステップST63へと進む。
ステップST63においてCPU231は、ミラー用の領域を確保済みであるか否かを確認する。すなわち、CPU231は、オリジナル領域のうちIDN_AESで示される領域のヘッダー部の「Reserve」の値がミラー用の領域が確保済みであることを示す値であるか否かを確認する。CPU231は、ミラー用の領域を確保済みであるならば、ステップST63においてYesと判定してステップST64へと進む。
On the other hand, if the value of “Count” exceeds the value Limit, the CPU 231 determines Yes in step ST54 and proceeds to step ST63.
In step ST63, the CPU 231 checks whether or not a mirror area has been secured. That is, the CPU 231 checks whether or not the value of “Reserve” in the header portion of the area indicated by IDN_AES in the original area is a value indicating that the mirror area has been secured. If the mirror area has been secured, the CPU 231 determines Yes in step ST63 and proceeds to step ST64.

ステップST64においてCPU231は、生成した暗号鍵をオリジナル領域のうちIDN_AESで示される領域へと書き込む。CPU231は、ステップST64の処理の後、ステップST65へと進む。   In step ST64, the CPU 231 writes the generated encryption key into the area indicated by IDN_AES in the original area. After the process of step ST64, the CPU 231 proceeds to step ST65.

ステップST65においてCPU231は、ミラー領域のIDNを、アドレスの高位からIDN_AESで検索する。そして、CPU231は、IDNがIDN_AESである領域を検出したならば、当該領域のデータを書き換えて更新することで、生成した暗号鍵を書き込む。なお、ここで、ミラー領域のうちIDN_AESで示される領域は、第2の領域の一例である。   In step ST65, the CPU 231 searches the IDN of the mirror area with IDN_AES from the highest address. If the CPU 231 detects an area whose IDN is IDN_AES, the CPU 231 writes the generated encryption key by rewriting and updating the data in the area. Here, the area indicated by IDN_AES in the mirror area is an example of the second area.

一方、CPU231は、ミラー用の領域を確保済みでないならば、ステップST63においてNoと判定してステップST60へと進む。
CPU231は、ステップST60の処理の後、図11に示す書き込み処理を終了する。このとき、CPU231は、変数F1の値を書き込み処理の戻り値とする。書き込み処理を終了したCPU231は、図10のステップST32へと進む。なお、ステップST30〜ステップST31の処理における情報の流れを、図7ではステップS8で示す。
以上のように、CPU231は、ステップST26において受信を確認したコマンドに基づいてデータの書き込みを行う。したがって、ステップST26の処理を行うことで、CPU231を中枢とするコンピューターは、通信部235と協働して、データの書き込みを命じるコマンドを受信する受信手段として機能する。
また、以上より、CPU231は、ステップST52及びステップST54でYesと判定した場合は、オリジナル領域及びミラー領域にデータを書き込む。すなわち、CPU231は、第1のモードを実行する。そして、CPU231は、ステップST52又はステップST54でNoと判定した場合は、ステップST56でYesと判定される場合を除いて、オリジナル領域にデータを書き込み、ミラー領域にはデータを書き込まない。すなわち、CPU231は、第2のモードを実行する。ここで、CPU231は、ステップST52において、データの特性を示すTYPE_NORMAL又はTYPE_LONGに基づいて判定を行う。さらに、CPU231は、ステップST54において、データの特性を示すCountに基づいて判定を行う。したがって、書き込み処理を行うことで、CPU231を中枢とするコンピューターは、コマンドの受信及びデータの特性に応じて、第1のモード又は第2のモードを選択的に実行する処理手段として機能する。
On the other hand, if the mirror area has not been secured, the CPU 231 determines No in step ST63 and proceeds to step ST60.
After the process in step ST60, the CPU 231 ends the write process shown in FIG. At this time, the CPU 231 uses the value of the variable F1 as the return value of the writing process. After completing the writing process, the CPU 231 proceeds to step ST32 in FIG. Note that the flow of information in the processing of step ST30 to step ST31 is shown in step S8 in FIG.
As described above, the CPU 231 writes data based on the command confirmed to be received in step ST26. Therefore, by performing the process of step ST26, the computer having the CPU 231 as a center functions as a receiving unit that receives a command for instructing data writing in cooperation with the communication unit 235.
As described above, when the CPU 231 determines Yes in step ST52 and step ST54, the CPU 231 writes data in the original area and the mirror area. That is, the CPU 231 executes the first mode. If the CPU 231 determines No in step ST52 or step ST54, the CPU 231 writes the data in the original area and does not write the data in the mirror area unless it is determined Yes in step ST56. That is, the CPU 231 executes the second mode. Here, in step ST52, the CPU 231 performs determination based on TYPE_NORMAL or TYPE_LONG indicating data characteristics. Further, in step ST54, the CPU 231 makes a determination based on Count indicating the data characteristic. Therefore, by performing the writing process, the computer having the CPU 231 as a center functions as a processing unit that selectively executes the first mode or the second mode according to command reception and data characteristics.

ステップST32においてCPU231は、ステップST31の書き込み処理の戻り値がTrueであるか否かを確認する。CPU231は、書き込み処理の戻り値がTrueであるならば、ステップST32においてYesと判定してステップST33へと進む。   In step ST32, the CPU 231 checks whether or not the return value of the writing process in step ST31 is True. If the return value of the writing process is True, the CPU 231 determines Yes in step ST32 and proceeds to step ST33.

ステップST33においてCPU231は、OSが書き込み処理を正常に終えたことを示すため、OSからアプリケーションソフトウェアに対してリターンを返す。CPU231は、ステップST33の処理の後、ステップST35へと進む。   In step ST33, the CPU 231 returns a return from the OS to the application software to indicate that the OS has completed the writing process normally. After the process of step ST33, the CPU 231 proceeds to step ST35.

一方、CPU231は、書き込み処理の戻り値がFalseであるならば、ステップST32においてNoと判定してステップST34へと進む。
ステップST34においてCPU231は、OSが書き込み処理を終えたが、ミラー領域に必要な空き領域が無かったことを示すため、OSからアプリケーションソフトウェアに対してリターンを返す。CPU231は、ステップST34の処理の後、ステップST35へと進む。ステップST33又はステップST34におけるリターンは、図7ではステップS9で示す。
On the other hand, if the return value of the writing process is False, the CPU 231 determines No in step ST32 and proceeds to step ST34.
In step ST34, the CPU 231 returns a return from the OS to the application software in order to indicate that the OS has finished the writing process but there is no free space required in the mirror area. After the process of step ST34, the CPU 231 proceeds to step ST35. The return in step ST33 or step ST34 is indicated by step S9 in FIG.

ステップST35においてCPU231は、暗号鍵をセットするように命令するコマンドを、アプリケーションソフトウェアからOSに対して入力する。CPU231は、ステップST35の処理の後、ステップST36へと進む。当該コマンドは、図7では、ステップS10で示す。   In step ST35, the CPU 231 inputs a command to set the encryption key from the application software to the OS. After the process of step ST35, the CPU 231 proceeds to step ST36. The command is shown in step S10 in FIG.

ステップST36においてCPU231は、暗号鍵をセットする。CPU231は、ステップST36の処理の後、ステップST37へと進む。   In step ST36, the CPU 231 sets an encryption key. After the process of step ST36, the CPU 231 proceeds to step ST37.

ステップST37においてCPU231は、OSが暗号鍵のセットを終えたことを示すため、OSからアプリケーションソフトウェアに対してリターンを返す。CPU231は、ステップST37の処理の後、ステップST38へと進む。当該リターンは、図7では、ステップS11で示す。   In step ST37, the CPU 231 returns a return from the OS to the application software to indicate that the OS has finished setting the encryption key. After the process of step ST37, the CPU 231 proceeds to step ST38. The return is shown in step S11 in FIG.

ステップST38においてCPU231は、ステップST28〜ステップST37の処理を正常に行ったならば、正常終了を示すSWを含むレスポンスを生成する。なお、CPU231は、ステップST32でNoと判定した場合も、ステップST28〜ステップST37の処理は正常に行われたと見做す。SWは、一例として9000である。なお、CPU231は、ステップST28〜ステップST37の処理を正常に行う事が出来なかった場合にはエラーが発生したことを示すSWを含むレスポンスを生成する。その後、CPU231は、生成したレスポンスを通信装置10に送信するように通信部235に対して指示する。その後、CPU231は、生成したレスポンスを、アプリケーションソフトウェアからOSに入力する。CPU231は、ステップST38の処理の後、ステップST39へと進む。OSに入力される当該レスポンスは、図7ではステップS12で示す。   In step ST38, if the processing of step ST28 to step ST37 is normally performed, the CPU 231 generates a response including SW indicating normal termination. Note that the CPU 231 also assumes that the processing of step ST28 to step ST37 has been performed normally even if it is determined No in step ST32. As an example, SW is 9000. Note that the CPU 231 generates a response including SW indicating that an error has occurred when the processing of step ST28 to step ST37 cannot be performed normally. Thereafter, the CPU 231 instructs the communication unit 235 to transmit the generated response to the communication device 10. Thereafter, the CPU 231 inputs the generated response from the application software to the OS. After the process of step ST38, the CPU 231 proceeds to step ST39. The response input to the OS is shown in step S12 in FIG.

ステップST39においてCPU231は、ステップST38においてOSに入力したレスポンスを通信装置10に送信するように通信部235に対して指示する。この指示を受けて通信部235は、当該レスポンスを通信装置10に送信する。送信された当該レスポンスは、通信装置10の通信インターフェース18によって受信される。当該レスポンスは、図7ではステップS13で示す。   In step ST39, the CPU 231 instructs the communication unit 235 to transmit the response input to the OS in step ST38 to the communication device 10. Upon receiving this instruction, the communication unit 235 transmits the response to the communication device 10. The transmitted response is received by the communication interface 18 of the communication device 10. The response is shown in step S13 in FIG.

一方、図8のステップST9において通信装置10のCPU11は、通信インターフェース18によってレスポンスが受信されるのを待ち受けている。CPU11は、レスポンスが受信されたならば、ステップST9においてYesと判定してステップST10へと進む。   On the other hand, in step ST <b> 9 of FIG. 8, the CPU 11 of the communication device 10 waits for a response to be received by the communication interface 18. If a response is received, CPU11 will determine Yes in step ST9, and will progress to step ST10.

ステップST10においてCPU11は、ステップST9において受信を確認したレスポンスが正常終了を示すものであるか否かを確認する。CPU11は、当該レスポンスが正常終了を示すものでないならば、レスポンスの内容に応じたエラー処理を行う。エラー処理についての詳細な説明は省略する。一方、CPU11は、当該レスポンスが正常終了を示すものであるならば、ステップST10においてYesと判定してステップST1へと戻る。   In step ST10, the CPU 11 confirms whether or not the response confirmed to be received in step ST9 indicates normal termination. If the response does not indicate normal end, the CPU 11 performs error processing according to the content of the response. A detailed description of error processing is omitted. On the other hand, if the response indicates normal termination, the CPU 11 determines Yes in step ST10 and returns to step ST1.

次に、ICカード20が、通信装置10からのコマンドを受けて、不揮発性メモリ14に記憶されたデータを通信装置10に送信する処理について図13及び図14に基づいて説明する。なお、ICカード20のCPU231は、図13に示す制御処理を開始するとき、変数i及び変数F2を、一例としてRAM233に割り当てる。   Next, a process in which the IC card 20 receives a command from the communication device 10 and transmits data stored in the nonvolatile memory 14 to the communication device 10 will be described with reference to FIGS. 13 and 14. Note that the CPU 231 of the IC card 20 assigns the variable i and the variable F2 to the RAM 233 as an example when starting the control processing shown in FIG.

通信装置10は、図8のステップST1と同様にして、ICカード20に対して行う処理を決定する。このとき、通信装置10は、ICカード20からデータを読み取る処理を行うことを決定する。
通信装置10のCPU11は、ICカード20からデータを読み取るためのコマンド(以下「読み取りコマンド」という。)を生成する。なお、CPU11は、読み取りたいデータのIDNを含むものとして読み取りコマンドを生成する。その後、CPU11は、生成した当該読み取りコマンドをICカード20に送信するように通信インターフェース18に対して指示する。この指示を受けて通信インターフェース18は、当該読み取りコマンドをICカード20に送信する。送信された当該読み取りコマンドは、ICカード20の通信部235によって受信される。
The communication device 10 determines the processing to be performed on the IC card 20 in the same manner as in step ST1 of FIG. At this time, the communication device 10 determines to perform processing for reading data from the IC card 20.
The CPU 11 of the communication device 10 generates a command for reading data from the IC card 20 (hereinafter referred to as “read command”). Note that the CPU 11 generates a read command on the assumption that the IDN of the data to be read is included. Thereafter, the CPU 11 instructs the communication interface 18 to transmit the generated read command to the IC card 20. Upon receiving this instruction, the communication interface 18 transmits the read command to the IC card 20. The transmitted read command is received by the communication unit 235 of the IC card 20.

一方、図13のステップST71においてICカード20のCPU231は、通信部235によってコマンドが受信されるのを待ち受けている。CPU231は、読み取りコマンドなどのコマンドが受信されたならば、ステップST71においてYesと判定してステップST72へと進む。   On the other hand, in step ST71 of FIG. 13, the CPU 231 of the IC card 20 waits for a command to be received by the communication unit 235. If a command such as a read command is received, CPU 231 determines Yes in step ST71 and proceeds to step ST72.

ステップST72においてCPU231は、ステップST71で受信を確認したコマンドが読み取りコマンドであるか否か確認する。CPU231は、当該コマンドが読み取りコマンドでないならば、当該コマンドに応じた処理をおこなう。そして、CPU231は、当該コマンドが読み取りコマンドであるならば、ステップST72においてYesと判定してステップST73へと進む。   In step ST72, the CPU 231 checks whether or not the command confirmed to be received in step ST71 is a read command. If the command is not a read command, the CPU 231 performs processing according to the command. If the command is a read command, the CPU 231 determines Yes in step ST72 and proceeds to step ST73.

ステップST73においてCPU231は、変数iにアドレス「App Start addr」を代入する。CPU231は、ステップST73の処理の後、ステップST74へと進む。   In step ST <b> 73, the CPU 231 substitutes an address “App Start addr” for the variable i. After the process of step ST73, CPU 231 proceeds to step ST74.

ステップST74においてCPU231は、変数iの値で示されるアドレスのデータに関連付けられたIDNと読み取りコマンドに含まれたIDNとを比較する。そして、CPU231は、比較した2つのIDNが一致するか否かを確認する。CPU231は、2つのIDNが一致しないならば、ステップST74においてNoと判定してステップST75へと進む。なお、CPU231は、変数iの値で示されるアドレスにデータが存在しない場合もステップST74においてNoと判定する。また、CPU231は、変数iの値で示されるアドレスからIDNを読み取れなかった場合もステップST74においてNoと判定する。ここで、IDNが読み取れない場合とは、不揮発性メモリ234が故障していることに起因する場合などが考えられる。   In step ST74, the CPU 231 compares the IDN associated with the data at the address indicated by the value of the variable i with the IDN included in the read command. Then, the CPU 231 confirms whether the two compared IDNs match. If the two IDNs do not match, CPU 231 determines No in step ST74 and proceeds to step ST75. Note that the CPU 231 also determines No in step ST74 when there is no data at the address indicated by the value of the variable i. The CPU 231 also determines No in step ST74 when the IDN cannot be read from the address indicated by the value of the variable i. Here, the case where the IDN cannot be read includes the case where the nonvolatile memory 234 is out of order.

ステップST75においてCPU231は、変数iに、変数iで示されるアドレスのページの次のページに関連付けられたアドレスを代入する。CPU231は、ステップST75の処理の後、ステップST76へと進む。   In step ST75, the CPU 231 substitutes an address associated with the next page of the page indicated by the variable i for the variable i. After the process of step ST75, the CPU 231 proceeds to step ST76.

ステップST76においてCPU231は、変数iの値がアドレス「Mirror Start addr」以上であるか否かを確認する。CPU231は、変数iの値がアドレス「Mirror Start addr」未満であるならば、ステップST76においてNoと判定してステップST74へと戻る。かくして、CPU231は、変数iの値がアドレス「Mirror Start addr」以上となるか、比較した2つのIDNが一致するまでステップST74〜ステップST76を繰り返す。   In step ST76, the CPU 231 confirms whether or not the value of the variable i is equal to or greater than the address “Mirror Start addr”. If the value of variable i is less than the address “Mirror Start addr”, CPU 231 determines No in step ST76 and returns to step ST74. Thus, the CPU 231 repeats steps ST74 to ST76 until the value of the variable i becomes equal to or greater than the address “Mirror Start addr” or the two compared IDNs match.

CPU231は、ステップST74〜ステップST76の繰り返し状態において、2つのIDNが一致したならば、ステップST74においてYesと判定してステップST77へと進む。
ステップST77においてCPU231は、変数iで示されるアドレスのページに含まれるオリジナルデータを読み取る。そして、CPU231は、読み取った当該オリジナルデータをRAM233に記憶する。CPU231は、ステップST77の処理の後、ステップST78へと進む。
If the two IDNs match in the repeated state of step ST74 to step ST76, CPU 231 determines Yes in step ST74 and proceeds to step ST77.
In step ST77, the CPU 231 reads the original data included in the page at the address indicated by the variable i. Then, the CPU 231 stores the read original data in the RAM 233. After the process of step ST77, CPU 231 proceeds to step ST78.

ステップST78においてCPU231は、直前のステップST77の処理においてデータの読み取りが成功したか否かを確認する。CPU231は、データの読み取りが成功したならば、ステップST78においてYesと判定してステップST79へと進む。   In step ST78, the CPU 231 checks whether or not the data has been successfully read in the process of the previous step ST77. If the data has been successfully read, the CPU 231 determines Yes in step ST78 and proceeds to step ST79.

ステップST79においてCPU231は、変数F2の値をTrueにする。なお、変数F2の値がTrueであるとき、変数F2は、オリジナルデータを読み取ることができたことを示す。CPU231は、ステップST79の処理の後、図14のステップST81へと進む。   In step ST79, the CPU 231 sets the value of the variable F2 to True. Note that when the value of the variable F2 is True, the variable F2 indicates that the original data can be read. After the process in step ST79, CPU 231 proceeds to step ST81 in FIG.

一方、CPU231は、図13のステップST77の処理においてデータの読み取りに失敗したならば、ステップST78においてNoと判定してステップST80へと進む。なお、データの読み取りに失敗する場合とは、不揮発性メモリ234が故障していることに起因する場合などが考えられる。
また、CPU231は、ステップST74〜ステップST76の繰り返し状態において、変数iの値がアドレス「Mirror Start addr」以上となった場合には、ステップST76においてYesと判定してステップST80へと進む。
ステップST80においてCPU231は、変数F2の値をFalseにする。なお、変数F2の値がFalseであるとき、変数F2は、オリジナルデータの読み取りができなかったことを示す。CPU231は、ステップST80の処理の後、図14のステップST81へと進む。
On the other hand, if the CPU 231 fails to read data in the process of step ST77 in FIG. 13, the CPU 231 determines No in step ST78 and proceeds to step ST80. Note that the case where data reading fails may be caused by a failure of the nonvolatile memory 234.
On the other hand, if the value of the variable i is equal to or greater than the address “Mirror Start addr” in the repeated state of step ST74 to step ST76, the CPU 231 determines Yes in step ST76 and proceeds to step ST80.
In step ST80, the CPU 231 sets the value of the variable F2 to False. When the value of the variable F2 is False, the variable F2 indicates that the original data could not be read. After the process in step ST80, CPU 231 proceeds to step ST81 in FIG.

ステップST81においてCPU231は、変数iにアドレス「Mirror Start addr」を代入する。CPU231は、ステップST81の処理の後、ステップST82へと進む。   In step ST81, the CPU 231 substitutes an address “Mirror Start addr” for the variable i. After the process of step ST81, the CPU 231 proceeds to step ST82.

ステップST82においてCPU231は、変数iの値で示されるアドレスのデータに関連付けられたIDNと読み取りコマンドに含まれたIDNとを比較する。そして、CPU231は、比較した2つのIDNが一致するか否かを確認する。CPU231は、2つのIDNが一致しないならば、ステップST82においてNoと判定してステップST83へと進む。なお、CPU231は、変数iの値で示されるページが存在しない場合もステップST82においてNoと判定する。また、CPU231は、変数iの値で示されるページからIDNを読み取れない場合もステップST82においてNoと判定する。ここで、IDNが読み取れない場合とは、不揮発性メモリ234が故障していることに起因する場合などが考えられる。   In step ST82, the CPU 231 compares the IDN associated with the data at the address indicated by the value of the variable i with the IDN included in the read command. Then, the CPU 231 confirms whether the two compared IDNs match. If the two IDNs do not match, CPU 231 determines No in step ST82 and proceeds to step ST83. Note that the CPU 231 also determines No in step ST82 when there is no page indicated by the value of the variable i. The CPU 231 also determines No in step ST82 when the IDN cannot be read from the page indicated by the value of the variable i. Here, the case where the IDN cannot be read includes the case where the nonvolatile memory 234 is out of order.

ステップST83においてCPU231は、変数iに、変数iで示されるアドレスのページの次のページに関連付けられたアドレスを代入する。CPU231は、ステップST83の処理の後、ステップST84へと進む。   In step ST83, the CPU 231 substitutes an address associated with the next page of the page indicated by the variable i for the variable i. After the process of step ST83, CPU 231 proceeds to step ST84.

ステップST84においてCPU231は、変数iの値がアドレス「Mirror End addr」以上であるか否かを確認する。CPU231は、変数iの値がアドレス「Mirror End addr」未満であるならば、ステップST84においてNoと判定してステップST85へと戻る。かくして、CPU231は、変数iの値がアドレス「Mirror End addr」以上となるか、比較した2つのIDNが一致するまでステップST82〜ステップST84を繰り返す。   In step ST84, the CPU 231 confirms whether or not the value of the variable i is equal to or greater than the address “Mirror End addr”. If the value of variable i is less than the address “Mirror End addr”, CPU 231 determines No in step ST84 and returns to step ST85. Thus, the CPU 231 repeats steps ST82 to ST84 until the value of the variable i becomes equal to or greater than the address “Mirror End addr” or the two compared IDNs match.

CPU231は、ステップST82〜ステップST84の繰り返し状態において、2つのIDNが一致したならば、ステップST82においてYesと判定してステップST85へと進む。
ステップST85においてCPU231は、変数iの値で示されるアドレスのページに含まれるミラーデータを読み取る。そして、CPU231は、読み取った当該ミラーデータをRAM233に記憶する。CPU231は、ステップST85の処理の後、ステップST86へと進む。
If the two IDNs match in the repeated state of step ST82 to step ST84, CPU 231 determines Yes in step ST82 and proceeds to step ST85.
In step ST85, the CPU 231 reads the mirror data included in the page at the address indicated by the value of the variable i. Then, the CPU 231 stores the read mirror data in the RAM 233. After the process of step ST85, CPU 231 proceeds to step ST86.

ステップST86においてCPU231は、変数F2の値がTrueであるか否かを確認する。CPU231は、変数F2の値がTrueであるならば、ステップST86においてYesと判定してステップST87へと進む。   In step ST86, the CPU 231 checks whether or not the value of the variable F2 is True. If the value of variable F2 is True, CPU 231 determines Yes in step ST86 and proceeds to step ST87.

ステップST87においてCPU231は、ステップST77で記憶したオリジナルデータとステップST85で記憶したミラーデータとを比較して、当該2つのデータが同一であるか否かを確認する。なお、比較の方法は問わないが、例えば次のように行う。すなわち、CPU231は、当該2つのデータのそれぞれについてハッシュ値を算出する。そして、CPU231は、算出した2つのハッシュ値が同一であるならば、当該2つのデータは同一であると見做す。CPU231は、2つのデータが同一であるならば、ステップST87においてYesと判定して、ステップST88へと進む。   In step ST87, the CPU 231 compares the original data stored in step ST77 with the mirror data stored in step ST85, and confirms whether the two data are the same. The comparison method is not limited, but is performed as follows, for example. That is, the CPU 231 calculates a hash value for each of the two data. Then, if the calculated two hash values are the same, the CPU 231 considers the two data to be the same. If the two data are the same, CPU 231 determines Yes in step ST87 and proceeds to step ST88.

ステップST88においてCPU231は、ステップST77で記憶したオリジナルデータを通信装置10に送信するために、レスポンスを生成する。なお、CPU231は、当該オリジナルデータを含むものとして当該レスポンスを生成する。そして、CPU231は、生成した当該レスポンスを通信装置10に送信するように通信部235に対して指示する。この指示を受けて通信部235は、当該レスポンスを通信装置10に送信する。送信された当該レスポンスは、通信装置10の通信インターフェース18によって受信される。通信装置10は、当該レスポンスを受信することにより、読み取りコマンドで要求したデータを入手する。   In step ST88, the CPU 231 generates a response to transmit the original data stored in step ST77 to the communication device 10. The CPU 231 generates the response as including the original data. Then, the CPU 231 instructs the communication unit 235 to transmit the generated response to the communication device 10. Upon receiving this instruction, the communication unit 235 transmits the response to the communication device 10. The transmitted response is received by the communication interface 18 of the communication device 10. The communication device 10 acquires the data requested by the read command by receiving the response.

一方、CPU231は、2つのデータが同一でないならば、ステップST87においてNoと判定して、ステップST89へと進む。
ステップST89においてCPU231は、ステップST85で記憶したミラーデータを通信装置10に送信するために、レスポンスを生成する。なお、CPU231は、当該ミラーデータを含むものとして当該レスポンスを生成する。そして、CPU231は、生成した当該レスポンスを通信装置10に送信するように通信部235に対して指示する。この指示を受けて通信部235は、当該レスポンスを通信装置10に送信する。送信された当該レスポンスは、通信装置10の通信インターフェース18によって受信される。通信装置10は、当該レスポンスを受信することにより、読み取りコマンドで要求したデータを入手する。なお、ステップST77で記憶したオリジナルデータとステップST85で記憶したミラーデータとが異なる場合に、通信装置10にミラーデータを送信するのは、オリジナルデータよりもミラーデータの方が、データが壊れている可能性が低いからである。これは、オリジナルデータよりもミラーデータの方が、書き込み回数の少ないミラー領域に書き込まれているためである。
On the other hand, if the two data are not identical, CPU 231 determines No in step ST87 and proceeds to step ST89.
In step ST89, the CPU 231 generates a response to transmit the mirror data stored in step ST85 to the communication device 10. Note that the CPU 231 generates the response as including the mirror data. Then, the CPU 231 instructs the communication unit 235 to transmit the generated response to the communication device 10. Upon receiving this instruction, the communication unit 235 transmits the response to the communication device 10. The transmitted response is received by the communication interface 18 of the communication device 10. The communication device 10 acquires the data requested by the read command by receiving the response. When the original data stored in step ST77 and the mirror data stored in step ST85 are different, the mirror data is transmitted to the communication device 10 because the mirror data is broken rather than the original data. This is because the possibility is low. This is because the mirror data is written in the mirror area where the number of times of writing is smaller than the original data.

また、CPU231は、ステップST82〜ステップST84の繰り返し状態において、変数iの値がアドレス「Mirror End addr」以上となった場合には、ステップST84においてYesと判定してステップST90へと進む。
ステップST90においてCPU231は、変数F2の値がFalseであるか否かを確認する。CPU231は、変数F2の値がTrueであるならば、ステップST90においてNoと判定してステップST88へと進む。また、CPU231は、変数F2の値がFalseであるならば、ステップST90においてYesと判定してステップST91へと進む。
On the other hand, when the value of the variable i is equal to or greater than the address “Mirror End addr” in the repeated state of step ST82 to step ST84, the CPU 231 determines Yes in step ST84 and proceeds to step ST90.
In step ST90, the CPU 231 checks whether or not the value of the variable F2 is False. If the value of variable F2 is True, CPU 231 determines No in step ST90 and proceeds to step ST88. On the other hand, if the value of variable F2 is False, CPU 231 determines Yes in step ST90 and proceeds to step ST91.

ステップST91においてCPU231は、データが読み取れなかったことに因るエラーが発生したことを通信装置10に通知するために、レスポンスを生成する。なお、CPU231は、エラーの内容を示す情報含むものとして当該レスポンスを生成する。そして、CPU231は、生成した当該レスポンスを通信装置10に送信するように通信部235に対して指示する。この指示を受けて通信部235は、当該レスポンスを通信装置10に送信する。送信された当該レスポンスは、通信装置10の通信インターフェース18によって受信される。通信装置10は、当該レスポンスを受信したならば、当該レスポンスに含まれるエラーの内容に応じた処理を行う。   In step ST91, the CPU 231 generates a response to notify the communication device 10 that an error has occurred due to the failure to read data. Note that the CPU 231 generates the response as including information indicating the content of the error. Then, the CPU 231 instructs the communication unit 235 to transmit the generated response to the communication device 10. Upon receiving this instruction, the communication unit 235 transmits the response to the communication device 10. The transmitted response is received by the communication interface 18 of the communication device 10. When the communication device 10 receives the response, the communication device 10 performs processing according to the content of the error included in the response.

CPU231は、ステップST89、ステップST90又はステップST92の処理の後、図13のステップST71へと戻る。なお、ステップST71に戻るとき、CPU231は、RAM233にオリジナルデータが記憶されている場合には、当該オリジナルデータをRAM233から削除する。また、ステップST71に戻るとき、CPU231は、RAM233にミラーデータが記憶されている場合には、当該ミラーデータをRAM233から削除する。   After the process of step ST89, step ST90, or step ST92, CPU 231 returns to step ST71 of FIG. When returning to step ST71, if the original data is stored in the RAM 233, the CPU 231 deletes the original data from the RAM 233. When returning to step ST <b> 71, when the mirror data is stored in the RAM 233, the CPU 231 deletes the mirror data from the RAM 233.

実施形態のICカード20によれば、データの書き込みを命じるコマンドを受信した場合、当該データの特性に応じて不揮発性メモリ234にオリジナルデータを書き込むか、オリジナルデータとミラーデータとを書き込むかを決定する。ICカード20は、オリジナルデータだけでなくミラーデータも書き込んだ場合、書き換えを何度も行うことによって不揮発性メモリ234が故障するなどしてオリジナルデータが読み込めなくなったとしてもミラーデータを読み込むことができる。したがって、オリジナルデータを書き込む場合に比べて、データを書き換えることができる回数が増加する。   According to the IC card 20 of the embodiment, when a command for writing data is received, it is determined whether to write the original data or the original data and the mirror data in the nonvolatile memory 234 according to the characteristics of the data. To do. When the IC card 20 writes not only the original data but also the mirror data, the mirror data can be read even if the original data cannot be read due to failure of the non-volatile memory 234 due to repeated rewriting. . Therefore, the number of times data can be rewritten increases compared to the case where original data is written.

また、実施形態のICカード20によれば、データの更新頻度に応じて不揮発性メモリ234にオリジナルデータを書き込むか、オリジナルデータとミラーデータとを書き込むかを決定する。したがって、ICカード20は、更新頻度の高いデータについてはオリジナルデータとミラーデータとを書き込み、更新頻度の低いデータについてはオリジナルデータだけを書き込むことができる。更新頻度の低いデータは、ミラーデータを書き込む必要性が薄いので、このようにすることで不揮発性メモリ234のデータ容量を節約することができる。   Further, according to the IC card 20 of the embodiment, it is determined whether to write the original data or the original data and the mirror data in the nonvolatile memory 234 according to the data update frequency. Therefore, the IC card 20 can write original data and mirror data for data with high update frequency, and can write only original data for data with low update frequency. Since it is less necessary to write mirror data for data with low update frequency, the data capacity of the nonvolatile memory 234 can be saved by doing so.

また、実施形態のICカード20によれば、データの書き込みを命じるコマンドに含まれるIDNに応じてオリジナルデータの書き込み位置を特定する。そして、当該オリジナルデータのCountが値Limitを超えている場合には、ミラーデータも書き込む。このようにすることで、例えば、書き込み保障回数が20万回で値Limitが18万である場合には、ICカード20は、最初の約18万回目はオリジナルデータを書き込む。そして、ICカード20は、約18万回目からはオリジナルデータに加えてミラーデータも書き込む。そして、そこから20万回のデータ書き換えまではミラーデータは書き込み保障の範囲内となる。したがって、書き込み保障回数が20万回のところ、オリジナル領域とミラー領域で合計約38万回まで書き込み保障回数を延長することができる。すなわち、ICカード20は、ミラーデータを書き込まない場合に比べて、データを書き換えることができる回数を増やすことができる。一般的に、ICカードの使用期間が長期にわたると書き換え回数は増加しデータの信頼性が低下するが、ミラーデータの書き込みによりデータの信頼性低下を防止することができる。言い換えれば、ミラーデータの書き込みにより保証期間を長期化することができる。   Further, according to the IC card 20 of the embodiment, the writing position of the original data is specified according to the IDN included in the command for commanding data writing. If the count of the original data exceeds the value Limit, the mirror data is also written. In this way, for example, when the guaranteed write count is 200,000 times and the value Limit is 180,000, the IC card 20 writes the original data for the first approximately 180,000 times. The IC card 20 also writes mirror data in addition to the original data from about 180,000 times. From then on, mirror data is within the guaranteed range of writing until 200,000 times of data rewriting. Therefore, when the guaranteed write count is 200,000, the guaranteed write count can be extended to approximately 380,000 times in total in the original area and the mirror area. That is, the IC card 20 can increase the number of times data can be rewritten compared to the case where mirror data is not written. In general, when the IC card is used for a long period of time, the number of rewrites increases and the reliability of the data decreases, but writing of mirror data can prevent a decrease in the reliability of the data. In other words, the guarantee period can be extended by writing mirror data.

また、実施形態のICカード20によれば、データごとに更新回数をカウントする。したがって、データごとに書き込み保障回数(又は保証期間)を延長することができる。   Further, according to the IC card 20 of the embodiment, the number of updates is counted for each data. Therefore, the guaranteed number of times of writing (or the guarantee period) can be extended for each data.

また、実施形態のICカード20によれば、データの書き込みを命じるコマンドがTYPE_LONG及びTYPE_NORMALのいずれを含むかに応じてオリジナルデータだけを書き込むか、オリジナルデータとミラーデータとを書き込むかを決定する。ここで、TYPE_LONGは、更新頻度の高いデータに用いられる。そして、TYPE_NORMALは、更新頻度の低いデータに用いられる。したがって、ICカード20は、更新頻度の高いデータであるか低いデータであるかを容易に判別することができる。また、TYPE_NORMALとするかTYPE_LONGとするかは、通信装置10側で決定することができる。したがって、通信装置10は、オリジナルデータだけを書き込むか、オリジナルデータとミラーデータとを書き込むかをICカード20に指示することができる。   Further, according to the IC card 20 of the embodiment, it is determined whether to write only the original data or to write the original data and the mirror data depending on whether the command for writing data includes TYPE_LONG or TYPE_NORMAL. Here, TYPE_LONG is used for data with a high update frequency. TYPE_NORMAL is used for data with low update frequency. Therefore, the IC card 20 can easily determine whether the data is frequently updated data or low data. In addition, it can be determined on the communication device 10 side whether TYPE_NORMAL or TYPE_LONG is set. Therefore, the communication device 10 can instruct the IC card 20 to write only the original data or write the original data and the mirror data.

また、実施形態のICカード20によれば、読み取りコマンドを受信した場合、ミラーデータをコマンドの送信元に送信する場合がある。ミラーデータは、オリジナルデータに比べて書き換え回数が少ないためデータが壊れている可能性が低い。したがって、ミラーデータを送信する場合、オリジナルデータを送信する場合に比べて、壊れていないデータを送信することができる可能性が高い。   Further, according to the IC card 20 of the embodiment, when a read command is received, mirror data may be transmitted to the command transmission source. Since the mirror data has a smaller number of rewrites than the original data, the possibility of data corruption is low. Therefore, when mirror data is transmitted, it is highly possible that unbroken data can be transmitted as compared with the case where original data is transmitted.

また、実施形態のICカード20によれば、オリジナルデータはオリジナル領域に、ミラーデータはミラー領域に書き込まれる。不揮発性メモリ234のメモリ空間をオリジナル領域とミラー領域とに分けることで、オリジナルデータとミラーデータとのアドレスを離すことができる。これにより、オリジナルデータが書き込まれた領域における故障が、ミラーデータが書き込まれた領域に波及する可能性を低減することができる。また、オリジナル領域とミラー領域に分けることで、オリジナルデータの中から検索したい場合、又はミラーデータの中から検索したい場合などにおいて、オリジナルデータとミラーデータとの区分が容易である。   Further, according to the IC card 20 of the embodiment, the original data is written in the original area and the mirror data is written in the mirror area. By dividing the memory space of the nonvolatile memory 234 into the original area and the mirror area, the addresses of the original data and the mirror data can be separated. Thereby, it is possible to reduce the possibility that a failure in the area where the original data is written will spread to the area where the mirror data is written. Also, by dividing the original data into the mirror data, it is easy to distinguish the original data from the mirror data when searching from the original data or when searching from the mirror data.

また、実施形態のICカード20によれば、ミラー領域の空き容量が不足している場合には、ミラー領域の空き容量が増えるまで待つ。そして、ICカード20は、データの削除などによってミラー領域の空き容量が増えたならば、ミラー領域にデータを書き込む。したがって、ミラー領域の空き容量が不足している場合であっても、ミラー領域へのデータの書き込みは中止する必要が無く、空き容量が増えた時点で書き込みを再開することができる。   Further, according to the IC card 20 of the embodiment, when the free space in the mirror area is insufficient, the process waits until the free space in the mirror area increases. The IC card 20 writes data in the mirror area when the free space in the mirror area increases due to data deletion or the like. Therefore, even when the free space in the mirror area is insufficient, it is not necessary to stop writing data to the mirror area, and writing can be resumed when the free space increases.

上記の実施形態は以下のような変形も可能である。
上記の実施形態では、不揮発性メモリ234に書き込むデータとして、AESにおける暗号鍵を例にとって説明した。しかしながら、不揮発性メモリ234に書き込むデータは、暗号鍵に限らず、データの内容は限定しない。
上記の実施形態では、「STORE DATA」コマンドを例にとって説明した。しかしながら、データの書き込みを伴うその他のコマンドであっても本実施形態を適用することができる。
The embodiment described above can be modified as follows.
In the above embodiment, the encryption key in AES has been described as an example of data to be written in the nonvolatile memory 234. However, the data written to the nonvolatile memory 234 is not limited to the encryption key, and the content of the data is not limited.
In the above embodiment, the “STORE DATA” command has been described as an example. However, the present embodiment can also be applied to other commands that involve data writing.

「STORE DATA」コマンドは、TYPE_NORMAL及びTYPE_LONGのいずれも含んでいなくても良い。この場合、CPU231がステップST52の処理においてYesと判定するかNoと判定するかは、一例としてICカード20の設計者などによって予め定められる。   The “STORE DATA” command may not include either TYPE_NORMAL or TYPE_LONG. In this case, whether the CPU 231 determines Yes or No in the process of step ST52 is determined in advance by the designer of the IC card 20 as an example.

CPU231は、TYPEに拘わらずにCountの値によってミラー領域へ書き込むか否かを決定しても良い。すなわち、CPU231は、一例としてステップST51の処理の後、ステップST52の処理をスキップしてステップST54へと進んでも良い。
CPU231は、Countの値に拘わらずにTYPEによってミラー領域へ書き込むか否かを決定しても良い。すなわち、CPU231は、一例としてステップST53でYesと判定した場合、ステップST54の処理をスキップしてステップST63へと進んでも良い。
The CPU 231 may determine whether to write to the mirror area based on the value of Count regardless of TYPE. That is, as an example, after the process of step ST51, the CPU 231 may skip the process of step ST52 and proceed to step ST54.
The CPU 231 may determine whether to write to the mirror area by TYPE regardless of the value of Count. That is, if CPU 231 determines Yes in step ST53 as an example, it may skip step ST54 and proceed to step ST63.

上記の実施形態では、図7のステップS7に示すKeyBuilder.buildKeyの引数は、「STORE DATE」に含まれるTYPEと同一のTYPEが含まれるとした。しかしながら、CPU231は、KeyBuilder.buildKeyの引数に含むTYPEを、「STORE DATE」と異なるものとすることができても良い。また、CPU231は、「STORE DATE」に含まれるTYPEに拘わらずにKeyBuilder.buildKeyに含むTYPEを決定しても良い。   In the above embodiment, KeyBuilder. Shown in step S7 of FIG. The argument of buildKey is assumed to include the same TYPE as the TYPE included in “STORE DATE”. However, the CPU 231 is not compatible with KeyBuilder. The TYPE included in the argument of buildKey may be different from “STORE DATE”. In addition, the CPU 231 determines whether or not KeyBuilder. The TYPE included in the buildKey may be determined.

上記の実施形態では、オリジナルデータのCountが値Limitを超えた場合、ステップST64及びステップST65においてオリジナル領域とミラー領域の両方にデータを書き込んだ。しかしながら、CPU231は、オリジナルデータのCountが値Limitを超えた場合、オリジナル領域にはデータを書き込まずにミラー領域にデータを書き込んでも良い。   In the above embodiment, when the count of the original data exceeds the value Limit, the data is written in both the original area and the mirror area in step ST64 and step ST65. However, when the count of the original data exceeds the value Limit, the CPU 231 may write the data in the mirror area without writing the data in the original area.

ICカード20は、オリジナル領域への書き込みが上手くいかなかった場合、以降はオリジナル領域への書き込みは行わずにミラー領域にデータを書き込んでも良い。ここで、オリジナル領域への書き込みが上手くいかない場合とは、不揮発性メモリ234が故障していることに起因する場合などが考えられる。   The IC card 20 may write data to the mirror area without writing to the original area after the writing to the original area is not successful. Here, the case where writing into the original area is not successful may be caused by the failure of the nonvolatile memory 234.

ICカード20は、読み取りコマンドを受信した場合に、オリジナルデータを読み取らずにミラーデータを読み取っても良い。すなわち、CPU231は、一例としてステップST72においてYesと判定した場合、ステップST81へと進んでも良い。この場合、CPU231は、ステップST85の処理の後、ステップST86及びステップST87の処理をスキップしてステップST89へと進む。そして、CPU231は、ステップST84においてYesと判定した場合、ステップST90をスキップしてステップST91へと進む。   The IC card 20 may read the mirror data without reading the original data when the read command is received. That is, if CPU 231 determines Yes in step ST72 as an example, it may proceed to step ST81. In this case, after the process of step ST85, the CPU 231 skips the processes of step ST86 and step ST87, and proceeds to step ST89. If the CPU 231 determines Yes in step ST84, it skips step ST90 and proceeds to step ST91.

上記の実施形態では、ICカード20は、ステップST73〜ステップST77においてオリジナルデータの読み取りを試みた後に、ステップST81〜ステップST85においてミラーデータの読み取りを試みた。しかしながら、ICカード20は、ミラーデータの読み取りを試みた後にオリジナルデータの読み取りを試みても良い。なおこのとき、ICカード20は、ミラーデータの読み取りに成功した場合、オリジナルデータの読み取りを試行しなくても良い。そして、ICカード20は、ミラーデータの読み取りに成功した場合、ミラーデータを通信装置10に送信する。   In the above embodiment, the IC card 20 attempted to read the mirror data in steps ST81 to ST85 after attempting to read the original data in steps ST73 to ST77. However, the IC card 20 may attempt to read the original data after attempting to read the mirror data. At this time, if the IC card 20 succeeds in reading the mirror data, the IC card 20 may not attempt to read the original data. When the IC card 20 succeeds in reading the mirror data, the IC card 20 transmits the mirror data to the communication device 10.

ICカード20は、オリジナルデータとミラーデータとを比較して当該2つのデータが同一であった場合、オリジナルデータに代えて、ミラーデータを送信しても良い。すなわち、CPU231は、図14のステップST87においてYesと判定した場合、ステップST88に代えてステップST89へと進んでも良い。   When the original data and the mirror data are compared and the two data are the same, the IC card 20 may transmit the mirror data instead of the original data. That is, if CPU 231 determines Yes in step ST87 in FIG. 14, CPU 231 may proceed to step ST89 instead of step ST88.

値Limitは書き換え可能であっても良い。値Limitが書き換え可能であれば、書き込み保障回数の延長回数を後から変更することができる。   The value Limit may be rewritable. If the value Limit is rewritable, the extension number of the write guarantee count can be changed later.

上記の実施形態における図9〜図11、図13及び図14に示す処理のそれぞれは、CPU231が行った。しかしながら、これら処理のうちの一部又は全部をCo−Pro237がCPU231に代えて処理を行っても良い。あるいは、これら処理のうちの一部又は全部をCPU231とCo−Pro237とが協働して処理を行っても良い。   Each of the processes shown in FIGS. 9 to 11, 13, and 14 in the above embodiment is performed by the CPU 231. However, the Co-Pro 237 may perform some or all of these processes in place of the CPU 231. Alternatively, some or all of these processes may be performed by the CPU 231 and the Co-Pro 237 working together.

上記の実施形態では、オリジナルデータはアドレス低位側からアドレス高位側へ、ミラーデータはMirror Start addrからアドレス高位側へ書き込まれていく。しかしながら、オリジナルデータ及びミラーデータが書き込まれる位置及び書き込まれる順番は限定しない。例えば、オリジナルデータは、アドレス高位側からアドレス低位側へ書き込まれても良い。また例えば、ミラーデータは、アドレス高位側からアドレス低位側、あるいはアドレス低位側からアドレス高位側へ書き込まれても良い。
上記の実施形態ではアプリケーション領域をオリジナル領域とミラー領域とで分割したが、領域を分割せず、オリジナルデータとミラーデータとが混在していても良い。
In the above embodiment, the original data is written from the low address side to the high address side, and the mirror data is written from the Mirror Start addr to the high address side. However, the position where the original data and the mirror data are written and the order of writing are not limited. For example, the original data may be written from the higher address side to the lower address side. Further, for example, the mirror data may be written from the high address side to the low address side, or from the low address side to the high address side.
In the above embodiment, the application area is divided into the original area and the mirror area. However, the original data and the mirror data may be mixed without dividing the area.

上記の実施形態では、ICカード20は、不揮発性メモリ234に、オリジナルデータに対応するミラーデータを1つ書き込んだ。しかしながら、ICカード20は、不揮発性メモリ234に、オリジナルデータに対応するミラーデータを2つ書きこんでも良い。この場合、2つ目のミラーデータは、例えば、1つ目のミラーデータのCountが予め定められた閾値を超えた場合に書き込む。すなわち、2つ目のミラーデータは、1つ目のミラーデータのミラーに相当する。同様に、ICカード20は、3つ以上のミラーデータを不揮発性メモリ234に書き込んでも良い。ICカード20は、2つ以上のミラーデータを書き込むことで、ミラーデータが1つの場合に比べて、さらにデータを書き換える回数を増やすことができる。   In the above embodiment, the IC card 20 writes one mirror data corresponding to the original data in the nonvolatile memory 234. However, the IC card 20 may write two mirror data corresponding to the original data in the nonvolatile memory 234. In this case, the second mirror data is written, for example, when the count of the first mirror data exceeds a predetermined threshold. That is, the second mirror data corresponds to the mirror of the first mirror data. Similarly, the IC card 20 may write three or more mirror data in the nonvolatile memory 234. By writing two or more mirror data, the IC card 20 can further increase the number of times data is rewritten as compared with the case of one mirror data.

上記の実施形態はICカードの場合について説明した。しかしながら、ICチップを搭載したその他の電子機器であっても良い。また、データを記憶することができる種々の電子機器に上記の実施形態を適用することができる。   The above embodiment has been described for the case of an IC card. However, other electronic devices equipped with an IC chip may be used. Further, the above-described embodiment can be applied to various electronic devices that can store data.

本発明のいくつかの実施形態を説明したが、これらの実施形態は、例として提示したものであり、発明の範囲を限定することは意図していない。これら新規な実施形態は、その他の様々な形態で実施されることが可能であり、発明の要旨を逸脱しない範囲で、種々の省略、置き換え、変更を行うことができる。これら実施形態やその変形は、発明の範囲や要旨に含まれるとともに、特許請求の範囲に記載された発明とその均等の範囲に含まれる。   Although several embodiments of the present invention have been described, these embodiments are presented by way of example and are not intended to limit the scope of the invention. These novel embodiments can be implemented in various other forms, and various omissions, replacements, and changes can be made without departing from the scope of the invention. These embodiments and modifications thereof are included in the scope and gist of the invention, and are included in the invention described in the claims and the equivalents thereof.

1…ICカードシステム、10…通信装置、11,231…CPU、12,232…ROM、13,233…RAM、14,234…不揮発性メモリ、15…リーダーライター、16…表示デバイス、17…入力デバイス、18通信インターフェース、19,238…バス、20…ICカード、21…本体、22…ICモジュール、23…ICチップ、235…通信部、236…電源部、237…Co−Pro   DESCRIPTION OF SYMBOLS 1 ... IC card system, 10 ... Communication apparatus, 11, 231 ... CPU, 12,232 ... ROM, 13,233 ... RAM, 14,234 ... Nonvolatile memory, 15 ... Reader / writer, 16 ... Display device, 17 ... Input Device, 18 communication interface, 19, 238 ... bus, 20 ... IC card, 21 ... main body, 22 ... IC module, 23 ... IC chip, 235 ... communication unit, 236 ... power supply unit, 237 ... Co-Pro

Claims (8)

複数の領域を備える記憶手段と、
データの書き込みを命じるコマンドを受信する受信手段と、
前記コマンドの受信及び前記データの特性に応じて、前記複数の領域のうちの第1及び第2の領域に前記データを書き込む第1のモード、及び前記第1の領域に前記データを書き込む第2のモードを選択的に実行する処理手段と、を具備する電子装置。
Storage means comprising a plurality of areas;
Receiving means for receiving a command to write data;
A first mode in which the data is written in the first and second areas of the plurality of areas, and a second mode in which the data is written in the first area according to the reception of the command and the characteristics of the data. Processing means for selectively executing the mode.
前記データの特性は、更新頻度である、請求項1に記載の電子装置。   The electronic device according to claim 1, wherein the characteristic of the data is an update frequency. 前記処理手段は、前記第1の領域の更新回数に基づき、前記第1及び第2のモードを選択的に実行する、請求項1又は2に記載の電子装置。   The electronic device according to claim 1, wherein the processing unit selectively executes the first mode and the second mode based on the number of updates of the first region. 前記処理手段は、各領域のデータの更新回数をカウントする、請求項3に記載の電子装置。   The electronic device according to claim 3, wherein the processing unit counts the number of times data is updated in each area. 前記コマンドは、前記データの特性を識別する情報を含む、請求項1又は請求項2に記載の電子装置。   The electronic device according to claim 1, wherein the command includes information that identifies a characteristic of the data. 前記処理手段は、データの要求に対して前記第2の領域のデータを出力する請求項1乃至請求項5のいずれか1項に記載の電子装置。 The electronic device according to claim 1, wherein the processing unit outputs the data in the second area in response to a data request. 前記記憶手段は、前記複数の領域のうちの所定数の領域を含むオリジナル領域と、前記複数の領域のうちの所定数の領域を含むミラー領域とを備え、
前記オリジナル領域は、前記第1の領域を含み、
前記処理手段は、前記ミラー領域に前記第2の領域を予約し、前記予約及び前記ミラー領域の空き容量に基づき前記ミラー領域に前記第2の領域を設定する、請求項1乃至6のいずれか1項に記載の電子装置。
The storage means includes an original area including a predetermined number of areas of the plurality of areas, and a mirror area including a predetermined number of areas of the plurality of areas,
The original area includes the first area,
7. The processing unit according to claim 1, wherein the processing unit reserves the second area in the mirror area, and sets the second area in the mirror area based on the reservation and a free capacity of the mirror area. The electronic device according to item 1.
前記処理手段は、前記第1のモードの選択に対応して、前記第2の領域が未設定の場合には前記第1の領域に前記データを書き込み、前記第2の領域が設定されたタイミングに基づき前記第2の領域に前記データを書き込む、請求項7に記載の電子装置。   In response to the selection of the first mode, the processing means writes the data in the first area when the second area is not set, and the timing at which the second area is set The electronic device according to claim 7, wherein the data is written to the second area based on the data.
JP2017043649A 2017-03-08 2017-03-08 Electronic device Pending JP2018147345A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2017043649A JP2018147345A (en) 2017-03-08 2017-03-08 Electronic device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2017043649A JP2018147345A (en) 2017-03-08 2017-03-08 Electronic device

Publications (1)

Publication Number Publication Date
JP2018147345A true JP2018147345A (en) 2018-09-20

Family

ID=63591320

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2017043649A Pending JP2018147345A (en) 2017-03-08 2017-03-08 Electronic device

Country Status (1)

Country Link
JP (1) JP2018147345A (en)

Similar Documents

Publication Publication Date Title
EP0451936B1 (en) Program control system for portable data storage device
JP4806639B2 (en) Secure device and IC card issuing system
JP2007317170A (en) Ic module and cellular phone
CN105653470A (en) Mobile communication device and method for swapping mifare applications
JP4090350B2 (en) IC card
TW451163B (en) Simplified use of smart cards
JP4742469B2 (en) IC card, IC card processing apparatus and processing method using a plurality of OSs
CN101273369A (en) Smartcard power management
JPH1139450A (en) Ic card
JP2018147345A (en) Electronic device
KR100884239B1 (en) Memory Card System and Method transmitting background Information thereof
JP4590201B2 (en) Data carrier and data carrier program
KR100399603B1 (en) Smart card and method for writing/erasing and operating an os program the same
EP2228734A1 (en) Portable electronic device and access control method in portable electronic device
JP7424536B1 (en) Electronic information storage medium, IC chip, IC card, communication parameter transmission method, and program
JP2006293706A (en) Multi-application ic card with application updating function
JP5214291B2 (en) IC card and IC card control method
JP2015125627A (en) Ic card and mobile electronic device
JP4734838B2 (en) Information recording medium, program, and command execution control method
JP7322923B2 (en) Secure element, transaction control method and device
US8704636B2 (en) Information processing apparatus, communication apparatus, and program
JP5932588B2 (en) IC card, portable electronic device, and IC card processing device
JP7439798B2 (en) Electronic information storage medium, application selection processing method, and program
JP5957347B2 (en) IC card and portable electronic device
KR101455539B1 (en) Ic card and ic card control method

Legal Events

Date Code Title Description
A711 Notification of change in applicant

Free format text: JAPANESE INTERMEDIATE CODE: A712

Effective date: 20170904

A711 Notification of change in applicant

Free format text: JAPANESE INTERMEDIATE CODE: A711

Effective date: 20170905