Smart Cards and the Open Terminal Architecture

Smart cards, sometimes known as "Integrated Circuit Cards" or "pocket PCs," are being promoted as a replacement for conventional credit/debit cards. Edward discusses smart cards and the Open Terminal Architecture, a standard that defines terminal software.


December 01, 1998
URL:http://www.drdobbs.com/open-source/smart-cards-and-the-open-terminal-archit/184410748

Dec98: Smart Cards and the Open Terminal Architecture

Edward, a former vice president of Forth Inc., is a freelance programmer. He can be contacted at [email protected].


Smart cards (technically known as "Integrated Circuit Cards" or ICCs) are being promoted as a more secure and more capable replacement for existing magnetic-stripe cards, such as credit and debit cards. An ICC typically contains a low-power processor (such as the Hitachi H8/300) and up to 16 KB of memory (mostly EEPROM, with some RAM). An ICC makes secure off-line transactions possible, and is capable of supporting multiple applications -- credit, debit, stored-value cash, and the like -- on a single card.

Software has been a significant barrier to the growth of the smart-card market. In particular, the primary challenge has been the new requirement for supporting multiple applications on single cards and, more importantly, on the variety of relatively low-end point-of-sale (POS) terminals that accept the cards. These terminals typically have simple processors, such as a 6303 or 8051, and limited memory (128 KB or so, most of which is required for data storage). The multiple application problem cannot be solved easily just by adding memory; the POS terminal business is extremely competitive and cost-sensitive, and memory represents one of the largest cost components. There are two additional important constraints.

