2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package gov.nasa.jpf.vm;
20 import gov.nasa.jpf.Config;
21 import gov.nasa.jpf.annotation.MJI;
22 import gov.nasa.jpf.vm.MJIEnv;
23 import gov.nasa.jpf.vm.NativePeer;
25 import java.security.MessageDigest;
26 import java.security.NoSuchAlgorithmException;
28 public class JPF_java_security_MessageDigest extends NativePeer {
30 MessageDigest[] digests;
32 public JPF_java_security_MessageDigest (Config conf){
33 digests = new MessageDigest[32];
37 int n = digests.length;
38 for (int i=0; i<n; i++){
39 if (digests[i] == null){
44 MessageDigest[] newd = new MessageDigest[n + 32];
45 System.arraycopy(digests,0,newd,0,digests.length);
50 MessageDigest getDigest (MJIEnv env, int objRef){
51 int id = env.getIntField(objRef, "id");
56 public int init0__Ljava_lang_String_2__I (MJIEnv env, int objRef, int algRef) {
57 String algorithm = env.getStringObject(algRef);
60 MessageDigest md = MessageDigest.getInstance(algorithm);
62 int id = getNewIndex();
66 } catch (NoSuchAlgorithmException x){
67 env.throwException("java.security.NoSuchAlgorithmException", algorithm);
73 public int digest___3B___3B (MJIEnv env, int objRef, int inputRef){
74 MessageDigest md = getDigest(env, objRef);
75 byte[] input = env.getByteArrayObject(inputRef);
77 byte[] res = md.digest(input);
78 return env.newByteArray(res);
82 public int digest_____3B (MJIEnv env, int objRef){
83 MessageDigest md = getDigest(env, objRef);
84 byte[] res = md.digest();
85 return env.newByteArray(res);
89 public void finalize____ (MJIEnv env, int objRef){
90 int id = env.getIntField(objRef, "id");
95 public void update___3B__V (MJIEnv env, int objRef, int inputRef){
96 MessageDigest md = getDigest(env, objRef);
97 byte[] input = env.getByteArrayObject(inputRef);