In 1995, Europay International (http://www.europay.com/), Europe's largest financial services organization, which handles MasterCard in Europe as well as numerous other card-based financial products, recognized the multiapplication, multiterminal problem and mounted an ambitious program to address it. The result is the "Open Terminal Architecture" (OTA), a published standard for terminal software backed by a family of software development tools. To prove the concept, Europay, together with Forth Inc. (http://www.forth.com/) and MPE Ltd. (http://www.mpe.co.uk/), produced a variety of terminal kernels and application programs. OTA was first demonstrated publicly at Europay's 1996 Members' Meeting in Seville, Spain, running two applications on six different terminal types. The first field prototypes have been operational since May 1997.

Open Terminal Architecture

As Figure 1 shows, the Open Terminal Architecture has three conceptual layers:

OTA is based on the Forth language, extended with commands to facilitate development of payment applications, in particular those compliant with a financial-transaction specification (usually referred to as EMV) developed by Europay, MasterCard, and Visa. Europay chose Forth because it provides a compact and efficient means of representing both terminal programs and the code that may reside on the ICC itself. The OTA architecture has been further modified for use with other programming languages; for example, it includes frame memory for local variables used in C. Both C and Forth compilers exist for OTA, and others may be added.

The OTA token set contains about 350 tokens, including about 250 1-byte tokens, each of which represents an instruction for the VM. The token set has three main components: low-level operations for arithmetic, stack management, flow-of-control, and so on (the great majority of these form a subset of ANS Forth); I/O and communications functions; and OTA-specific functions, such as databases, messages, and Tag-Length-Value (TLV) data formats used in ICC communications. Some tokens also have associated in-line values, for such things as literal values or address offsets.

Security is extremely important in financial applications. In addition to isolation of application modules in the terminal, all critical communications between the terminal and an ICC are encrypted using SHA or RSA algorithms. The latter requires modulo multiplication, shifting, and subtraction using numbers up to 1024 bits long. Achieving this with satisfactory execution time on simple 8-bit CPUs (the 8051, for example) required careful optimization, but eventually fell below Europay's maximum allowable security-verification time (one to three seconds, depending on key length).

Running an application involves two steps. First, the application token module is instantiated, meaning that it is assigned data storage space for its local variables, and links are established to any library routines it calls. Second, it is executed, which means that its tokens are interpreted by the VM. When the module finishes executing, its local data space is cleared for security reasons.

One of the services the VM and TRS jointly provide is maintenance of the module storage area, which is usually in extended memory. A utility is available in module form for downloading new modules, a process that is extremely quick since the average size is very small.

The OTA Virtual Machine

The basic architecture of the OTA Virtual Machine is conceptually similar to the Java Virtual Machine with bytecode applets. However, there are some significant differences:

The entire OTA system is language independent. Both VMs and applications have been written in C and in Forth (a language designed specifically for embedded systems programming), and a Java compiler is under consideration.

Although OTA applies only to terminal software, Europay explored a similar VM approach for the ICCs themselves, and others are actively developing such VMs. The two most popular systems currently are JavaCard and MULTOS. Since the functions the ICC needs to execute (mostly data storage and retrieval) are much simpler than terminal functions, the card VMs and applications are correspondingly smaller. Typical sizes of 10 to 18 KB for JavaCard and 6 to 8 KB for MULTOS have been reported.

With VMs both on the card and in the terminal, it is theoretically feasible to pass not only data but also application code between the two. OTA includes functions that allow a card to download code to a terminal application, to be executed at predesignated points (sockets) in the application. Such code might be used to implement a loyalty reward, the exact form of which is determined by the downloaded code: That is, for cards issued by a certain bank, a terminal transaction could also post miles to the owner's frequent-flier account. For security and contractual reasons, the terminal application controls whether socketed code is allowed to execute, and both terminal and card application code undergo stringent testing and certification.

Virtual Machine Architecture

The OTA Virtual Machine is a byte-addressed, two's complement, 32-bit machine, with 32-bit registers. It is based on a multiple-stack architecture, as is usual in Forth; see Figure 2. OTA was carefully designed to keep applications separate, and so the VM employs the so-called "Harvard Architecture," with separate code and data spaces. The data, return, and exception stacks, although technically in data RAM, are not in accessible memory space and can only be managed through specific tokens. Code memory is used only by the VM kernel and is not available to token programs (which are handled as data); thus, code memory can be considered to be in ROM. Initialized data space is preset at compile time, and will be instantiated in the target at run time. Uninitialized data is similar but preset to binary zero. These data spaces, as well as extensible scratch memory and nonvolatile memory are available to token programs, but again only through specific tokens.

The VM kernel contains all of the functions whose implementation depends on a particular platform (CPU and sometimes a terminal operating system). Besides elementary functions such as arithmetic, stack support, and program flow control, the kernel includes a number of specialized OTA functions such as support for terminal-specific I/O and support for the token loader/interpreter, which manages the CPU-independent libraries and application modules. Most OTA kernels to date have been written in Forth, although some have been written in C. The reentrance capability inherent in the Forth language results in quite compact kernels, less than 32 KB for an 8-bit or 16-bit CPU.

The VM's registers are described in Table 1. The local variable frame requires two pointers to allow the traditional C calling sequences. Frames grow down in memory, matching the behavior of the majority of CISC processor machine stacks. How VM registers are mapped onto the target CPU architecture is up to the kernel implementer for that CPU. Although these registers are conceptually present, for security, no direct access is provided to them by the token set.

Most OTA tokens are single-byte (primary) tokens. A 1-byte prefix token allow a theoretical maximum of 65,536 tokens, regarding prefixes as defining pages of 256 tokens each (secondary tokens). In fact, only the primary 1-byte page and two (largely unfilled) secondary pages are needed.

Tables 2, 3, and 4 show some examples of tokens in each of the three major classifications. For convenience, tokens are named when they are defined, although they are processed solely as numerical values (shown here in hex; two values indicate a secondary token).

The code for the low-level tokens in a VM implementation is nearly all assembly, as is the code for most of the I/O and communications tokens. Assembly is used to optimize execution speed for commonly used tokens and/or because hardware is being accessed directly. Many of the OTA-specific tokens, on the other hand, are coded in high-level Forth for convenience; their relatively infrequent execution does not result in a serious performance penalty. The code for DBADDREC, for example, is shown in Example 1.

The code for DBADDREC checks to see if the file is ordered, and if it is, generates an exception. Otherwise it sets the parameter AVAILABLE (indicating the next available record number) to the end of the file, and calls the previously defined routine INSERT-RECORD, which actually performs the insertion.

Using OTA-specific tokens, the modularized and encapsulated application programs and supporting libraries are managed as individual data modules. One module may call another, but only at specific published entry points. Module code is written in terms of tokens, and modules have no way to access code space, which is private to the VM. Data space needed by an application may be of two kinds: local scratch data space, which is used during a transaction but erased when the transaction is completed, and databases used for long-term storage, such as transaction logs. Databases are managed by the VM as a server, which provides access to data in databases one record at a time, and only to the application that instantiated the database(s). The absolute location of a database is not known even to the application that owns it.

Memory requirements are somewhat flexible, but for good performance a terminal should provide:

Although it is possible to use extended memory, flash, or even disk for database and module storage, the medium designated for this purpose can have a significant impact on performance. Writing flash, for example, is much slower than writing RAM, so data storage operations are slow. Similarly, executing modules in memory accessed only through lengthy mapping operations or OS calls is slower than from more directly accessible RAM. Vendors designing new terminals that will be used with OTA can make choices that will greatly enhance their performance, at relatively low unit cost.

Writing OTA Applications

OTA provides a token set that is rich in high-level functions and that greatly simplifies the task of writing smart-card applications. The token set not only provides standard operators for arithmetic, logical operations, flow-of-control structures, and so on, it also provides tokens for such advanced features as:

Library modules are available for high-level functions such as menu construction, report generation, communications protocols, and a library of all transaction steps defined in published financial specifications. As a result, applications tend to be short and easy to write.

The typical environment for OTA kernel and application development consists of a PC host connected to the target terminal with an interactive serial communications link. The software development of a multiapplication terminal under OTA takes place in several steps.

Example 2 is code for a sample application. The functions whose names begin with TRS- are provided in the terminal-specific TRS library; those beginning with EMV- or ICC- are from the Europay financial transaction library, and those beginning with MSG- are named messages which will be displayed in the language currently selected by users. Other functions have been previously defined in this application. As Example 2 illustrates, it is relatively simple to put together applications using these tested, high-level library functions.

To show how small resulting applications are, Table 5 lists the modules required to run an existing offline CLIP (stored value) application. The module named CLIP is the application; all the others are library modules that would also support another application. An online application would also require a communications protocol module; these are typically about seven KB in size.

Conclusion

Smart cards have enormously increased capability over current magnetic-stripe cards, but programming the wide variety of low-end terminals that accept them is difficult to do in a cost-effective way. The Open Terminal Architecture is an approach that converts all types of terminals into the same VM with a common set of bytecode token instructions. Using OTA, applications may be written, tested, and certified once for use on any OTA-compliant terminal. The published OTA standard includes provision for multiple competing applications in the terminal and/or on the ICC, and is carefully designed to keep applications from interacting. OTA is optimized for small size and fast execution, and has demonstrated successful operation of multiple applications on terminals as small as a 6303 processor with 128 KB of memory.

Although OTA was initially intended for financial applications, its token instruction set and associated features (such as database management) were designed to be general in nature, and easily support nonfinancial applications as well. If needed, extension of the token set to other specific application-related functions is relatively simple, particularly because the code for a token may be written in a high-level language such as Forth or C.

DDJ


Copyright © 1998, Dr. Dobb's Journal
Dec98: Smart Cards and the Open Terminal Architecture

Smart Cards and the Open Terminal Architecture

By Edward K. Conklin

Dr. Dobb's Journal December 1998

: INSERT-RECORD ( S: -- )   ( G: Insert a record before the current )
 WRITABLE #RECORD 0 MAX         \ From the current record
 DUP >R AVAILABLE  DB-INSERT    \ To last record, insert record
 AVAILABLE 1+ TO AVAILABLE      \ Increment available
 R> TO #RECORD                  \ Reset current record
 UPDATE-RECORD                  \ Save file update
;
: DBADDREC ( S: -- )       ( G: Add a record to the end of the database )
 KIND ORDERED AND               \ Check that file is not ordered
 DB-INVALID-FUNCTION ?THROW     \ Exception
 AVAILABLE TO #RECORD           \ Set record number to end of database
 INSERT-RECORD                  \ Insert a new record
 ;

Example 1: Code for DBADDREC.


Copyright © 1998, Dr. Dobb's Journal
Dec98: Smart Cards and the Open Terminal Architecture

Smart Cards and the Open Terminal Architecture

By Edward K. Conklin

Dr. Dobb's Journal December 1998

:INIT-PURCHASE   ( S: -- )
 ( Initialize the purchase transaction. Perform all common steps for 
     online and offline transactions. )
 NEEDS-UPLOADING? ERR-DENIED ?THROW     \ Transaction log full ?
 LOAD-APPLICATION-DATA                  \ Load application data
 5 TRS-TRANSACTION-AMOUNT               \ Determine transaction amount
 EMV-INITIATE-APPLICATION               \ Initiate application on card
 EMV-PROCESS-COMPLETE?                  \ $9000 returned ?
 GET-CURRENT-BALANCE                    \ Get current balance from card
 MSG-BALANCE TRS-CONSTRUCT-CH-MESSAGE   \ Display balance for cardholder
 [ FLG-SECONDARY-DISPLAY ] [IF]
   MSG-PLEASE-WAIT TRS-CONSTRUCT-MRCH-MESSAGE   \ Ask merchant to wait
 [THEN]
 EMV-READ-APPLICATION-DATA              \ Read data from the card
 EMV-PROCESS-COMPLETE?                  \ $9000 returned ?
 ICC-PUBLIC-KEY-AUTH                    \ Authenticate ICC public key
 EMV-PROCESSING-RESTRICTIONS            \ Check restrictions
 TRS-CHECK-STATUS                       \ Check transaction has not                                                                 
                                        \       been canceled
;

Example 2: A sample OTA application.


Copyright © 1998, Dr. Dobb's Journal
Dec98: Smart Cards and the Open Terminal Architecture

Smart Cards and the Open Terminal Architecture

By Edward K. Conklin

Dr. Dobb's Journal December 1998

Figure 1: OTA software components in a typical terminal.


Copyright © 1998, Dr. Dobb's Journal
Dec98: Smart Cards and the Open Terminal Architecture

Smart Cards and the Open Terminal Architecture

By Edward K. Conklin

Dr. Dobb's Journal December 1998

Figure 2: The OTA Virtual Machine.


Copyright © 1998, Dr. Dobb's Journal
Dec98: Smart Cards and the Open Terminal Architecture

Smart Cards and the Open Terminal Architecture

By Edward K. Conklin

Dr. Dobb's Journal December 1998

Table 1: Virtual Machine registers.


Copyright © 1998, Dr. Dobb's Journal
Dec98: Smart Cards and the Open Terminal Architecture

Smart Cards and the Open Terminal Architecture

By Edward K. Conklin

Dr. Dobb's Journal December 1998

Table 2: Sample VM low-level tokens.


Copyright © 1998, Dr. Dobb's Journal
Dec98: Smart Cards and the Open Terminal Architecture

Smart Cards and the Open Terminal Architecture

By Edward K. Conklin

Dr. Dobb's Journal December 1998

Table 3: Sample VM I/O and communications. tokens.


Copyright © 1998, Dr. Dobb's Journal
Dec98: Smart Cards and the Open Terminal Architecture

Smart Cards and the Open Terminal Architecture

By Edward K. Conklin

Dr. Dobb's Journal December 1998

Table 4: Sample OTA-specific VM tokens.


Copyright © 1998, Dr. Dobb's Journal
Dec98: Smart Cards and the Open Terminal Architecture

Smart Cards and the Open Terminal Architecture

By Edward K. Conklin

Dr. Dobb's Journal December 1998

Table 5: Size of modules required to run an existing offline CLIP application.


Copyright © 1998, Dr. Dobb's Journal

Terms of Service | Privacy Statement | Copyright © 2024 UBM Tech, All rights reserved.